/// <summary>method <c>Check</c> Checks if the given context contains any values and populates them if needed. /// If refresh is true then all screening dates updates to current time</summary> public static async Task Check(webnetlabb3Context _context) { _context.Database.EnsureCreated(); PrintInfo("Running checks..."); if (await Empty(_context.Movie)) { var movies = DummyMovies(); await _context.Movie.AddRangeAsync(movies); await _context.SaveChangesAsync(); } PrintInfo("Movies [Done]"); if (await Empty(_context.Salon)) { await _context.Salon.AddRangeAsync(DummySalons()); await _context.SaveChangesAsync(); } PrintInfo("Salons [Done]"); if (await Empty(_context.Screening)) { var screenings = await DummyScreenings(_context); await _context.Screening.AddRangeAsync(screenings); } PrintInfo("Screenings [Done]"); if (Refresh) { await RefreshScreenings(_context); } await _context.SaveChangesAsync(); PrintInfo("Checks complete!"); }
private static async Task <ICollection <Screening> > DummyScreenings(webnetlabb3Context _context, int amountPerSalon = 10) { var x = new List <Screening>(); var TimeStarted = DateTime.Now; var prices = new decimal[] { 100, 120, 150 }; foreach (var salon in await _context.Salon.ToListAsync()) { var date = TimeStarted; for (int i = 0; i < amountPerSalon; i++) { var movie = await RandomMovie(_context.Movie); var s = new Screening { Date = date, SalonID = salon.SalonID, MovieID = movie.MovieID, Price = prices[new Random().Next(0, prices.Length)], Tickets = new List <Ticket>() }; date = s.Date.AddMinutes(movie.Length); x.Add(s); } } return(x); }
private static async Task RefreshScreenings(webnetlabb3Context _context) { PrintInfo("Refreshing..."); var startTime = DateTime.Now; var salonList = await _context.Salon.Include(s => s.Screenings).ThenInclude(m => m.Movie).ToListAsync(); foreach (var salon in salonList) { var date = startTime; foreach (var screening in salon.Screenings) { screening.Date = date; date = screening.Date.AddMinutes(screening.Movie.Length); } } PrintInfo("Refresh [Done]"); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, webnetlabb3Context context) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } //Context helper settings //Debug = console output ContextHelper.Debug = true; //Refresh = Update all dates on screenings. ContextHelper.Refresh = false; //Run ContextHelper.Check(context).Wait(); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); }
public MoviesController(webnetlabb3Context context) { _context = context; }
public TicketsController(webnetlabb3Context context) { _context = context; }
public HomeController(ILogger <HomeController> logger, webnetlabb3Context context) { _logger = logger; _context = context; }