public async Task <IActionResult> EditProjections(int id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            ProjectionRes projection = await _projectionsRepository.GetProjectionById(new ProjectionGetDetailsReq { Id = id });

            return(View(projection));
        }
        public async Task <IActionResult> EditProjections(int id, [Bind("MovieName, ProjectionTime, CinemaHallId")] ProjectionRes projection)
        {
            projection.AllCinemaHalls = await _projectionsRepository.GetAllCinemaHalls();

            if (ModelState.IsValid)
            {
                await _projectionsRepository.EditProjections(projection);

                return(RedirectToAction("HomeAdmin", "Administrator"));
            }
            return(View(projection));
        }
        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);
            }
        }
示例#4
0
        public async Task <IActionResult> MovieReservation(ProjectionGetDetailsReq req)
        {
            if (await _userRepository.DoesUserExists())
            {
                ProjectionRes res = await _projectionsRespository.GetProjectionById(req);

                res.AvailableSeats = res.AvailableSeats.OrderBy(r => r.Name).ToList();
                return(View(res));
            }
            else
            {
                return(View("UserDoesNotExist"));
            }
        }
示例#5
0
        public async Task <IActionResult> TicketPayment(AvailableSeatGetDetailsReq req)
        {
            AvailableSeatGetDetailsRes availableSeatGetDetailsRes = await _availableSeatsRepository.GetAvailableSeatDetails(req);

            ProjectionGetDetailsReq projectionGetDetailsReq = new ProjectionGetDetailsReq
            {
                Id = availableSeatGetDetailsRes.ProjectionId
            };
            ProjectionRes projectionGetDetailsRes = await _projectionsRepository.GetProjectionById(projectionGetDetailsReq);

            ReservationGetDetailsRes reservation = new ReservationGetDetailsRes
            {
                Seat       = availableSeatGetDetailsRes,
                Projection = projectionGetDetailsRes
            };

            return(View(reservation));
        }
        public async Task <IActionResult> DeleteProjections1(int id)
        {
            if (id == null)
            {
                return(NotFound());
            }



            ProjectionRes projection = await _projectionsRepository.GetProjectionById(new ProjectionGetDetailsReq { Id = id });

            if (ModelState.IsValid)
            {
                await _projectionsRepository.DeleteProjections(id);

                return(RedirectToAction("HomeAdmin", "Administrator"));
            }
            return(View(projection));
        }
        public async Task <ProjectionRes> GetProjectionById(ProjectionGetDetailsReq req)
        {
            IList <AvailableSeatGetDetailsRes> seatGetDetailsRes = await _dbContext.AvailableSeats
                                                                   .Where(avs => avs.ProjectionId == req.Id)
                                                                   .Select(s => new AvailableSeatGetDetailsRes
            {
                Id           = s.Id,
                SeatId       = s.SeatId,
                ProjectionId = req.Id,
                Name         = s.Seat.Name
            }).ToListAsync();


            IList <CinemaHallGetDetailsRes> cinemaHalls = await _dbContext.CinemaHalls.Select
                                                              (c => new CinemaHallGetDetailsRes
            {
                Id            = c.Id,
                HallImageUrl  = c.HallImageUrl,
                numberOfSeats = c.AllSeats.Count()
            }).ToListAsync();


            ProjectionRes res = await _dbContext.Projections
                                .Where(p => p.Id == req.Id)
                                .Select(p => new ProjectionRes
            {
                Id             = p.Id,
                ProjectionTime = p.ProjectionTime,
                MovieId        = p.MovieId,
                MovieName      = p.Movie.Name,
                CinemaHall     = new CinemaHallGetDetailsRes
                {
                    Id           = p.CinemaHallId,
                    HallImageUrl = p.CinemaHall.HallImageUrl
                },
                AvailableSeats = seatGetDetailsRes,
                AllCinemaHalls = cinemaHalls
            }).FirstOrDefaultAsync();

            return(res);
        }
        public async Task <TicketGetDetailsRes> GetTicketForIdAsync(TicketGetDetailsReq req)
        {
            TicketGetDetailsRes res = await _dbContext.Tickets
                                      .Where(t => t.Id == req.Id)
                                      .Select(t => new TicketGetDetailsRes
            {
                Id           = t.Id,
                Price        = t.Price,
                ProjectionId = t.ProjectionId,
                SeatName     = t.Seat.Name,
                SeatId       = t.SeatId
            }).FirstOrDefaultAsync();

            ProjectionGetDetailsReq projectionReq = new ProjectionGetDetailsReq
            {
                Id = res.ProjectionId
            };

            ProjectionRes projectionRes = await _projectionsRepository.GetProjectionById(projectionReq);

            res.Projection = projectionRes;

            return(res);
        }
        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;
        }