Example #1
0
        public async Task <ShowDomainModel> DeleteShow(int id)
        {
            var existingShow = await _showsRepository.GetByIdAsync(id);

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

            if (existingShow.Reservations.Any())
            {
                return(null);
            }

            var deletedShow = await _showsRepository.Delete(id);

            _showsRepository.Save();

            return(new ShowDomainModel
            {
                Id = deletedShow.Id,
                ShowTime = deletedShow.ShowTime,
                TicketPrice = deletedShow.TicketPrice
            });
        }
        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
                }
            });
        }
Example #3
0
 public IActionResult Delete(int id)
 {
     if (id > 0)
     {
         var deleted = repo.Delete(id);
         if (deleted)
         {
             return(Ok(new
             {
                 status = "OK",
                 message = "Show has successfully deleted"
             }));
         }
     }
     return(NotFound(new { status = "fail", message = "Show failed to be deleted" }));
 }