public async Task <ActionResult> UpdateDonorPF(Guid id, [FromBody] DonorPFUpdateDto donorDto) { // Check if the donor already exists var donorPF = await DonorPFapplication.GetDonorPF((d) => d.Id.Equals(id)); if (donorPF == null) { ErrorMessage error = new ErrorMessage((int)HttpStatusCode.BadRequest, $"O doador PF, {id}, não foi encontrado."); return(BadRequest(error)); } if (!donorPF.CPF.Equals(donorDto.CPF)) { // Check if the donor already exists bool hasDonor = await DonorPFapplication.ExistDonorPF((d) => d.CPF.Equals(donorDto.CPF)); if (hasDonor) { ErrorMessage error = new ErrorMessage((int)HttpStatusCode.BadRequest, $"O doador PF, {donorDto.CPF}, já existe."); return(BadRequest(error)); } } await DonorPFapplication.UpdateDonorPF(donorPF, donorDto); return(Ok()); }
public async Task <IActionResult> CreateDonorPF([FromBody] DonorPFCreateDto donorDto) { var userDto = await UserApplication.GetUserDto(u => u.Login.ToLower().Equals(donorDto.Login.ToLower())); if (userDto != null) { ErrorMessage error = new ErrorMessage((int)HttpStatusCode.BadRequest, $"O usuário, {donorDto.Login}, já existe."); return(BadRequest(error)); } // Check if the donor already exists bool hasDonor = await DonorPFapplication.ExistDonorPF((d) => d.CPF.Equals(donorDto.CPF.ToLower())); if (hasDonor) { ErrorMessage error = new ErrorMessage((int)HttpStatusCode.BadRequest, $"O doador PF, {donorDto.CPF}, já existe."); return(BadRequest(error)); } var donorId = await DonorPFapplication.CreateDonorPF(donorDto); return(CreatedAtRoute("GetDonorPFById", new { id = donorId }, null)); }