Exemplo n.º 1
0
        public async Task CancelReservation(CancelReservationModel model)
        {
            var userId = _httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);

            Reservation reservation = await _dbContext.Reservations
                                      .Where(rs => rs.UserId == userId && rs.TicketId == model.TicketId)
                                      .FirstOrDefaultAsync();

            Ticket ticket = await _dbContext.Tickets
                            .Where(t => t.Id == model.TicketId)
                            .FirstOrDefaultAsync();

            AvailableSeat availableSeat = new AvailableSeat
            {
                ProjectionId = model.ProjectionId,
                SeatId       = model.SeatId
            };

            CinemaCreditCard card = await _dbContext.CinemaCreditCards
                                    .Where(u => u.UserId == userId)
                                    .FirstOrDefaultAsync();

            card.Balance = card.Balance + 7;

            _dbContext.Reservations.Remove(reservation);
            _dbContext.Tickets.Remove(ticket);
            _dbContext.AvailableSeats.Add(availableSeat);
            await _dbContext.SaveChangesAsync();
        }
Exemplo n.º 2
0
        public async Task CreateReservationAsync(CheckReservationModel model)
        {
            var userId = _httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);

            if (await DoesUserExists(userId))
            {
                AvailableSeat availableSeat = await _dbContext.AvailableSeats
                                              .Where(avs => avs.Id == model.AvailableSeatId)
                                              .FirstOrDefaultAsync();

                Ticket ticket = new Ticket
                {
                    ProjectionId = model.ProjectionId,
                    SeatId       = availableSeat.SeatId,
                    Price        = 7.0
                };
                int seatId = availableSeat.SeatId;


                _dbContext.Tickets.Add(ticket);
                _dbContext.AvailableSeats.Remove(availableSeat);
                await _dbContext.SaveChangesAsync();
                await AddReservation(model, seatId);
            }
        }
Exemplo n.º 3
0
        public async Task <bool> AddProjections(ProjectionRes res)
        {
            try
            {
                Movie movie = await _dbContext.Movies.Where(m => m.Name == res.MovieName).FirstOrDefaultAsync();

                CinemaHall cinHall = await _dbContext.CinemaHalls.Where(m => m.Id == res.CinemaHallId).FirstOrDefaultAsync();



                Projection projection = new Projection
                {
                    ProjectionTime = res.ProjectionTime,
                    MovieId        = movie.Id,

                    CinemaHallId = cinHall.Id,
                };


                _dbContext.Add(projection);
                await _dbContext.SaveChangesAsync();

                Projection project = _dbContext.Projections.Where(m => m.ProjectionTime == res.ProjectionTime && m.MovieId == movie.Id).FirstOrDefault();

                List <AvailableSeatGetDetailsRes> avalSeats = await _dbContext.Seats
                                                              .Where(s => s.CinemaHallId == project.CinemaHallId)
                                                              .Select(avs => new AvailableSeatGetDetailsRes
                {
                    ProjectionId = project.Id,
                    SeatId       = avs.Id,
                    Name         = avs.Name
                }).ToListAsync();

                foreach (var avSeat in avalSeats)
                {
                    AvailableSeat availableSeat = new AvailableSeat
                    {
                        ProjectionId = avSeat.ProjectionId,
                        SeatId       = avSeat.SeatId
                    };

                    _dbContext.AvailableSeats.Add(availableSeat);
                    await _dbContext.SaveChangesAsync();
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 4
0
        public async Task <bool> EditProjections(ProjectionRes res)
        {
            try
            {
                Movie movie = await _dbContext.Movies.Where(m => m.Name == res.MovieName).FirstOrDefaultAsync();

                CinemaHall cinHall = await _dbContext.CinemaHalls.Where(m => m.Id == res.CinemaHallId).FirstOrDefaultAsync();

                //IEnumerable<AvailableSeat> available = await _dbContext.CinemaHalls.Where(m => m.Id == res.CinemaHallId).AllSeats.Select(p => new AvailableSeat
                //{
                //    ProjectionId = res.Id,
                //    SeatId = p.SeatNumber
                //};



                Projection projection = new Projection
                {
                    ProjectionTime = res.ProjectionTime,
                    MovieId        = movie.Id,

                    CinemaHallId = cinHall.Id,
                };


                _dbContext.Add(projection);
                await _dbContext.SaveChangesAsync();

                Projection project = _dbContext.Projections.Where(m => m.ProjectionTime == res.ProjectionTime && m.MovieId == movie.Id).FirstOrDefault();

                foreach (var seat in cinHall.AllSeats)
                {
                    Seat seat1 = _dbContext.Seats.Where(m => m.Id == seat.Id).FirstOrDefault();
                    if (seat1 == null)
                    {
                        Seat newSeat = new Seat
                        {
                            Name = seat.Name
                        };
                        _dbContext.Seats.Add(newSeat);
                        await _dbContext.SaveChangesAsync();
                    }

                    Seat          addedSeat = _dbContext.Seats.Where(m => m.Id == seat.Id).FirstOrDefault();
                    AvailableSeat avl       = new AvailableSeat
                    {
                        ProjectionId = project.Id,
                        SeatId       = addedSeat.Id
                    };
                    _dbContext.AvailableSeats.Add(avl);
                }

                return(true);
            }
            catch
            {
                return(false);
            }
            //    Movie movie = await _dbContext.Movies.Where(m => m.Name == res.MovieName).FirstOrDefaultAsync();
            //    CinemaHall cinHall = await _dbContext.CinemaHalls.Where(m => m.Id == res.CinemaHallId).FirstOrDefaultAsync();
            //    Projection projection = new Projection
            //    {
            //        Id=res.Id,
            //        ProjectionTime = res.ProjectionTime,
            //        MovieId = movie.Id,
            //        Movie = movie,
            //        CinemaHallId = cinHall.Id,
            //        CinemaHall = cinHall
            //    };
            //    _dbContext.Update(projection);
            //    await _dbContext.SaveChangesAsync();
            //    return true;
            //}
            //catch
            //{
            //    return false;
        }