public async Task <ActionResult> UpdateDonorPJ(Guid id, [FromBody] DonorPJUpdateDto donorDto)
        {
            // Check if the donor already exists
            var donorPJ = await DonorPJApplication.GetDonorPJ((d) => d.Id.Equals(id));

            if (donorPJ == null)
            {
                ErrorMessage error = new ErrorMessage((int)HttpStatusCode.BadRequest, $"O doador PJ, {id}, não foi encontrado.");
                return(BadRequest(error));
            }

            if (!donorPJ.CNPJ.Equals(donorDto.CNPJ) || !donorPJ.CompanyName.ToLower().Equals(donorDto.CompanyName.ToLower()))
            {
                // Check if the donor already exists
                bool hasDonor = await DonorPJApplication.ExistDonorPJ(d => d.CNPJ.Equals(donorDto.CNPJ) && d.CompanyName.ToLower().Equals(donorDto.CompanyName.ToLower()));

                if (hasDonor)
                {
                    ErrorMessage error = new ErrorMessage((int)HttpStatusCode.BadRequest, $"O doador PJ, {donorDto.CNPJ} - {donorDto.CompanyName}, já existe.");
                    return(BadRequest(error));
                }
            }

            await DonorPJApplication.UpdateDonorPJ(donorPJ, donorDto);

            return(Ok());
        }
        public async Task <ActionResult <DonorPJResponseDto> > GetDonorPJById(Guid id)
        {
            DonorPJResponseDto donorDto = await DonorPJApplication.GetDonorPJ(i => i.Id.Equals(id));

            if (donorDto == null)
            {
                ErrorMessage error = new ErrorMessage((int)HttpStatusCode.NotFound, $"O doador PJ, {id}, não foi encontrado.");
                return(NotFound(error));
            }

            return(Ok(donorDto));
        }
        public async Task <ActionResult> DeleteDonorPJ(Guid id)
        {
            // Check if the donor exists
            DonorPJResponseDto donorDto = await DonorPJApplication.GetDonorPJ(i => i.Id.Equals(id));

            if (donorDto == null)
            {
                ErrorMessage error = new ErrorMessage((int)HttpStatusCode.NotFound, $"O doador PJ, {id}, não foi encontrado.");
                return(NotFound(error));
            }

            await DonorPJApplication.DeleteDonorPJ(donorDto);

            return(NoContent());
        }
        public async Task <IActionResult> CreateDonorPJ([FromBody] DonorPJCreateDto 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 DonorPJApplication.ExistDonorPJ(d => d.CNPJ.Equals(donorDto.CNPJ) && d.CompanyName.ToLower().Equals(donorDto.CompanyName.ToLower()));

            if (hasDonor)
            {
                ErrorMessage error = new ErrorMessage((int)HttpStatusCode.BadRequest, $"O doador PJ, {donorDto.CNPJ} - {donorDto.CompanyName}, já existe.");
                return(BadRequest(error));
            }

            var donorId = await DonorPJApplication.CreateDonorPJ(donorDto);

            return(CreatedAtRoute("GetDonorPJById", new { id = donorId }, null));
        }
        public async Task <ActionResult <PagedResponse <DonorPJResponseDto> > > GetDonorsPJ([FromQuery] PaginationParams paginationParams)
        {
            PagedResponse <DonorPJResponseDto> pagedResponse = await DonorPJApplication.GetAllDonorsPJ(paginationParams);

            return(Ok(pagedResponse));
        }
 public DonorsPJController(DonorPJApplication donorPJApplication,
                           UserApplication userApplication)
 {
     this.DonorPJApplication = donorPJApplication;
     this.UserApplication    = userApplication;
 }