auto.bus_razor/TicketOffice/Models/SeedData.cs
cuqmbr c47d67b15d feat: places' availability depends on bought tickets
if cities in route you're searching for intersects with cities in the smb's ticket for the route, taken place will be unavailable and capacity in the search results will be decreased
2022-05-28 20:10:50 +03:00

128 lines
4.3 KiB
C#

using Microsoft.EntityFrameworkCore;
using TicketOffice.Data;
namespace TicketOffice.Models;
public class SeedData
{
public static void Initialize(IServiceProvider serviceProvider)
{
using var context =
new TicketOfficeContext(serviceProvider
.GetRequiredService<DbContextOptions<TicketOfficeContext>>());
if (context == null)
{
throw new ArgumentNullException("Null TicketOfficeContext");
}
if (context.User.Any() | context.Route.Any() | context.RouteCity.Any() | context.Ticket.Any())
{
return; // Data has been seeded
}
context.Database.EnsureCreated();
context.User.AddRange(new User[]
{
new User
{
Email = "danylo.nazarko@nure.ua",
Password = "*Hashed Password*",
IsManager = false,
},
new User
{
Email = "ruslan.shanin@nure.ua",
Password = "*Hashed Password*",
IsManager = false
}
});
context.Route.AddRange(new Route[]
{
new Route {
Number = 2,
Capacity = 30,
Cities = new RouteCity[]
{
new RouteCity
{
Name = "Кремінна",
ArrivalTime = new DateTime(2022, 03, 28, 8, 15, 0),
DepartureTime = new DateTime(2022, 03, 28, 8, 35, 0),
},
new RouteCity
{
Name = "Рубіжне",
ArrivalTime = new DateTime(2022, 03, 28, 9, 5, 0),
DepartureTime = new DateTime(2022, 03, 28, 9, 25, 0),
},
new RouteCity
{
Name = "Сєвєродонецьк",
ArrivalTime = new DateTime(2022, 03, 28, 9, 55, 0)
}
}
},
new Route
{
Number = 1,
Capacity = 25,
Cities = new RouteCity[]
{
new RouteCity
{
Name = "Сєвєродонецьк",
ArrivalTime = new DateTime(2022, 03, 28, 15, 55, 0),
DepartureTime = new DateTime(2022, 03, 28, 16, 15, 0),
},
new RouteCity
{
Name = "Рубіжне",
ArrivalTime = new DateTime(2022, 03, 28, 16, 45, 0),
DepartureTime = new DateTime(2022, 03, 28, 17, 5, 0),
},
new RouteCity
{
Name = "Кремінна",
ArrivalTime = new DateTime(2022, 03, 28, 17, 40, 0)
}
}
},
new Route
{
Number = 3,
Capacity = 30,
Cities = new RouteCity[]
{
new RouteCity
{
Name = "Кремінна",
ArrivalTime = new DateTime(2022, 03, 28, 9, 20, 0),
DepartureTime = new DateTime(2022, 03, 28, 8, 40, 0),
},
new RouteCity
{
Name = "Житлівка",
ArrivalTime = new DateTime(2022, 03, 28, 10, 0, 0),
DepartureTime = new DateTime(2022, 03, 28, 10, 15, 0),
},
new RouteCity
{
Name = "Рубіжне",
ArrivalTime = new DateTime(2022, 03, 28, 11, 5, 0),
DepartureTime = new DateTime(2022, 03, 28, 11, 20, 0),
},
new RouteCity
{
Name = "Сєвєродонецьк",
ArrivalTime = new DateTime(2022, 03, 28, 11, 55, 0)
}
}
}
});
context.SaveChanges();
}
}