コード例 #1
0
        public IActionResult DeleteDogs(int dogID)
        {
            Dog deleteDog = _dogRepository.DeleteDog(dogID);

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

            return(RedirectToAction("DogsList"));
        }
コード例 #2
0
 public ActionResult Delete(int id, Dog dog)
 {
     try
     {
         _dogRepo.DeleteDog(id);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
コード例 #3
0
ファイル: DogController.cs プロジェクト: chadjones839/DogGo
 public ActionResult Delete(int id, Dog dog)
 {
     try
     {
         _dogRepo.DeleteDog(id);
         return(RedirectToAction(nameof(Index)));
     }
     catch (Exception ex)
     {
         return(View(dog));
     }
 }
コード例 #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));
     }
 }
コード例 #5
0
        public ActionResult Delete(Dog dog)
        {
            try
            {
                int ownerId = GetCurrentUserId();
                _dogRepository.DeleteDog(dog.Id, ownerId);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
コード例 #6
0
ファイル: DogsController.cs プロジェクト: Mtneer/DogGo
 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));
     }
 }
コード例 #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));
            }
        }
コード例 #8
0
ファイル: DogsController.cs プロジェクト: bloges56/DogGo
 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));
     }
 }
コード例 #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());
        }
コード例 #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());
        }
コード例 #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());
        }
コード例 #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);
        }
コード例 #13
0
ファイル: DogsController.cs プロジェクト: bstoudt01/DogGo
        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));
            }
        }
コード例 #14
0
 public IActionResult Delete(Dog dog)
 {
     repository.DeleteDog(dog.Id);
     return(RedirectToAction("Index"));
 }