コード例 #1
0
        public async Task <bool> CreateRole(ClaimsPrincipal claim, ApplicationRoleViewModel data)
        {
            data.CreatedBy  = ExtBusinessLogic.UserValue(claim);
            data.ModifiedBy = ExtBusinessLogic.UserValue(claim);
            ApplicationRole roleData  = _mapper.Map <ApplicationRole>(data);
            bool            roleExist = await _roleManager.RoleExistsAsync(roleData.Name);

            if (roleExist)
            {
                throw new WebApiApplicationException(StatusCodes.Status409Conflict, ErrorMessages.RoleAlreadyExist);
            }

            roleData.GenerateNewId();
            var result = await _roleManager.CreateAsync(roleData);

            if (!result.Succeeded)
            {
                throw new WebApiApplicationException(StatusCodes.Status400BadRequest, ErrorMessages.CommonErrorMessage, result.Errors.ToList());
            }

            return(true);
        }