public ActionResult Edit(int?id) { BLL.BaseBLL <Entity.SysRole> bll = new BLL.BaseBLL <Entity.SysRole>(); if (id == null) { GetTree(); } else { GetTree(TypeHelper.ObjectToInt(id, 0)); } Entity.SysRole entity = new Entity.SysRole(); int num = TypeHelper.ObjectToInt(id, 0); if (num != 0) { entity = bll.GetModel(p => p.ID == num, null); if (entity == null) { return(PromptView("/admin/SysRole", "404", "Not Found", "信息不存在或已被删除", 5)); } } return(View(entity)); }
public ActionResult Edit(Entity.SysRole entity) { var isAdd = entity.ID == 0 ? true : false; BLL.BaseBLL <Entity.SysRole> bll = new BLL.BaseBLL <Entity.SysRole>(); GetTree(entity.ID); var qx = WebHelper.GetFormString("hid_qx"); //数据验证 if (isAdd) { if (bll.Exists(p => p.RoleName == entity.RoleName)) { ModelState.AddModelError("RoleName", "该组名已存在"); } } else { if (!bll.Exists(p => p.ID == entity.ID)) { return(PromptView("/admin/SysRole", "404", "Not Found", "该组不存在或已被删除", 5)); } var old_entity = bll.GetModel(p => p.ID == entity.ID, null); //验证组名是否存在 if (old_entity.RoleName != entity.RoleName) { if (bll.Exists(p => p.RoleName == entity.RoleName)) { ModelState.AddModelError("RoleName", "该组名已存在"); } } } if (ModelState.IsValid) { BLL.BLLSysRole bll_role = new BLL.BLLSysRole(); if (entity.ID == 0)//添加 { bll_role.Add(entity, qx); } else //修改 { bll_role.Modify(entity, qx); } return(PromptView("/admin/SysRole", "OK", "Success", "操作成功", 5)); } else { return(View(entity)); } }
/// <summary> /// 获取树数据 /// </summary> /// <param name="id">当前组ID,没有传0</param> private void GetTree(int id = 0) { BLL.BaseBLL <Entity.SysRole> bll_route = new BLL.BaseBLL <Entity.SysRole>(); BLL.BaseBLL <Entity.SysRoleRoute> bll_role_route = new BLL.BaseBLL <Entity.SysRoleRoute>(); Entity.SysRole role = null; if (id != 0) { role = bll_route.GetModel(p => p.ID == id, null); } List <Models.ViewModelTree> list = new List <Models.ViewModelTree>(); var route_group = new BLL.BLLSysRoute().GetListGroupByTag(); for (int i = 0; i < route_group.Count; i++) { int top_id = i + 10000; Models.ViewModelTree model = new Models.ViewModelTree(); model.id = top_id; model.name = route_group[i].Key; model.open = i < 4 ? true : false; model.pId = 0; list.Add(model); foreach (var item in route_group[i].ToList()) { Models.ViewModelTree model2 = new Models.ViewModelTree(); model2.id = item.ID; model2.name = item.Desc; model2.open = false; model2.pId = top_id; if (role != null) { model2.is_checked = bll_role_route.Exists(p => p.SysRoleID == role.ID && p.SysRouteID == item.ID); } list.Add(model2); } } ViewData["Tree"] = JsonHelper.ToJson(list).Replace("is_checked", "checked"); }