Ejemplo n.º 1
0
        public async Task <SeatDomainModel> DeleteSeat(Guid id)
        {
            var existingSeats = await _seatsRepository.GetByIdAsync(id);

            if (existingSeats == null)
            {
                return(null);
            }

            _seatsRepository.Delete(id);

            _seatsRepository.Save();

            if (existingSeats.Tickets != null)
            {
                return(null);
            }

            SeatDomainModel domainModel = new SeatDomainModel
            {
                AuditoriumId = existingSeats.AuditoriumId,
                Id           = existingSeats.Id,
                Number       = existingSeats.Number,
                Row          = existingSeats.Row
            };

            return(domainModel);
        }
Ejemplo n.º 2
0
        public async Task <SeatDomainModel> DeleteSeat(Guid seatId)
        {
            var reservationData = await _reservationService.DeleteBySeatId(seatId);

            if (reservationData == null)
            {
                return(null);
            }

            var data = _seatsRepository.Delete(seatId);

            if (data == null)
            {
                return(null);
            }

            _seatsRepository.Save();

            SeatDomainModel domainModel = new SeatDomainModel
            {
                Id           = data.Id,
                AuditoriumId = data.AuditoriumId,
                Number       = data.Number,
                Row          = data.Row
            };

            return(domainModel);
        }
