示例#1
0
        public IActionResult Delete(int shelterID)
        {
            Shelter deleteShelter = repository.DeleteShelter(shelterID);

            if (deleteShelter != null)
            {
                TempData["message"] = $"{deleteShelter.Name} foi excluido.";
            }
            return(RedirectToAction("List"));
        }
        public async Task <ActionResult <Shelter> > DeleteShelter(int id)
        {
            var shelter = _repository.DeleteShelter(id);

            if (shelter == null)
            {
                return(NotFound());
            }

            return(shelter);
        }
示例#3
0
        public async Task <ServiceResponse <ShelterDto, GetAccountDto> > AddShelter(ShelterDto shelterDto)
        {
            var shelter = mapper.Map <Shelter>(shelterDto);

            shelter.IsApproved = true;
            var addShelterResult = await shelterRepository.AddShelter(shelter);

            var serviceResponse = mapper.Map <RepositoryResponse <Shelter>, ServiceResponse <ShelterDto, GetAccountDto> >(addShelterResult);

            if (addShelterResult.Successful)
            {
                var addAccountResult = await accountService.AddShelterAccount(addShelterResult.Data);

                if (addAccountResult.Successful)
                {
                    serviceResponse.Metadata = addAccountResult.Data;
                }
                else
                {
                    serviceResponse.Data       = null;
                    serviceResponse.Successful = false;
                    var deleteResult = await shelterRepository.DeleteShelter(addShelterResult.Data.Id);

                    if (deleteResult.Successful)
                    {
                        serviceResponse.Message = $"Failed to add shelter acccount: {addAccountResult.Message}";
                    }
                    else
                    {
                        serviceResponse.Message = $"Data corrupted! Failed to add shelter account and remove shelter after failing to add acccount: {addAccountResult.Message} {deleteResult.Message}";
                    }
                }
            }
            else
            {
                serviceResponse.StatusCode = StatusCodes.Status400BadRequest;
            }

            return(serviceResponse);
        }
示例#4
0
        public IActionResult DeleteShelter(int shelterId)
        {
            if (!shelterRepo.ShelterExists(shelterId))
            {
                return(NotFound());
            }

            var shelter = shelterRepo.GetShelter(shelterId);

            if (!shelterRepo.DeleteShelter(shelter))
            {
                ModelState.AddModelError("", $"Error while deleting object {shelter.Name}");
                return(StatusCode(500, ModelState));
            }
            return(NoContent());
        }
        public async void DeleteShelterWithoutDogsFailsForNotExistingShelter()
        {
            var result = await shelterRepository.DeleteShelter(-1);

            Assert.False(result.Successful);
        }