public async Task SeedAsync(ParkingAppDbContext context) { if (context.Car.Any()) { return; } List <Car> cars = new() { new Car { LicensePlateNumber = "TEST-LICENSE-PLATE-NUMBER-1", Color = "WHITE" }, new Car { LicensePlateNumber = "TEST-LICENSE-PLATE-NUMBER-2", Color = "GRAY" }, new Car { LicensePlateNumber = "TEST-LICENSE-PLATE-NUMBER-3", Color = "BLUE" }, new Car { LicensePlateNumber = "TEST-LICENSE-PLATE-NUMBER-4", Color = "BLACK" }, new Car { LicensePlateNumber = "TEST-LICENSE-PLATE-NUMBER-5", Color = "RED" }, new Car { LicensePlateNumber = "TEST-LICENSE-PLATE-NUMBER-6", Color = "PURPLE" } }; await context.Car.AddRangeAsync(cars); await context.SaveChangesAsync(); } }
public async Task SeedAsync(ParkingAppDbContext context) { if (context.ParkingPass.Any()) { return; } List <Car> cars = GetCars(context); List <ParkingPass> parkingPasses = new() { new ParkingPass { Number = "PARKING-PASS/1/2021", Car = cars[0], IsKeyPartner = false, PaymentOption = PaymentOption.Daily }, new ParkingPass { Number = "PARKING-PASS/2/2021", Car = cars[3], IsKeyPartner = true, Discount = 25, PaymentOption = PaymentOption.Monthly }, new ParkingPass { Number = "PARKING-PASS/3/2021", IsKeyPartner = false, PaymentOption = PaymentOption.Immediately }, new ParkingPass { Number = "PARKING-PASS/4/2021", IsKeyPartner = true, Discount = 235, PaymentOption = PaymentOption.Monthly } }; await context.ParkingPass.AddRangeAsync(parkingPasses); await context.SaveChangesAsync(); }
public async Task SeedAsync(ParkingAppDbContext context) { if (context.Card.Any()) { return; } List <Car> cars = GetCars(context); List <ParkingPass> parkingPasses = GetParkingPasses(context); List <Card> cards = new() { new Card { ParkingPass = parkingPasses[2], Number = "CARD-1-2021", Cars = new List <Car> { cars[1], cars[2] } }, new Card { ParkingPass = parkingPasses[3], Number = "CARD-2-2021", Cars = new List <Car> { cars[4], cars[5] } } }; await context.Card.AddRangeAsync(cards); await context.SaveChangesAsync(); }
private static async Task SeedAsync(ParkingAppDbContext context) { Type[] migrationTypes = MigrationHelper.GetMigrationTypes(); IReadOnlySet <IDataMigration> dataMigrations = GetIDataMigrations(migrationTypes); foreach (IDataMigration dataMigration in dataMigrations) { await dataMigration.SeedAsync(context); } }
public async Task SeedAsync(ParkingAppDbContext context) { if (context.LoggedParkingPeriod.Any()) { return; } List <Car> cars = GetCars(context); List <LoggedParkingPeriod> loggedParkingPeriods = new() { new LoggedParkingPeriod { Car = cars[0], TransactionId = Guid.NewGuid().ToString(), StartDate = DateTime.Now, EndDate = DateTime.Now.AddHours(1) }, new LoggedParkingPeriod { Car = cars[0], TransactionId = Guid.NewGuid().ToString(), StartDate = DateTime.Now.AddHours(1), EndDate = DateTime.Now.AddHours(5) }, new LoggedParkingPeriod { Car = cars[1], TransactionId = Guid.NewGuid().ToString(), StartDate = DateTime.Now, EndDate = DateTime.Now.AddHours(3) }, new LoggedParkingPeriod { Car = cars[1], TransactionId = Guid.NewGuid().ToString(), StartDate = DateTime.Now.AddHours(2), EndDate = DateTime.Now.AddHours(2) }, new LoggedParkingPeriod { Car = cars[2], TransactionId = Guid.NewGuid().ToString(), StartDate = DateTime.Now, EndDate = DateTime.Now.AddHours(12) }, new LoggedParkingPeriod { Car = cars[2], TransactionId = Guid.NewGuid().ToString(), StartDate = DateTime.Now.AddHours(3), EndDate = DateTime.Now.AddHours(8) }, new LoggedParkingPeriod { Car = cars[3], TransactionId = Guid.NewGuid().ToString(), StartDate = DateTime.Now, EndDate = DateTime.Now.AddHours(2) }, new LoggedParkingPeriod { Car = cars[3], TransactionId = Guid.NewGuid().ToString(), StartDate = DateTime.Now.AddHours(4), EndDate = DateTime.Now.AddHours(11) }, new LoggedParkingPeriod { Car = cars[4], TransactionId = Guid.NewGuid().ToString(), StartDate = DateTime.Now, EndDate = DateTime.Now.AddHours(10) }, new LoggedParkingPeriod { Car = cars[4], TransactionId = Guid.NewGuid().ToString(), StartDate = DateTime.Now.AddHours(5), EndDate = DateTime.Now.AddHours(9) }, new LoggedParkingPeriod { Car = cars[5], TransactionId = Guid.NewGuid().ToString(), StartDate = DateTime.Now, EndDate = DateTime.Now.AddHours(8) }, new LoggedParkingPeriod { Car = cars[5], TransactionId = Guid.NewGuid().ToString(), StartDate = DateTime.Now.AddHours(4), EndDate = DateTime.Now.AddHours(7) } }; await context.LoggedParkingPeriod.AddRangeAsync(loggedParkingPeriods); await context.SaveChangesAsync(); }
public static IHost MigrateDatabase(this IHost host) { using (IServiceScope scope = host.Services.CreateScope()) { IServiceProvider serviceProvider = scope.ServiceProvider; ParkingAppDbContext context = serviceProvider.GetRequiredService <ParkingAppDbContext>(); context.InitDatabaseAsync().Wait(); } return(host); }
public static async Task InitDatabaseAsync(this ParkingAppDbContext context) { await context.Database.MigrateAsync(); await SeedAsync(context); }
public ExportParkingListCommandHandler(ParkingAppDbContext context, IJsonExportService jsonExportService) : base(context) { _jsonExportService = jsonExportService; }
private static List <Car> GetCars(ParkingAppDbContext context) { return(context.Car.ToList()); }
protected CommandBase(ParkingAppDbContext context) { Context = context; }
private static List <ParkingPass> GetParkingPasses(ParkingAppDbContext context) { return(context.ParkingPass.ToList()); }