blob: 4b6361ee50bbf8613f86fd15a06b75e70e3dff7c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
using Bogus;
using Bogus.Locations;
namespace WhatApi;
public static class Seed
{
public static void Full(AppDatabase db, Action<SeedOptions> seedOptions) {
var opt = new SeedOptions();
seedOptions.Invoke(opt);
Content(db, opt);
}
public static void Content(AppDatabase 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; }
}
|