using Bogus; using Bogus.Locations; using WhatApi.Tables; namespace WhatApi; public static class Seed { public static void Full(Database db, Action seedOptions) { var opt = new SeedOptions(); seedOptions.Invoke(opt); Content(db, opt); } public static void Content(Database db, SeedOptions opt) { var any = db.Places.Any(); if (any) { if (!opt.ClearTables) return; db.Places.RemoveRange(db.Places.ToList()); db.SaveChanges(); } var faker = new Faker(); for (var i = 0; i < 30; i++) { var ip = faker.Internet.IpAddress(); var content = new Content() { Id = Guid.NewGuid(), Ip = ip, Mime = "image/jpeg", BlobId = new Guid("3ae0ea2d-851d-4e27-ad89-205822126395") }; var location = faker.Location(); var point = location.AreaCircle(59.91838, 10.73861, 30000); var place = new Place() { Location = new Point(new Coordinate(point.Longitude, point.Latitude)), Content = content }; db.Places.Add(place); } db.SaveChanges(); } } public class SeedOptions { public bool ClearTables { get; set; } }