Ejemplo n.º 3
0
        public ActionResult DeleteConfirmed(int id)
        {
            Seat seat = repository.Find(id);

            repository.Delete(id);
            repository.Save();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 4
0
        public async Task <DeleteAuditoriumResultModel> DeleteAuditorium(int Id)
        {
            var auditorium = await _auditoriumsRepository.GetByIdAsync(Id);

            if (auditorium == null)
            {
                return(new DeleteAuditoriumResultModel
                {
                    IsSuccessful = false,
                    ErrorMessage = Messages.AUDITORIUM_NOT_FOUND
                });
            }

            var futureShows = auditorium.Shows.Any(show => show.ShowTime > DateTime.Now);

            if (futureShows)
            {
                return(new DeleteAuditoriumResultModel
                {
                    IsSuccessful = false,
                    ErrorMessage = Messages.AUDITORIUM_HAS_FUTURE_SHOWS
                });
            }

            var seats = await _seatsRepository.GetSeatsByAuditoriumId(auditorium.Id);

            foreach (var seat in seats)
            {
                await _seatsRepository.Delete(seat.Id);
            }

            foreach (var show in auditorium.Shows)
            {
                await _showsRepository.Delete(show.Id);
            }

            await _auditoriumsRepository.Delete(auditorium.Id);

            _showsRepository.Save();
            _seatsRepository.Save();
            _auditoriumsRepository.Save();

            return(new DeleteAuditoriumResultModel
            {
                IsSuccessful = true,
                Auditorium = new AuditoriumDomainModel
                {
                    Id = auditorium.Id,
                    Name = auditorium.Name,
                    TheatreId = auditorium.TheatreId
                }
            });
        }
Ejemplo n.º 5
0
        public async Task <TheatreDomainModel> Delete(int id)
        {
            var theatre = await _theatreRepository.GetByIdAsync(id);

            if (theatre == null)
            {
                return(null);
            }

            var allAuditoriums = await _auditoriumsRepository.GetAllAsync();

            if (allAuditoriums == null)
            {
                return(null);
            }

            var auditoriumsInTheatre = allAuditoriums.Where(x => x.TheatreId == id);

            var seats = await _seatsRepository.GetAllAsync();

            foreach (var auditorium in auditoriumsInTheatre)
            {
                seats = seats.Where(x => x.AuditoriumId == auditorium.Id);

                foreach (var seat in seats)
                {
                    if (seat.ReservationSeats.Any())
                    {
                        return(null);
                    }
                    //dodat await
                    await _seatsRepository.Delete(seat.Id);
                }
                //dodat await
                await _auditoriumsRepository.Delete(auditorium.Id);
            }

            TheatreDomainModel theatreModel = new TheatreDomainModel
            {
                Id              = theatre.Id,
                Name            = theatre.Name,
                AddressId       = theatre.AddressId,
                AuditoriumsList = theatre.Auditoriums.Select(x => new AuditoriumDomainModel
                {
                    Id        = x.Id,
                    TheatreId = x.TheatreId,
                    Name      = x.Name,
                    SeatsList = x.Seats.Select(x => new SeatDomainModel
                    {
                        Id           = x.Id,
                        AuditoriumId = x.AuditoriumId,
                        Number       = x.Number,
                        Row          = x.Row
                    })
                                .ToList()
                })
                                  .ToList()
            };
            //dodat await
            await _theatreRepository.Delete(theatre.Id);

            _theatreRepository.Save();

            return(theatreModel);
        }
Ejemplo n.º 6
0
        public async Task <CreateCinemaResultModel> DeleteCinema(int id)
        {
            var existingCinema = await _cinemasRepository.GetByIdAsync(id);

            var auditoriumsInCinema = _auditoriumService.GetAllOfSpecificCinema(id);

            if (existingCinema == null)
            {
                CreateCinemaResultModel errorModel = new CreateCinemaResultModel
                {
                    ErrorMessage = Messages.CINEMA_DOES_NOT_EXIST,
                    IsSuccessful = false
                };
                return(errorModel);
            }

            foreach (var item in auditoriumsInCinema)
            {
                var existingAuditorium = await _auditoriumsRepository.GetByIdAsync(item.Id);

                if (existingAuditorium == null)
                {
                    return(new CreateCinemaResultModel
                    {
                        ErrorMessage = Messages.AUDITORIUM_DOES_NOT_EXIST,
                        IsSuccessful = false
                    });
                }
                var projectionsInAuditorium = _projectionsRepository.GetAllOfSpecificAuditorium(item.Id);
                if (projectionsInAuditorium != null)
                {
                    foreach (var projection in projectionsInAuditorium)
                    {
                        if (projection.DateTime > DateTime.Now)
                        {
                            return(new CreateCinemaResultModel
                            {
                                ErrorMessage = Messages.PROJECTION_IN_FUTURE,
                                IsSuccessful = false,
                                Cinema = new CinemaDomainModel
                                {
                                    Id = existingCinema.Id,
                                    Name = existingCinema.Name
                                }
                            });
                        }
                        _projectionsRepository.Delete(projection.Id);
                        await _ticketService.DeleteTicketFromProjection(projection.Id);
                    }
                }
                var seatsInAuditorium = _seatsRepository.GetAllOfSpecificAuditorium(item.Id);
                if (seatsInAuditorium != null)
                {
                    foreach (var seat in seatsInAuditorium)
                    {
                        _seatsRepository.Delete(seat.Id);
                    }
                }
                var deleteVariable = _auditoriumsRepository.Delete(item.Id);
                AuditoriumResultModel auditoriumModel = new AuditoriumResultModel
                {
                    ErrorMessage = null,
                    IsSuccessful = true,
                    Auditorium   = new AuditoriumDomainModel
                    {
                        CinemaId = existingAuditorium.CinemaId,
                        Id       = existingAuditorium.Id,
                        Name     = existingAuditorium.Name
                    }
                };

                if (!auditoriumModel.IsSuccessful)
                {
                    CreateCinemaResultModel errorModel = new CreateCinemaResultModel
                    {
                        ErrorMessage = Messages.CINEMA_DELETION_ERROR,
                        IsSuccessful = false,
                        Cinema       = new CinemaDomainModel
                        {
                            Id   = existingCinema.Id,
                            Name = existingCinema.Name
                        }
                    };
                    return(errorModel);
                }
            }
            var data = _cinemasRepository.Delete(id);

            _cinemasRepository.Save();

            CreateCinemaResultModel domainModel = new CreateCinemaResultModel
            {
                ErrorMessage = null,
                IsSuccessful = true,
                Cinema       = new CinemaDomainModel
                {
                    Id   = existingCinema.Id,
                    Name = existingCinema.Name
                }
            };

            return(domainModel);
        }
Ejemplo n.º 7
0
        public async Task <AuditoriumResultModel> UpdateAuditorium(AuditoriumDomainModel auditoriumToUpdate)
        {
            var projectionsInAuditorium = _projectionsRepository.GetAllOfSpecificAuditorium(auditoriumToUpdate.Id);

            if (projectionsInAuditorium != null)
            {
                foreach (var item in projectionsInAuditorium)
                {
                    if (item.DateTime > DateTime.Now)
                    {
                        return(new AuditoriumResultModel
                        {
                            IsSuccessful = false,
                            ErrorMessage = Messages.AUDITORIUM_UPDATE_ERROR_PROJECTION_IN_FUTURE
                        });
                    }
                }
            }
            var seatsInAuditorium = _seatsRepository.GetAllOfSpecificAuditorium(auditoriumToUpdate.Id);

            if (seatsInAuditorium != null)
            {
                foreach (var item in seatsInAuditorium)
                {
                    await _ticketService.DeleteTicket(item.Id);

                    _seatsRepository.Delete(item.Id);
                }
            }

            Auditorium auditorium = new Auditorium()
            {
                Id       = auditoriumToUpdate.Id,
                Name     = auditoriumToUpdate.Name,
                CinemaId = auditoriumToUpdate.CinemaId,
                Seats    = new List <Seat>()
            };

            for (int i = 1; i <= auditoriumToUpdate.SeatRows; i++)
            {
                for (int j = 1; j <= auditoriumToUpdate.NumberOfSeats; j++)
                {
                    Seat newSeat = new Seat()
                    {
                        Row    = i,
                        Number = j
                    };
                    auditorium.Seats.Add(newSeat);
                }
            }

            var data = _auditoriumsRepository.Update(auditorium);

            if (data == null)
            {
                return(new AuditoriumResultModel
                {
                    IsSuccessful = false,
                    ErrorMessage = Messages.AUDITORIUM_UPDATE_ERROR
                });
            }
            _auditoriumsRepository.Save();

            AuditoriumResultModel domainModel = new AuditoriumResultModel
            {
                ErrorMessage = null,
                IsSuccessful = true,
                Auditorium   = new AuditoriumDomainModel
                {
                    CinemaId      = data.CinemaId,
                    Id            = data.Id,
                    Name          = data.Name,
                    NumberOfSeats = data.Seats.Select(x => x.Number).Count(),
                    SeatRows      = data.Seats.Select(x => x.Row).Count(),
                }
            };

            return(domainModel);
        }
Ejemplo n.º 8
0
        public async Task <CinemaDomainModel> DeleteCinemaAsync(int id)
        {
            var cinema = await _cinemasRepository.GetByIdAsync(id);

            if (cinema == null)
            {
                return(null);
            }

            var allAuditoriums = await _auditoriumsRepository.GetAll();

            if (allAuditoriums == null)
            {
                return(null);
            }

            var auditoriumsInCinema = allAuditoriums.Where(a => a.CinemaId == id);

            var seats = await _seatsRepository.GetAll();

            foreach (var auditorium in auditoriumsInCinema)
            {
                seats = seats.Where(s => s.AuditoriumId == auditorium.Id);

                foreach (var seat in seats)
                {
                    if (seat.ReservationSeats.Any())
                    {
                        return(null);
                    }
                    _seatsRepository.Delete(seat.Id);
                }

                _auditoriumsRepository.Delete(auditorium.Id);
            }

            CinemaDomainModel cinemaModel = new CinemaDomainModel
            {
                Id              = cinema.Id,
                Name            = cinema.Name,
                CityId          = cinema.CityId,
                AuditoriumsList = cinema.Auditoriums.Select(a => new AuditoriumDomainModel
                {
                    Id        = a.Id,
                    CinemaId  = a.CinemaId,
                    Name      = a.AuditName,
                    SeatsList = a.Seats.Select(s => new SeatDomainModel
                    {
                        Id           = s.Id,
                        AuditoriumId = s.AuditoriumId,
                        Number       = s.Number,
                        Row          = s.Row
                    })
                                .ToList()
                })
                                  .ToList()
            };

            _cinemasRepository.Delete(cinema.Id);

            _cinemasRepository.Save();

            return(cinemaModel);
        }