/// <summary> /// 删除还原 /// </summary> /// <param name="perm">实体类(权限)</param> /// <param name="ID">用户ID组</param> /// <param name="Flag">伪删除 还原标志</param> /// <returns></returns> public ActionResult DeletePermissions(BasePermission perm,string ID,string Flag) { BaseUser loginUser = Session["UserInfo"] as BaseUser; List<int> delIds = new List<int>(); if (ID.Length > 1) //选择多条 { string[] idstrs = ID.Split(','); foreach (var item in idstrs) { delIds.Add(int.Parse(item)); } } else //只选择一条 { delIds.Add(int.Parse(ID)); } if (Flag == "not") //伪删除 { foreach (var item in delIds) { var removePer = _permissionService.LoadEntities(p => p.ID == item).FirstOrDefault(); removePer.DeletionStateCode = 1; //更改用户的信息 removePer.ModifiedUserID = loginUser.Code; removePer.ModifiedBy = loginUser.UserName; removePer.ModifiedOn = DateTime.Now; _permissionService.UpdateEntity(removePer); } return Content("OK"); } if (Flag == "back") //还原 { foreach (var item in delIds) { var restoreUser = _permissionService.LoadEntities(u => u.ID == item).FirstOrDefault(); restoreUser.DeletionStateCode = 0; //更改用户的信息 restoreUser.ModifiedUserID = loginUser.Code; restoreUser.ModifiedBy = loginUser.UserName; restoreUser.ModifiedOn = DateTime.Now; _permissionService.UpdateEntity(restoreUser); } return Content("OK"); } else { if (_permissionService.DeletePermissions(delIds) > 0) { return Content("OK"); } return Content("Error"); } }
//!!!此处变量名不能为permission 不然接收到对象为null /// <summary> /// 添加权限 /// </summary> /// <param name="user">实体类(权限)</param> /// <returns>添加成功的标志</returns> public ActionResult AddPermission(BasePermission perm) { perm.Code = Guid.NewGuid().ToString(); perm.Enabled = 1; perm.DeletionStateCode = 0; perm.IsVisible = 1; perm.AllowEdit = 1; perm.AllowDelete = 1; BaseUser loginUser = Session["UserInfo"] as BaseUser; perm.CreateUserID = loginUser.Code; perm.CreateBy = loginUser.UserName; perm.CreateOn = DateTime.Now; _permissionService.AddEntity(perm); return Content("OK"); }
/// <summary> /// 创建新的 BasePermission 对象。 /// </summary> /// <param name="id">ID 属性的初始值。</param> /// <param name="actionType">ActionType 属性的初始值。</param> public static BasePermission CreateBasePermission(global::System.Int32 id, global::System.Int16 actionType) { BasePermission basePermission = new BasePermission(); basePermission.ID = id; basePermission.ActionType = actionType; return basePermission; }
/// <summary> /// 用于向 BasePermission EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet<T> 属性的 .Add 方法。 /// </summary> public void AddToBasePermission(BasePermission basePermission) { base.AddObject("BasePermission", basePermission); }
/// <summary> /// 修改权限信息 /// </summary> /// <param name="user">实体类(权限)</param> /// <returns></returns> public ActionResult UpdatePermission(BasePermission perm) { var editPermission = _permissionService.LoadEntities(c => c.ID == perm.ID).FirstOrDefault(); if (editPermission == null) { return Content("请您检查,错误信息"); } editPermission.PerMission = perm.PerMission; editPermission.RequestHttpType = perm.RequestHttpType; editPermission.RequestURL = perm.RequestURL; editPermission.ActionType = perm.ActionType; editPermission.SortCode = perm.SortCode; editPermission.AllowDelete = perm.AllowDelete; editPermission.AllowEdit = perm.AllowEdit; editPermission.IsVisible = perm.IsVisible; editPermission.Enabled = perm.Enabled; editPermission.Description = perm.Description; editPermission.ModifiedOn = DateTime.Parse(DateTime.Now.ToString()); BaseUser user = Session["UserInfo"] as BaseUser; editPermission.ModifiedUserID = user.Code; editPermission.ModifiedBy = user.UserName; if (_permissionService.UpdateEntity(editPermission)) { return Content("OK"); } return Content("Error"); }