public ActionResult Index(bool isManage = false, long menuId = 0) { ViewBag.AllPages = _pageService.LoadAllByPageStatus(NccPage.NccPageStatus.Published); ViewBag.RecentPages = _pageService.LoadRecentPages(5); ViewBag.MenuList = _menuService.LoadAll(); ViewBag.MenuLocations = GlobalConfig.ActiveTheme.MenuLocations.ToList(); ViewBag.IsManage = false; if (isManage) { ViewBag.IsManage = true; } ViewBag.CurrentMenu = new NccMenu(); ViewBag.CurrentMenuItems = ""; if (menuId > 0) { //NccMenu nccMenu = _menuService.Get(menuId); NccMenu nccMenu = GlobalConfig.Menus.Where(x => x.Id == menuId).FirstOrDefault(); if (nccMenu != null) { ViewBag.CurrentMenu = nccMenu; string finalMenuList = ""; foreach (var menuItem in nccMenu.MenuItems.OrderBy(m => m.MenuOrder)) { finalMenuList += menuItemToString(menuItem, 1); } ViewBag.CurrentMenuItems = finalMenuList; } } return(View()); }
public JsonResult CreateEditMenu(string model) { var query = Request.Query; var menu = JsonConvert.DeserializeObject <NccMenuViewModel>(model); var r = new ApiResponse(); if (menu != null) { if (string.IsNullOrEmpty(menu.MenuLanguage)) { menu.MenuLanguage = ""; } if (menu.Name.Trim() == "") { r.IsSuccess = false; r.Message = "Please enter a menu name."; } else if (menu.Position.Trim() == "") { r.IsSuccess = false; r.Message = "Please select a menu position."; } else if (menu.Items.Count == 0) { r.IsSuccess = false; r.Message = "You cannot save an empty menu."; } else { if (menu.Id > 0) { if (_menuService.LoadAll(false, -1, menu.Name).Count > 0 && _menuService.LoadAll(false, -1, menu.Name).FirstOrDefault().Id != menu.Id) { r.IsSuccess = false; r.Message = "This menu name already used."; } else { NccMenu menuModel = CreateMenuObject(menu); CreateMenuItems(menuModel, menu); _menuService.Update(menuModel); r.IsSuccess = true; r.Message = "Menu updated successfully."; } } else { if (_menuService.LoadAll(false, -1, menu.Name).Count > 0) { r.IsSuccess = false; r.Message = "This menu name already exists."; } else { NccMenu menuModel = CreateMenuObject(menu); CreateMenuItems(menuModel, menu); _menuService.Save(menuModel); r.IsSuccess = true; r.Message = "Menu added successfully."; } } } } GlobalContext.Menus = _menuService.LoadAllSiteMenus(); ViewBag.MenuList = _menuService.LoadAll(); //ApiResponse rsp = new ApiResponse(); //rsp.IsSuccess = false; //rsp.Message = "Error occoured. Please fill up all field correctly."; //return Json(rsp); return(Json(r)); }