コード例 #1
0
ファイル: AdminUserBLL.cs プロジェクト: QJesus/ASP.Net-MVC
        public AdminUserAddNewStatus AddAdminUser(string username, string password, List<long> roleIds)
        {
            if (CommonHelper.IsNullOrEmptyOrWhiteSpace(username, password) || roleIds.Count <= 0)
            {
                throw new ArgumentNullException("username和password不能为null, string.Empty或只包含空格. roleIds至少包含一个元素");
            }
            int dbNums = new RoleBLL(new HengNuoWangDBContext()).GetRoles(roleIds).Count;
            if (dbNums != roleIds.Count)
            {
                throw new Exception(string.Format("‘{0}’中存在没有的角色", string.Join(",", roleIds)));
            }

            AdminUser au = GetAdminUser(username);
            if (au != null)
            {
                return AdminUserAddNewStatus.UserNameExist;
            }
            au = new AdminUser()
            {
                // Id
                UserName = username,
                Password = CommonHelper.CalcMd5(password),
                IsEnabled = true,
            };
            int row = dal.AddAdminUser(au, roleIds);
            if (row != (roleIds.Count + 1))
            {
                throw new ArgumentNullException(string.Format("出大事了,{0}添加了多条数据:{1}", au.UserName, string.Join(",", roleIds)));
            }
            return AdminUserAddNewStatus.Success;
        }
コード例 #2
0
ファイル: RoleController.cs プロジェクト: QJesus/ASP.Net-MVC
 public ActionResult Delete(long id)
 {
     RoleBLL rolebll = new RoleBLL(new HengNuoWangDBContext());
     Role role;
     if (id <= default(long) ||
         (role = rolebll.GetRole(id)) == null ||
         _rolePowerBll.IsRoleReferencedByPower(role.Id))                   // 正常操作,第三个条件才会影响
     {
         ViewBag.error = "角色被赋予了权限,请先取消所有权限再操作";
         return View("Error");
     }
     if (!_roleBll.DeleteRole(role.Id))
     {
         ViewBag.error = "删除角色发生错误,错误未知";
         return View("Error");
     }
     _adminOperationLogBll.AddAdminOperationLog(AdminUserId, string.Format("删除角色:【{0}】", role.Name));
     return RedirectToAction("List", "Role");
 }