public ActionResult Index(MenuItemsViewModels model) { if (!ModelState.IsValid) { return(View(model)); } if (model.MenuItem.MenuItemId > 0) { model.MenuItem.ObjectState = ObjectState.Modified; _menuItemsService.InsertOrUpdateGraph(model.MenuItem); saveResult = _unitOfWork.SaveChanges(); if (saveResult.success) { //List<string> cacheKeys = MemoryCache.Default.Select(kvp => kvp.Key).ToList(); //foreach (string cacheKey in cacheKeys) //{ // MemoryCache.Default.Remove(cacheKey); //} TempData["SuccessMessage"] = "Updated successfully."; RouteData.Values.Remove("id"); } else { AddErrors(saveResult.errors, saveResult.ErrorMessage); return(View(model)); } } else { model.MenuItem.ObjectState = ObjectState.Added; _menuItemsService.InsertOrUpdateGraph(model.MenuItem); saveResult = _unitOfWork.SaveChanges(); if (saveResult.success) { TempData["SuccessMessage"] = "Added successfully."; } else { AddErrors(saveResult.errors, saveResult.ErrorMessage); return(View(model)); } } return(RedirectToAction("Index")); }
public ActionResult Index(int id = 0, int rid = 0) { MenuItemsViewModels model = new MenuItemsViewModels(); model.MenuItemsGroupList = _menuItemsService.GetAllGroups(); if (id > 0) { model.MenuItem = _menuItemsService.Find(id).data; } else { model.MenuItem = new MenuItems(); model.MenuItem.GroupId = rid; } if (rid > 0) { model.MenuItemsList = _menuItemsService.GetAllResourcesByGroupId(rid); } else { model.MenuItemsList = _menuItemsService.GetAllResourcesByGroupId(); } return(View(model)); }