Snootalogue/Models/SeedData.cs

57 lines
1.8 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 {
ID = Document.NewID(context),
Title = "The Peebler Chronicles",
Filename = "peebler.pdf",
Size = Convert.ToInt64(0.5 * 1024 * 1024),
DateAdded = DateTime.UtcNow,
Authors = new List<string>() { "Pempos", "Artep" },
Category = "News",
Hash = "0d96a4ff68ad6d4b6f1f30f713b18d5184912ba8dd389f86aa7710db079abcb0"
},
new Document {
ID = Document.NewID(context),
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,
Hash = "0d96a4ff68ad6d4b6f1f30f713b18d5184912ba8dd389f86aa7710db079abcb0"
},
new Document {
ID = Document.NewID(context),
Title = "What on Boo Earth? My Girlfriend can Walk on the Ceiling?!",
Filename = "ceiling_gf.pdf",
Size = Convert.ToInt64(22.5 * 1024 * 1024),
DateAdded = DateTime.UtcNow,
Authors = new List<string>() { "Lynne" },
Category = "Romance",
Hash = "0d96a4ff68ad6d4b6f1f30f713b18d5184912ba8dd389f86aa7710db079abcb0"
}
);
context.SaveChanges();
}
}
}
}