public FilmSeance LoadFormat(FilmSeance filmSeance) { if (!ModelState.IsValid) { return(new FilmSeance()); } List <FilmSeance> seances = _seanceRepository.GetByFilmId(filmSeance.FilmId).ToList(); if (seances == null) { return(new FilmSeance()); } foreach (FilmSeance seance in seances) { if (seance.Date == filmSeance.Date && seance.Time == filmSeance.Time && seance.RoomNumber == filmSeance.RoomNumber && seance.FilmId == filmSeance.FilmId && seance.Price == filmSeance.Price) { return(seance); } } return(new FilmSeance()); }
public async Task <int[]> GetReservedSeats(FilmSeance filmSeance) { if (!ModelState.IsValid) { return new int[] { } } ; Guid seanceId = await _seanceRepository.GetIdBySeance(filmSeance); FilmSeance seance = await _seanceRepository.GetByIdAsync(seanceId); if (seance == null) { return new int[] { } } ; List <int> seatsNumber = new List <int>(); foreach (ReservedSeat reservedSeat in seance.ReservedSeats) { int seatNumber = (reservedSeat.SeatsNumber) + ((reservedSeat.RowNumber - 1) * seatsCountInRow); seatsNumber.Add(seatNumber); } return(seatsNumber.ToArray()); }
public async Task <IActionResult> Create(CreateSeanceViewModel model) { if (!ModelState.IsValid) { return(PartialView(model)); } Film film = await _filmRepository.GetByIdAsync(model.FilmId); if (film == null) { ModelState.AddModelError(string.Empty, "Фильм не найден."); return(PartialView(model)); } FilmSeance seance = new FilmSeance { Date = model.Date, Time = model.Time, Price = model.Price, FilmId = model.FilmId, RoomNumber = model.RoomNumber, Format = model.Format }; await _seanceRepository.CreateAsync(seance); film.Seances.Add(seance); await _filmRepository.UpdateAsync(film); return(RedirectToAction("Index", "Admin")); }
public async Task <Guid> GetIdBySeance(FilmSeance seance) { FilmSeance filmSeance = await _context.Seances.SingleOrDefaultAsync(sod => sod.Date == seance.Date && sod.Time == seance.Time && sod.Price == seance.Price && sod.RoomNumber == seance.RoomNumber && sod.FilmId == seance.FilmId); return(filmSeance.Id); }
public async Task <IActionResult> Delete(Guid id) { FilmSeance seance = await _seanceRepository.GetByIdAsync(id); if (seance == null) { return(NotFound()); } await _seanceRepository.DeleteAsync(seance); return(RedirectToAction("Index", "Admin")); }
public async Task <IViewComponentResult> InvokeAsync(User user) { List <ReservedFilmViewModel> reservedFilms = new List <ReservedFilmViewModel>(); foreach (ReservedSeat reservedSeat in user.ReservedSeats) { FilmSeance seance = await _seanceRepository.GetByIdAsync(reservedSeat.SeanceId); if (seance == null) { continue; } Film film = await _filmRepository.GetByIdAsync(seance.FilmId); if (film == null) { continue; } ReservedFilmViewModel reservedFilm = reservedFilms.Find(f => f.SeanceId == seance.Id); if (reservedFilm == null) { reservedFilm = new ReservedFilmViewModel { FilmId = film.Id, SeanceId = seance.Id, FilmName = film.Name, FilmPosterUrl = film.Posters.First().Url, FilmDuration = film.Duration, SeanceDate = seance.Date, SeanceTime = seance.Time, RoomNumber = seance.RoomNumber, RowSeatNumbers = new Dictionary <int, int>() { { reservedSeat.RowNumber, reservedSeat.SeatsNumber } } }; } else { reservedFilm.RowSeatNumbers.Add(reservedSeat.RowNumber, reservedSeat.SeatsNumber); } reservedFilms.Add(reservedFilm); } return(View("ReservedSeatsList", reservedFilms)); }
public async Task <bool> ReservedSeats(ReservedSeatViewModel reservedSeats) { if (!ModelState.IsValid) { return(false); } string userId = await _userRepository.GetCurrentUserId(User); if (string.IsNullOrEmpty(userId)) { return(false); } FilmSeance seance = new FilmSeance { Date = reservedSeats.Date, Time = reservedSeats.Time, Price = reservedSeats.Price, RoomNumber = reservedSeats.RoomNumber, FilmId = reservedSeats.FilmId }; Guid seanceId = await _seanceRepository.GetIdBySeance(seance); if (seanceId == default) { return(false); } for (int i = 0; i < reservedSeats.SeatNumbers.Length; i++) { double row = ((double)reservedSeats.SeatNumbers[i] + 1) / ((double)seatsCountInRow); int rowNumber = Convert.ToInt32(Math.Ceiling(row)); int seatNumber = (reservedSeats.SeatNumbers[i] + 1) - ((rowNumber - 1) * seatsCountInRow); ReservedSeat reservedSeat = new ReservedSeat { RowNumber = rowNumber, SeatsNumber = seatNumber, UserId = userId, SeanceId = seanceId }; await _reservedSeatRepository.CreateAsync(reservedSeat); } return(true); }
public int LoadPrice(FilmSeance filmSeance) { if (filmSeance.FilmId == default) { return(0); } if (filmSeance.Date == default) { return(0); } if (filmSeance.Time == default) { return(0); } if (filmSeance.RoomNumber < 1 || filmSeance.RoomNumber > 2) { return(0); } List <FilmSeance> seances = _seanceRepository.GetByFilmId(filmSeance.FilmId).ToList(); if (seances == null) { return(0); } foreach (FilmSeance seance in seances) { if (seance.Date == filmSeance.Date && seance.Time == filmSeance.Time && seance.RoomNumber == filmSeance.RoomNumber && seance.FilmId == filmSeance.FilmId) { return(seance.Price); } } return(0); }
private async Task SaveState(FilmSeance seance, EntityState state) { _context.Entry(seance).State = state; await _context.SaveChangesAsync(); }
public async Task DeleteAsync(FilmSeance seance) { _context.Remove(seance); await _context.SaveChangesAsync(); }
public async Task UpdateAsync(FilmSeance seance) { await SaveState(seance, EntityState.Modified); }
public async Task CreateAsync(FilmSeance seance) { await SaveState(seance, EntityState.Added); }