public async Task <IActionResult> UpdateSeatAsync(int id, SeatUpdateDto flightUpdateDto) { if (id != flightUpdateDto.Id) { return(BadRequest()); } var flightFromRepo = await _repository.GetByIdAsync(id); if (flightFromRepo == null) { return(NotFound()); } _mapper.Map(flightUpdateDto, flightFromRepo); //_repository.UpdateSeat(flightFromRepo.Value); // this is achieved by the previous code try { await _repository.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if ((await _repository.GetByIdAsync(id)) == null) { return(NotFound()); } } return(NoContent()); }
public IActionResult Put(int id, [FromBody] SeatUpdateDto dto, [FromServices] ISeatUpdate command) { dto.Id = id; _executor.ExecuteCommand(command, dto); return(StatusCode(204)); }
public void Execute(SeatUpdateDto request) { var seat = _context.Seats.Find(request.Id); if (seat == null) { throw new NotFoundException(request.Id, typeof(Seat)); } _validator.ValidateAndThrow(request); seat.Number = request.Number; seat.AuditoriumId = _context.Auditoriums.Where(a => a.Name == request.AuditoriumName).First().Id; _context.SaveChanges(); }