public ActionResult Create(MenuSiteModel Model) { if (String.IsNullOrEmpty(Model.Name)) { return(Create().WithError("Please provide a valid name!")); } MenuSite newEntry = new MenuSite(); newEntry.MenuName = Model.Name; using (CityInfoDBEntities dc = new CityInfoDBEntities()) { var MenuSiteModelId = dc.MenuSites.FirstOrDefault(i => i.MenuName == Model.SelectedParent); if (MenuSiteModelId != null) { newEntry.ParentId = MenuSiteModelId.MenuId; } else { newEntry.ParentId = 0; } dc.MenuSites.Add(newEntry); dc.SaveChanges(); } return(RedirectToAction <HomeController>(c => c.Index()).WithSuccess("Item Created!")); }
public ActionResult Index() { Tree = new List <MenuSite>(); using (CityInfoDBEntities dc = new CityInfoDBEntities()) { Tree = dc.MenuSites.OrderBy(T => T.MenuId).ToList(); } return(View(Tree)); }
public void DeleteBranch(CityInfoDBEntities dc, MenuSite branch) { var childList = dc.MenuSites.Where(a => a.ParentId == branch.MenuId).ToList(); if (childList.Count != 0) { foreach (var child in childList) { DeleteBranch(dc, child); } } dc.MenuSites.Remove(branch); }
public ActionResult Delete() { var myList = new List <string>(); using (CityInfoDBEntities dc = new CityInfoDBEntities()) { var ListQuery = from q in dc.MenuSites orderby q.MenuId select q.MenuName; myList.AddRange(ListQuery.Distinct()); ViewBag.myList = new SelectList(myList); } return(View()); }
public ActionResult Create() { var model = new MenuSiteModel(); var myList = new List <string>(); using (CityInfoDBEntities dc = new CityInfoDBEntities()) { var ListQuery = from q in dc.MenuSites orderby q.MenuId select q.MenuName; myList.AddRange(ListQuery); //ViewBag.myList = new SelectList(myList); model.TreeList = new SelectList(myList); } return(View(model)); }
public ActionResult Delete(string myList) { using (CityInfoDBEntities dc = new CityInfoDBEntities()) { var MenuSiteEntry = dc.MenuSites.FirstOrDefault(i => i.MenuName == myList); if (MenuSiteEntry != null) { DeleteBranch(dc, MenuSiteEntry); dc.SaveChanges(); } else { return(RedirectToAction <HomeController>(c => c.Index()) .WithError("Please select a valid item to delete!")); } } return(RedirectToAction <HomeController>(c => c.Index()) .WithSuccess("Branch Item successfully deleted.")); }