Beispiel #1
0
        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());
        }
Beispiel #2
0
        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());
        }
Beispiel #3
0
        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"));
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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"));
        }
Beispiel #6
0
        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));
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        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);
        }
Beispiel #9
0
 private async Task SaveState(FilmSeance seance, EntityState state)
 {
     _context.Entry(seance).State = state;
     await _context.SaveChangesAsync();
 }
Beispiel #10
0
 public async Task DeleteAsync(FilmSeance seance)
 {
     _context.Remove(seance);
     await _context.SaveChangesAsync();
 }
Beispiel #11
0
 public async Task UpdateAsync(FilmSeance seance)
 {
     await SaveState(seance, EntityState.Modified);
 }
Beispiel #12
0
 public async Task CreateAsync(FilmSeance seance)
 {
     await SaveState(seance, EntityState.Added);
 }