public async Task <SeatDomainModel> AddSeat(SeatDomainModel newSeat) { Seat seatToCreate = new Seat() { AuditoriumId = newSeat.AuditoriumId, Number = newSeat.Number, Row = newSeat.Row }; var data = _seatsRepository.Insert(seatToCreate); 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); }
public ActionResult Create([Bind(Include = "Id,IsAvailable,SeatNumber,PassengerId,BusId,Time")] Seat seat) { if (ModelState.IsValid) { repository.Insert(seat); repository.Save(); return(RedirectToAction("Index")); } ViewBag.BusId = new SelectList(repository_b.All, "BusId", "NrReg", seat.BusId); ViewBag.PassengerId = new SelectList(repository_p.All, "Id", "Name", seat.PassengerId); return(View(seat)); }
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); }
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 } }); }