Ejemplo n.º 1
0
        public async Task <ServiceResponse> RejectShelter(int id)
        {
            var getReponse = await shelterRepository.GetShelterApprovalInvariant(id);

            var serviceResponse = mapper.Map <ServiceResponse>(getReponse);

            if (getReponse.Successful)
            {
                if (getReponse.Data.IsApproved)
                {
                    serviceResponse.Successful = false;
                    serviceResponse.Message    = $"Failed to reject shelter, it was already approved";
                    serviceResponse.StatusCode = StatusCodes.Status400BadRequest;
                }
                else
                {
                    var repoResponse = await shelterRepository.DeleteShelter(id);

                    serviceResponse = mapper.Map <ServiceResponse>(repoResponse);

                    if (serviceResponse.Successful)
                    {
                        serviceResponse.Message = $"Shelter with id {id} was rejected";
                    }
                }
            }
            else
            {
                serviceResponse.Message    = $"Failed to reject shelter! {getReponse.Message}";
                serviceResponse.StatusCode = StatusCodes.Status400BadRequest;
            }

            return(serviceResponse);
        }