/// <summary> /// 修改角色 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult Update(int id) { IRoleBLL bll = OperationContext.GetBLLSessionFactory().GetBLLSession().GetRoleBLL; Role role = new Role(); role = bll.GetListBy(r => r.ID == id).SingleOrDefault(); List<SelectListItem> departmentLst = new List<SelectListItem>(); List<Department> departments = new List<Department>(); IDepartmentBLL dbll = OperationContext.GetBLLSessionFactory().GetBLLSession().GetDepartmentBLL; departments = dbll.GetListBy(d => d.IsDelete == false); foreach (var department in departments) { departmentLst.Add(new SelectListItem { Text = department.DepartmentName, Value = department.ID.ToString(), Selected = role.DepartmentID == department.ID ? true : false }); } ViewBag.Departments = departmentLst; ViewBag.Role = role; return View(); }
/// <summary> /// 还原角色 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult Return(int id) { AjaxModel ajaxModel = new AjaxModel(); Role role = new Role(); try { IRoleBLL bll = OperationContext.GetBLLSessionFactory().GetBLLSession().GetRoleBLL; role = bll.GetListBy(r => r.ID == id).SingleOrDefault(); role.IsDelete = false; bll.Modify(role, "IsDelete"); ajaxModel.Statu = "ok"; ajaxModel.Msg = "还原成功"; } catch { ajaxModel.Statu = "ok"; ajaxModel.Msg = "还原成功"; } return Json(ajaxModel); }
/// <summary> /// 执行增加权限 /// </summary> /// <param name="model"></param> /// <returns></returns> public ActionResult DoAdd(Role model) { AjaxModel ajaxModel = new AjaxModel(); try { IRoleBLL bll = OperationContext.GetBLLSessionFactory().GetBLLSession().GetRoleBLL; model.AddTime = DateTime.Now; model.IsDelete = false; bll.Add(model); ajaxModel.Statu = "ok"; ajaxModel.Msg = "增加成功!"; ajaxModel.BackUrl = "/Admin/Role/Index"; } catch { ajaxModel.Statu = "err"; ajaxModel.Msg = "增加失败!"; } return Json(ajaxModel); }
/// <summary> /// 修改角色 /// </summary> /// <param name="model"></param> /// <returns></returns> public ActionResult DoUpdate(Role model) { AjaxModel ajaxModel = new AjaxModel(); Role role = new Role(); IRoleBLL bll = OperationContext.GetBLLSessionFactory().GetBLLSession().GetRoleBLL; try { role = bll.GetListBy(r => r.ID == model.ID).SingleOrDefault(); role.RoleName = model.RoleName; role.Remark = model.Remark; role.DepartmentID = model.DepartmentID; role.IsShow = model.IsShow; bll.Modify(role, "RoleName", "Remark", "DepartmentID", "IsShow"); ajaxModel.Statu = "ok"; ajaxModel.Msg = "修改成功"; ajaxModel.BackUrl = "/Admin/Role/Index"; } catch { ajaxModel.Statu = "err"; ajaxModel.Msg = "修改失败!"; } return Json(ajaxModel); }
/// <summary> /// 得到用户角色 /// </summary> /// <returns></returns> public ActionResult GetUserRoles(int uid) { DGModel<vRole> dgModel = new DGModel<vRole>(); List<UserRole> userRoles = new List<UserRole>(); List<vRole> vroles = new List<vRole>(); Role role = new Role(); try { IUserRoleBLL urbll = OperationContext.GetBLLSessionFactory().GetBLLSession().GetUserRoleBLL; IRoleBLL rbll = OperationContext.GetBLLSessionFactory().GetBLLSession().GetRoleBLL; userRoles = urbll.GetListBy(ur => ur.UserID == uid && ur.IsDelete == false, ur => ur.AddTime); foreach (var ur in userRoles) { role = rbll.GetListBy(r => r.ID == ur.RoleID).SingleOrDefault(); vroles.Add(new vRole(role)); } dgModel.rows = vroles; dgModel.total = vroles.Count(); } catch { dgModel.rows = null; dgModel.total = 0; } return Json(dgModel); }