public async Task AddAsync(AddSeance seance) { var newSeance = _mapper.Map <AddSeance, Seance>(seance); var movie = await _dbContext.Movies.FirstOrDefaultAsync(x => x.Id == newSeance.MovieId); if (movie == null) { throw new Exception("Movie with this id doesn't exists."); } if (movie.Duration > newSeance.Duration) { throw new Exception("Seance duration cannot be shorter than movie duration."); } var availableRooms = await _roomService.GetAvailableRoomsOnTimeAsync(newSeance.SeanceStart, newSeance.SeanceStart.Add(newSeance.Duration)); if (!availableRooms.Select(r => r.Id).Contains(newSeance.RoomId)) { throw new Exception("Room is not available"); } await _dbContext.Seances.AddAsync(newSeance); await _dbContext.SaveChangesAsync(); }
private void updateSeanceList_Click(object sender, RoutedEventArgs e) { GetHall(); AddSeance addSeance = new AddSeance(HallNameList, FilmNameList, SeanceTimeList, allFilmList); addSeance.Owner = this; addSeance.Show(); }
public async Task <IActionResult> Post([FromBody] AddSeance seance) { if (!ModelState.IsValid) { return(BadRequest()); } await _seanceService.AddAsync(seance); return(Ok()); }