public ActionResult Edit(string Name, int id) { if (id <= 0) { throw new HttpRequestValidationException(); } IMenusService menuSrv = IoC.Resolve <IMenusService>(); Menu model = menuSrv.Getbykey(id); try { TryUpdateModel <Menu>(model); model.Name = Name; menuSrv.Save(model); menuSrv.CommitChanges(); Messages.AddFlashMessage("Cập nhật thành công!"); log.Info("Update menu by:" + HttpContext.User.Identity.Name + ", Date:" + DateTime.Now); MenuModels.ResetMenu(); return(RedirectToAction("Index")); } catch (Exception ex) { log.Error("Update menu error", ex); ViewBag.ParentMenus = menuSrv.GetParent(model.ComID); Messages.AddErrorMessage("Có lỗi trong quá trình xử lý, vui lòng thực hiện lại!"); return(View(model)); } }
public ActionResult Edit(int id) { IMenusService menuSrv = IoC.Resolve <IMenusService>(); ICompanyService compSrv = IoC.Resolve <ICompanyService>(); Menu model = menuSrv.Getbykey(id); ViewBag.ParentMenus = menuSrv.GetParent(model.ComID); return(View(model)); }
public static IList <MenuModel> GetTree(int comId, int rootId) { List <MenuModel> MenuTrees = new List <MenuModel>(); IMenusService menuSrv = IoC.Resolve <IMenusService>(); IList <Menu> menus = menuSrv.GetList(comId); var baseMenu = new MenuModel(menuSrv.Getbykey(rootId)); MenuTrees.Add(baseMenu); foreach (var item in menus.Where(x => x.ParentId == rootId)) { var root = new MenuModel(item, 1); MenuTrees.Add(root); BuildMenuTree(menus, root); } return(MenuTrees); }