Snootalogue/Models/SeedData.cs

52 lines
1.4 KiB
C#

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Snootalogue.Data;
using System;
using System.Linq;
using System.Collections.Generic;
namespace Snootalogue.Models {
public static class SeedData {
public static void Initialise(IServiceProvider serviceProvider) {
using (var context = new SnootalogueContext(
serviceProvider.GetRequiredService<DbContextOptions<SnootalogueContext>>()
)) {
if (context.Document.Any()) {
// database already contains entries, no need to seed it
return;
}
context.Document.AddRange(
new Document {
Title = "The Peebler Chronicles",
Filename = "peebler.pdf",
Size = 5 * 1024 * 1024,
DateAdded = DateTime.UtcNow,
Authors = new List<string>() { "Pempos", "Artep" },
Category = "News"
},
new Document {
Title = "Smooched by a Wifeoid",
Filename = "smooched_by_a_wifeoid.pdf",
Size = 7 * 1024 * 1024,
DateAdded = DateTime.UtcNow,
Authors = new List<string>() { "Lynne", "Petra" },
Category = "Romance",
Read = true
},
new Document {
Title = "What on Boo Earth? My Girlfriend can Walk on the Ceiling?!",
Filename = "ceiling_gf.pdf",
Size = 22 * 1024 * 1024,
DateAdded = DateTime.UtcNow,
Authors = new List<string>() { "Lynne" },
Category = "Romance"
}
);
context.SaveChanges();
}
}
}
}