public IActionResult SubmitEditPinnedLink(DBPinnedLink mydbPinnedlink, string categoryID, int pinnedLinkID, string name, string link) { if (HttpContext.Session.GetString("auth") != "true") { return(RedirectToAction("Login", "Login")); } if (!ModelState.IsValid) { return(RedirectToAction("AdminIndex")); } try { int newcategoryID = Convert.ToInt32(categoryID); DBPinnedLink editedLink = pinnedLinkManager.dbPinnedLinks.Find(id => id.pinnedLinkID == pinnedLinkID); editedLink.categoryID = newcategoryID; editedLink.name = name; editedLink.link = link; pinnedLinkManager.SaveChanges(); } catch (Exception e) { Console.WriteLine("Problem submitting pinned link" + e); TempData["adminFeedBack"] = "Unsuccessful edit of pinned link"; } finally { TempData["adminFeedBack"] = "Successful edit of pinned link"; } return(RedirectToAction("AdminIndex")); }
public IActionResult SubmitAddLink(DBLink mydblink, string name, string link, int categoryID, bool pinnedToTop) { if (HttpContext.Session.GetString("auth") != "true") { return(RedirectToAction("Login", "Login")); } if (!ModelState.IsValid) { return(RedirectToAction("AdminIndex")); } try { Console.WriteLine("from submit" + name + link + categoryID + pinnedToTop); linkManager.Add(mydblink); linkManager.SaveChanges(); if (pinnedToTop == true) { DBPinnedLink dbpinlink = new DBPinnedLink(); dbpinlink.categoryID = categoryID; dbpinlink.name = name; dbpinlink.link = link; pinnedLinkManager.Add(dbpinlink); pinnedLinkManager.SaveChanges(); } } catch (Exception e) { Console.WriteLine("Problem adding link" + e); TempData["adminFeedBack"] = "Unsuccessful addition of link"; } finally { TempData["adminFeedBack"] = "Successful addition of link"; } return(RedirectToAction("AdminIndex")); }
public IActionResult DeletePinnedLink(int pinLinkID) { if (HttpContext.Session.GetString("auth") != "true") { return(RedirectToAction("Login", "Login")); } DBPinnedLink dbPinLink = new DBPinnedLink(); ViewBag.forDeleteLink = pinnedLinkManager.dbPinnedLinks.Find(id => id.pinnedLinkID == pinLinkID); return(View(dbPinLink)); }
// Submit delete request for pinned link public IActionResult SubmitDeletePinnedLink(DBPinnedLink dbPinLink) { if (HttpContext.Session.GetString("auth") != "true") { return(RedirectToAction("Login", "Login")); } try { pinnedLinkManager.Remove(dbPinLink); pinnedLinkManager.SaveChanges(); } catch (Exception e) { Console.WriteLine("Problem deleting pinned link" + e); TempData["adminFeedBack"] = "Unsuccessful deletion of pinned link"; } finally { TempData["adminFeedBack"] = "Successful deletion of pinned link"; } return(RedirectToAction("AdminIndex")); }