public async Task <ProjectionDomainModel> DeleteProjection(Guid id)
        {
            var reservationData = _reservationService.DeleteByProjectionId(id);

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

            var data = _projectionsRepository.Delete(id);

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

            _projectionsRepository.Save();

            ProjectionDomainModel domainModel = new ProjectionDomainModel
            {
                Id             = data.Id,
                MovieId        = data.MovieId,
                AuditoriumId   = data.AuditoriumId,
                ProjectionTime = data.DateTime
            };

            return(domainModel);
        }
Пример #2
0
        public async Task <CreateProjectionResultModel> DeleteProjection(Guid id)
        {
            var existingProjections = _projectionsRepository.GetProjectionById(id);
            var ticketsInProjection = _ticketRepository.GetAllForSpecificProjection(id);

            if (existingProjections == null)
            {
                CreateProjectionResultModel errorModel = new CreateProjectionResultModel
                {
                    ErrorMessage = Messages.PROJECTION_IN_FUTURE,
                    IsSuccessful = true
                };
                return(errorModel);
            }

            if (existingProjections.DateTime > DateTime.Now)
            {
                CreateProjectionResultModel errorModel = new CreateProjectionResultModel
                {
                    ErrorMessage = Messages.PROJECTION_IN_FUTURE,
                    IsSuccessful = false,
                    Projection   = new ProjectionDomainModel
                    {
                        AuditoriumId   = existingProjections.AuditoriumId,
                        Id             = existingProjections.Id,
                        MovieId        = existingProjections.MovieId,
                        AuditoriumName = existingProjections.Auditorium.Name,
                        MovieTitle     = existingProjections.Movie.Title,
                        ProjectionTime = existingProjections.DateTime
                    }
                };
                return(errorModel);
            }
            foreach (var ticket in ticketsInProjection)
            {
                _ticketRepository.Delete(ticket.Id);
            }
            _projectionsRepository.Delete(id);

            _projectionsRepository.Save();

            CreateProjectionResultModel domainModel = new CreateProjectionResultModel
            {
                ErrorMessage = null,
                IsSuccessful = true,
                Projection   = new ProjectionDomainModel
                {
                    AuditoriumName = existingProjections.Auditorium.Name,
                    AuditoriumId   = existingProjections.AuditoriumId,
                    Id             = existingProjections.Id,
                    MovieId        = existingProjections.MovieId,
                    MovieTitle     = existingProjections.Movie.Title
                }
            };

            return(domainModel);
        }
Пример #3
0
        public async Task <AuditoriumResultModel> DeleteAuditorium(int id)
        {
            var existingAuditorium = await _auditoriumsRepository.GetByIdAsync(id);

            if (existingAuditorium == null)
            {
                return(new AuditoriumResultModel
                {
                    ErrorMessage = Messages.AUDITORIUM_DOES_NOT_EXIST,
                    IsSuccessful = false
                });
            }
            var projectionsInAuditorium = _projectionsRepository.GetAllOfSpecificAuditorium(id);

            if (projectionsInAuditorium != null)
            {
                foreach (var projection in projectionsInAuditorium)
                {
                    if (projection.DateTime > DateTime.Now)
                    {
                        return(new AuditoriumResultModel
                        {
                            ErrorMessage = Messages.PROJECTION_IN_FUTURE,
                            IsSuccessful = false
                        });
                    }
                    _projectionsRepository.Delete(projection.Id);
                    await _ticketService.DeleteTicketFromProjection(projection.Id);
                }
            }
            var seatsInAuditorium = _seatsRepository.GetAllOfSpecificAuditorium(id);

            if (seatsInAuditorium != null)
            {
                foreach (var seat in seatsInAuditorium)
                {
                    _seatsRepository.Delete(seat.Id);
                }
            }
            var data = _auditoriumsRepository.Delete(id);

            _auditoriumsRepository.Save();

            AuditoriumResultModel domainModel = new AuditoriumResultModel
            {
                ErrorMessage = null,
                IsSuccessful = true,
                Auditorium   = new AuditoriumDomainModel
                {
                    CinemaId = existingAuditorium.CinemaId,
                    Id       = existingAuditorium.Id,
                    Name     = existingAuditorium.Name
                }
            };

            return(domainModel);
        }
Пример #4
0
        public async Task <DeleteMovieModel> DeleteMovie(Guid id)
        {
            var data = _moviesRepository.Delete(id);

            if (data == null)
            {
                return(null);
            }
            var projectionsForDelete = await _projectionsRepository.GetAllFromOneMovie(id);

            foreach (var projectionForDelete in projectionsForDelete)
            {
                if (projectionForDelete.DateTime < DateTime.Now)
                {
                    _projectionsRepository.Delete(projectionForDelete.Id);
                }
                else
                {
                    return(new DeleteMovieModel());
                }
                var ticketsForDelete = _ticketRepository.GetAllForSpecificProjection(projectionForDelete.Id);
                foreach (var ticketForDelete in ticketsForDelete)
                {
                    _ticketRepository.Delete(ticketForDelete.Id);
                }
            }

            var movieTags = await _movieTagsRepository.GetAllForSpecificMovie(id);

            foreach (var movieTag in movieTags)
            {
                _movieTagsRepository.Delete(movieTag.Id);
            }

            _moviesRepository.Save();

            DeleteMovieModel deleteMovieModel = new DeleteMovieModel
            {
                ErrorMessage     = null,
                IsSuccessful     = true,
                MovieDomainModel = new MovieDomainModel
                {
                    Id      = data.Id,
                    Title   = data.Title,
                    Current = data.Current,
                    Year    = data.Year,
                    Rating  = data.Rating ?? 0
                }
            };

            return(deleteMovieModel);
        }
Пример #5
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);
        }