-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppDbContext.cs
91 lines (85 loc) · 3.85 KB
/
AppDbContext.cs
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using Bogus;
using Microsoft.EntityFrameworkCore;
using NodaTime;
using Sukalibur.Graph.Auth;
using Sukalibur.Graph.Invoices;
using Sukalibur.Graph.Orders;
using Sukalibur.Graph.Organizers;
using Sukalibur.Graph.Trips;
using Sukalibur.Graph.Users;
namespace Sukalibur
{
public class AppDbContext : DbContext
{
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
builder
.HasPostgresEnum<UserRole>()
.HasPostgresEnum<UserGender>()
.HasPostgresEnum<OrganizerStatus>()
.HasPostgresEnum<TripStatus>()
.HasPostgresEnum<TripScheduleStatus>()
.HasPostgresEnum<TripReservationStatus>()
.HasPostgresEnum<OrderStatus>();
builder.Entity<User>()
.HasIndex(u => u.Username)
.IsUnique();
builder.Entity<User>()
.HasIndex(u => u.Email)
.IsUnique();
#region Seed initial data
int accountId = 11;
var accountData = new Faker<User>()
.UseSeed(42)
.RuleFor(m => m.Id, f => accountId++)
.RuleFor(m => m.Username, f => f.Person.UserName)
.RuleFor(m => m.Email, f => f.Person.Email)
.RuleFor(m => m.Password, f => f.Internet.Password())
.RuleFor(m => m.Dob, f => null)
.RuleFor(m => m.Phone, f => f.Person.Phone)
.RuleFor(m => m.FullName, f => f.Person.FullName)
.RuleFor(m => m.Role, f => f.PickRandom<UserRole>())
.RuleFor(m => m.Gender, f => f.PickRandom<UserGender>())
.RuleFor(m => m.CreatedAt, f => f.Noda().Instant.Past())
.RuleFor(m => m.UpdatedAt, f => f.Noda().Instant.Past())
.Generate(100);
accountData.InsertRange(0, [
new User { Id = 1, Username = "root", Email = "[email protected]", FullName = "Root", Password = BCrypt.Net.BCrypt.HashPassword("root"), Role = UserRole.Super, Gender = UserGender.Other }
]);
builder.Entity<User>()
.HasData(accountData);
builder.Entity<TripCategory>()
.HasData([
new TripCategory { Id = 1, Name = "Open Trip" },
new TripCategory { Id = 2, Name = "Private Trip" },
new TripCategory { Id = 4, Name = "Group Trip" },
]);
builder.Entity<Organizer>()
.HasData([
new Organizer { Id = 1, Username = "root", Name = "Root", Email="[email protected]", Phone = "14025", Status = OrganizerStatus.Active },
]);
builder.Entity<Trip>()
.HasData([
new Trip { Id = 1, CategoryId = 1, OrganizerId = 1, Title = "Main Trip", Description = "Main Trip Description" },
]);
#endregion
base.OnModelCreating(builder);
}
public DbSet<User> Users { get; set; }
public DbSet<Organizer> Organizers { get; set; }
public DbSet<OrganizerMember> OrganizerMembers { get; set; }
public DbSet<Trip> Trips { get; set; }
public DbSet<TripCategory> TripCategories { get; set; }
public DbSet<TripItinerary> TripItineraries { get; set; }
public DbSet<TripSchedule> TripSchedules { get; set; }
public DbSet<TripReservation> TripReservations { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<OrderDetail> OrderDetails { get; set; }
public DbSet<Invoice> Invoices { get; set; }
public DbSet<InvoiceDetail> InvoiceDetails { get; set; }
public DbSet<RefreshToken> RefreshTokens { get; set; }
}
}