public IActionResult DeleteDogs(int dogID)
        {
            Dog deleteDog = _dogRepository.DeleteDog(dogID);

            if (deleteDog != null)
            {
                TempData["message"] = $"Delete {deleteDog.Name}.";
            }

            return(RedirectToAction("DogsList"));
        }
Exemple #2
0
 public ActionResult Delete(int id, Dog dog)
 {
     try
     {
         _dogRepo.DeleteDog(id);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Exemple #3
0
 public ActionResult Delete(int id, Dog dog)
 {
     try
     {
         _dogRepo.DeleteDog(id);
         return(RedirectToAction(nameof(Index)));
     }
     catch (Exception ex)
     {
         return(View(dog));
     }
 }
Exemple #4
0
 public ActionResult Delete(int id, Dog dog)
 {
     try
     {
         dog.OwnerId = GetCurrentUserId();
         _dogRepo.DeleteDog(id);
         return(RedirectToAction(nameof(Index)));
     }
     catch (Exception ex)
     {
         return(View(dog));
     }
 }
        public ActionResult Delete(Dog dog)
        {
            try
            {
                int ownerId = GetCurrentUserId();
                _dogRepository.DeleteDog(dog.Id, ownerId);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Exemple #6
0
 public ActionResult Delete(int id, Dog dog)
 {
     if (dog.OwnerId != GetCurrentUserId())
     {
         return(NotFound());
     }
     try
     {
         _dogRepo.DeleteDog(id);
         return(RedirectToAction("Index"));
     }
     catch (Exception ex)
     {
         return(View(dog));
     }
 }
Exemple #7
0
        public ActionResult Delete(int id, Dog dog)
        {
            try
            {
                // update the dogs OwnerId to the current user's Id
                dog.OwnerId = GetCurrentUserId();

                _dogRepo.DeleteDog(id);

                return(RedirectToAction("Index"));
            }
            catch (Exception)
            {
                return(View(dog));
            }
        }
Exemple #8
0
 public ActionResult Delete(int id, Dog dog)
 {
     if (dog.OwnerId != GetCurrentUserId())
     {
         return(RedirectToAction(nameof(NotFound)));
     }
     try
     {
         // TODO: Add delete logic here
         _dogRepo.DeleteDog(id);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View(dog));
     }
 }
Exemple #9
0
        public IActionResult DeleteDogForOwner(int ownerId, int dogId)
        {
            if (!_ownerRepository.OwnerExists(ownerId))
            {
                return(NotFound());
            }

            var dogFromRepo = _dogRepository.GetDogByOwner(ownerId, dogId);

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

            _dogRepository.DeleteDog(dogFromRepo);
            return(NoContent());
        }
Exemple #10
0
        public ActionResult DeleteDogForClient(int clientId, int dogId)
        {
            if (!_clientRepository.ClientExists(clientId))
            {
                return(NotFound());
            }
            var dogForClientFromRepo = _dogRepository.GetDog(dogId, clientId);

            if (dogForClientFromRepo == null)
            {
                return(NotFound());
            }
            _dogRepository.DeleteDog(dogForClientFromRepo);
            _dogRepository.Save();

            return(NoContent());
        }
Exemple #11
0
        public ActionResult Delete(int id, Dog dog)
        {
            int currentUserId = GetCurrentUserId();

            if (dog.OwnerId == currentUserId)
            {
                try
                {
                    _dogRepo.DeleteDog(id);
                    return(RedirectToAction(nameof(Index)));
                }
                catch
                {
                    return(View(dog));
                }
            }
            return(NotFound());
        }
Exemple #12
0
        public void Index_DeleteDog()
        {
            //Arrange
            IDogRepository sut = GetInMemoryDogRepository();
            Dog            dog = new Dog()
            {
                Id                = 3,
                DogName           = "Jo",
                Breed             = "Terrier x",
                DOB               = DateTime.Parse("2012-07-26"),
                Image             = "jo.jpg",
                ApplicationUserId = "d4eb7d23-d641-4c2d-8cd3-a036e08a3c65"
            };

            //Act
            Dog savedDog  = sut.CreateDog(dog);
            Dog savedDog1 = sut.DeleteDog(dog);

            //Assert
            Assert.Empty(sut.Dogs);
        }
Exemple #13
0
        public ActionResult Delete(int id, Dog dog)
        {
            int ownerId   = GetCurrentUserId();
            Dog deleteDog = _dogRepo.GetDogById(id);

            try
            {
                if (deleteDog.OwnerId != ownerId)
                {
                    return(NotFound());
                }
                else
                {
                    _dogRepo.DeleteDog(id);

                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                return(View(dog));
            }
        }
 public IActionResult Delete(Dog dog)
 {
     repository.DeleteDog(dog.Id);
     return(RedirectToAction("Index"));
 }