//IActionResult é mais genérico e conseguimos retornar tanto o Unauthorized, quanto o Ok. public IActionResult Create(CreateRentRequest request) { StringValues userId; if (!Request.Headers.TryGetValue("UserId", out userId)) { return(Unauthorized()); } var user = _usersService.GetById(Guid.Parse(userId)); if (user == null) { return(Unauthorized()); } var response = _rentsService.Create( request.CustomerId, request.RentedProductId, request.Date, request.ContractStartDate, request.ContractEndDate, request.Observation ); if (!response.IsValid) { return(BadRequest(response.Errors)); } return(NoContent()); }
public async Task <RentDto> Post(RentDto dto) { return(await _rentsService.Create(dto)); }