Beispiel #1
0
 public ActionResult Delete(long id)
 {
     // 1. 是否还有角色引用该权限
     PowerBLL powerbll = new PowerBLL(new HengNuoWangDBContext());           // 避免使用同一个上下文时,数据重复
     Power power;
     if (id <= default(long) ||
         (power = powerbll.GetPower(id)) == null ||
         _rolePowerBll.IsPowerReferencedByRole(power.Id))
     {
         ViewBag.error = "权限正在被角色使用,请先解除再操作";
         return View("Error");
     }
     // 2. 删除
     bool success = _powerBll.DeletePower(id);
     if (!success)
     {
         ViewBag.error = "删除权限发生错误,错误未知";
         return View("Error");
     }
     // 3. 记录日志
     _adminOperationLogBll.AddAdminOperationLog(AdminUserId, string.Format("删除权限:【{0}】", power.Name));
     return RedirectToAction("List", "Power");
 }
Beispiel #2
0
 private void CheckPowerIdsAllExist(List<long> powerIds)
 {
     bool allExist = new PowerBLL(new HengNuoWangDBContext()).IsPowersAllExist(powerIds);
     if (!allExist)
     {
         throw new Exception(string.Format("操作异常:权限包含不存在'{0}'", string.Join(",", powerIds)));
     }
 }
Beispiel #3
0
        public ActionResult Edit(long id, string rolename, string powers)
        {
            Role role;
            if (CommonHelper.IsNullOrEmptyOrWhiteSpace(rolename) ||
                rolename.Length > 50 ||
                (role = _roleBll.GetRole(id)) == null)
            {
                return JsonHelper.GetJsonResult(_ERROR, "角色名错误");
            }

            List<long> powerIds;
            AdminHelper.GetRequestIds(powers, out powerIds);        // 修改时,角色的权限可以不要
            if (string.Equals(role.Name, rolename, StringComparison.CurrentCultureIgnoreCase) &&
                CommonHelper.IsListEquals(new RolePowerBLL(new HengNuoWangDBContext()).GetPowerIdsOfRole(role.Id),
                                            powerIds))
            {
                return JsonHelper.GetJsonResult(_ERROR, "角色名 或 所拥有的权限 至少得有一个发生变化");
            }

            List<string> oldPowers = new PowerBLL(new HengNuoWangDBContext()).GetPowerNamesOfRole(role.Id);
            string oldRoleName = role.Name;
            _roleBll.UpdateRole(new Role()
            {
                Id = role.Id,
                Name = rolename,
            }, powerIds);
            List<string> newPowers = new PowerBLL(new HengNuoWangDBContext()).GetPowerNamesOfRole(role.Id);

            _adminOperationLogBll.AddAdminOperationLog(AdminUserId,
                string.Format("编辑角色:【‘{0}’=>‘{1}’】; 权限:【‘{2}’=>‘{3}’】", oldRoleName, rolename,
                string.Join(",", oldPowers), string.Join(",", newPowers)));
            return JsonHelper.GetJsonResult(_OK, "编辑成功", "/Role/List");
        }