/// <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!"); }
public async Task <IActionResult> Create([Bind("TicketID, ScreeningID, Seats")] Ticket ticket) { if (ModelState.IsValid) { var screening = await _context.Screening .Include(m => m.Salon) .Include(m => m.Tickets) .FirstOrDefaultAsync(m => m.ScreeningID == ticket.ScreeningID); if (screening.FreeSeats >= ticket.Seats) { _context.Add(ticket); await _context.SaveChangesAsync(); TempData["TID"] = ticket.TicketID; return(RedirectToAction(nameof(Success))); } } var x = new TicketViewModel { Screening = await _context.Screening .Include(m => m.Salon) .Include(m => m.Movie) .Include(m => m.Tickets) .FirstOrDefaultAsync(m => m.ScreeningID == ticket.ScreeningID), Ticket = ticket }; return(View(x)); }