public async Task <SeatAuditoriumDomainModel> GetSeatsByAuditoriumId(int auditoriumId) { var seatsInAuditorium = await _seatsRepository .GetSeatsByAuditoriumId(auditoriumId); if (seatsInAuditorium.Count() == 0) { return(null); } int maxRow = seatsInAuditorium.Max(seat => seat.Row); int maxNumber = seatsInAuditorium.Max(seat => seat.Number); seatsInAuditorium = seatsInAuditorium.OrderBy(x => x.Row).ThenBy(x => x.Number); SeatAuditoriumDomainModel seatAuditoriumDomainModel = new SeatAuditoriumDomainModel { Seats = seatsInAuditorium.Select(seat => new SeatDomainModel { Id = seat.Id, Number = seat.Number, Row = seat.Row, AuditoriumId = seat.AuditoriumId }).ToList(), MaxRow = maxRow, MaxNumber = maxNumber }; return(seatAuditoriumDomainModel); }
public async Task <IEnumerable <SeatDomainModel> > GetAllSeatsByAuditoriumId(int auditoriumId) { var seatsInAuditorium = await _seatsRepository.GetSeatsByAuditoriumId(auditoriumId); if (seatsInAuditorium.Count() == 0) { return(null); } IEnumerable <SeatDomainModel> seatDomainModels = seatsInAuditorium.Select(seat => new SeatDomainModel { Id = seat.Id, Row = seat.Row, Number = seat.Number, AuditoriumId = seat.AuditoriumId }); return(seatDomainModels); }
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 } }); }