예제 #1
0
        public async Task <IActionResult> SetRole([FromForm] SetRolePara setRolePara)
        {
            var result = new Result
            {
                code = (int)StatusCodeEnum.Success,
                msg  = StatusCodeEnum.Success.GetEnumText()
            };
            Guid gid = Guid.Empty;

            if (!Guid.TryParse(setRolePara.Id, out gid))
            {
                result.code = (int)StatusCodeEnum.HttpMehtodError;
                result.msg  = StatusCodeEnum.HttpMehtodError.GetEnumText();
                return(Json(result));
            }
            if (string.IsNullOrWhiteSpace(setRolePara.RoleIds))
            {
                result.code = (int)StatusCodeEnum.HttpMehtodError;
                result.msg  = StatusCodeEnum.HttpMehtodError.GetEnumText();
                return(Json(result));
            }
            var setResult = await _userManagerServices.SetRoleAsync(setRolePara);

            if (setResult.code != 0)
            {
                return(Json(setResult));
            }
            return(Json(result));
        }
예제 #2
0
        public async Task <Result> SetRoleAsync(SetRolePara setRolePara)
        {
            var result = new Result();

            Guid gid   = Guid.Parse(setRolePara.Id);
            bool isDel = await _userManagerRepository.DelUserRoleByUserIdAsync(gid);

            if (isDel)
            {
                if (setRolePara.RoleIds != null)
                {
                    List <UserRole> userRoles = setRolePara.RoleIds.Split(',')
                                                .Select(d => new UserRole
                    {
                        Id            = Guid.NewGuid(),
                        UserManagerId = gid,
                        RoleId        = Guid.Parse(d)
                    }).ToList();
                    bool isAdd = await _userManagerRepository.SetRoleAsync(userRoles);

                    if (!isAdd)
                    {
                        result.code = (int)StatusCodeEnum.Accepted;
                        result.msg  = StatusCodeEnum.Accepted.GetEnumText();
                        return(result);
                    }
                }
                else
                {
                    result.code = (int)StatusCodeEnum.ParameterError;
                    result.msg  = StatusCodeEnum.ParameterError.GetEnumText();
                    return(result);
                }
            }
            else
            {
                result.code = (int)StatusCodeEnum.Accepted;
                result.msg  = StatusCodeEnum.Accepted.GetEnumText();
                return(result);
            }

            return(result);
        }