public IActionResult CancelPetPolicy(string change, int id) { int? activeId = HttpContext.Session.GetInt32("activeUser"); bool isValid = SecurityCheck.CheckActiveUserVsPet(activeId, id, _context); if (isValid == false) { //Redirected to Logout as user may be malicious return(RedirectToAction("Logout", "PetOwner")); } var changingPet = _context.pet.SingleOrDefault(p => p.Id == id); //Switch case allows one route/method to handle different yet similar logic as needed switch (change) { case "Transfer": return(RedirectToAction("Transfer", new{ id = id })); case "Cancel": changingPet.Active = false; break; case "Activate": changingPet.Active = true; break; } _context.SaveChanges(); return(RedirectToAction("Dashboard", "PetOwner")); }
public IActionResult Transfer(int id) { int? activeId = HttpContext.Session.GetInt32("activeUser"); bool isValid = SecurityCheck.CheckActiveUserVsPet(activeId, id, _context); if (isValid == false) { //Redirected to Logout as user may be malicious return(RedirectToAction("Logout", "PetOwner")); } var transferPet = _context.pet.SingleOrDefault(p => p.Id == id); TransferOwner transfer = new TransferOwner { PetToBeTransferred = (Pet)transferPet, CurrentOwner = _context.petowner.SingleOrDefault(o => o.Id == (int)activeId) }; return(View(transfer)); }