Add project files.

This commit is contained in:
2026-02-03 23:02:37 +01:00
parent 94bae0de01
commit 263a4d54f6
92 changed files with 85145 additions and 0 deletions

View File

@ -0,0 +1,56 @@
using DiaryApp.Models;
using Microsoft.EntityFrameworkCore;
namespace DiaryApp.Data
{
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
}
public DbSet<DiaryEntry> DiaryEntries { get; set; } = null!;
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<DiaryEntry>().HasData(
new DiaryEntry
{
Id = 1,
Title = "Went Hiking",
Content = "Went hiking with Joe!",
DateCreated = DateTime.Parse("2026-01-01 10:32")
},
new DiaryEntry
{
Id = 2,
Title = "Went Shoping",
Content = "Went Shoping with Joe!",
DateCreated = DateTime.Parse("2026-01-10 08:32")
},
new DiaryEntry
{
Id = 3,
Title = "Went Swimming",
Content = "Went Swimming with Joe!",
DateCreated = DateTime.Parse("2026-01-15 15:42")
},
new DiaryEntry
{
Id = 4,
Title = "Went Biking",
Content = "Went Biking with Joe!",
DateCreated = DateTime.Parse("2026-01-17 12:00")
}
);
}
// Four steps to add a table
// 1. Create a Model Class
// 2. Add DB-set
// 3. add-migration AddDiaryEntryTable
// 4. update-database
}
}