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)); }
public Dog DeleteDog(int DogId) { string dogJson = GetDogById(DogId); Dog dog = JsonConvert.DeserializeObject <Dog>(dogJson); _dogRepository.DeleteDog(DogId); return(dog); }
public ActionResult Delete(int id, Dog dog) { try { _dogRepo.DeleteDog(id); return(RedirectToAction("Index")); } catch (Exception ex) { return(View(dog)); } }
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)); }
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)); } }
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()); } }
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)); } }