コード例 #1
0
 public IActionResult Delete(Animals model)
 {
     if (ModelState.Count > 0)
     {
         var dogToDelete = dogRepository.GetDogs().Find(x => x.Id == model.Id);
         dogRepository.DeleteDog(dogToDelete);
     }
     return(View(model));
 }
コード例 #2
0
        public Dog DeleteDog(int DogId)
        {
            string dogJson = GetDogById(DogId);
            Dog    dog     = JsonConvert.DeserializeObject <Dog>(dogJson);

            _dogRepository.DeleteDog(DogId);

            return(dog);
        }
コード例 #3
0
ファイル: DogController.cs プロジェクト: heidijane/DogGo
 public ActionResult Delete(int id, Dog dog)
 {
     try
     {
         _dogRepo.DeleteDog(id);
         return(RedirectToAction("Index"));
     }
     catch (Exception ex)
     {
         return(View(dog));
     }
 }
コード例 #4
0
ファイル: DogsController.cs プロジェクト: alexcurnow/DogGo
        public ActionResult Delete(int id, Dog dog)
        {
            int OwnerId = GetCurrentUserId();

            dog.OwnerId = OwnerId;
            if (dog.OwnerId == OwnerId)
            {
                _dogRepo.DeleteDog(id);
                return(RedirectToAction(nameof(Index)));
            }

            return(View(dog));
        }
コード例 #5
0
        public ActionResult Delete(int id, Dog dog)
        {
            try
            {
                _dogRepo.DeleteDog(id);

                return(RedirectToAction("Index"));
            }
            catch
            {
                // If something goes wrong, just keep the user on the same page so they can try again
                return(View(dog));
            }
        }
コード例 #6
0
 public ActionResult Delete(int id, Dog dog)
 {
     if (dog.OwnerId == GetCurrentUserId())
     {
         try
         {
             _dogRepo.DeleteDog(dog.Id);
             return(RedirectToAction("Index"));
         }
         catch
         {
             return(View(dog));
         }
     }
     else
     {
         return(NotFound());
     }
 }
コード例 #7
0
ファイル: DogsController.cs プロジェクト: Keartroth/DogGo
        public ActionResult Delete(int id, Dog dog)
        {
            dog = _dogRepo.GetDogById(id);

            try
            {
                if (dog.OwnerId == GetCurrentUserId())
                {
                    _dogRepo.DeleteDog(id);

                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception ex)
            {
                return(View(dog));
            }
        }