public async Task <ActionResult> Post([FromBody] BookingDtoPost booking) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var result = await _service.Post(booking); if (result != null) { return(Created(new Uri(Url.Link("GetById", new { id = result.Id })), result)); } else { return(BadRequest()); } } catch (ArgumentException e) { return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message)); } }
public async Task <InputCreateBooking> Post(BookingDtoPost booking) { var visitor = await _visitorRepository.SelectAsync(booking.VisitorId); var administrator = await _repositoryAdmin.SelectAsync(booking.AdminId); var model = _mapper.Map <BookingModel>(booking); var entity = _mapper.Map <Booking>(model); entity.Administrator = administrator; entity.Visitor = visitor; var result = await _repository.InsertAsync(entity); var teste = _mapper.Map <InputCreateBooking>(result); return(teste); }