Snootalogue/Models/SeedData.cs

55 lines
1.7 KiB
C#
Raw Normal View History

2020-09-15 12:31:52 +00:00
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",
2020-09-16 01:43:55 +00:00
Size = Convert.ToInt64(0.5 * 1024 * 1024),
2020-09-15 12:31:52 +00:00
DateAdded = DateTime.UtcNow,
Authors = new List<string>() { "Pempos", "Artep" },
2020-09-16 01:43:55 +00:00
Category = "News",
Hash = "0d96a4ff68ad6d4b6f1f30f713b18d5184912ba8dd389f86aa7710db079abcb0"
2020-09-15 12:31:52 +00:00
},
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",
2020-09-16 01:43:55 +00:00
Read = true,
Hash = "0d96a4ff68ad6d4b6f1f30f713b18d5184912ba8dd389f86aa7710db079abcb0"
2020-09-15 12:31:52 +00:00
},
new Document {
Title = "What on Boo Earth? My Girlfriend can Walk on the Ceiling?!",
Filename = "ceiling_gf.pdf",
2020-09-16 01:43:55 +00:00
Size = Convert.ToInt64(22.5 * 1024 * 1024),
2020-09-15 12:31:52 +00:00
DateAdded = DateTime.UtcNow,
Authors = new List<string>() { "Lynne" },
2020-09-16 01:43:55 +00:00
Category = "Romance",
Hash = "0d96a4ff68ad6d4b6f1f30f713b18d5184912ba8dd389f86aa7710db079abcb0"
2020-09-15 12:31:52 +00:00
}
);
context.SaveChanges();
}
}
}
}