Ejemplo n.º 1
0
        public async Task <ActionResult <AspNetRolesReadModel> > Add([FromBody] AspNetRolesCreateModel createModel, CancellationToken cancellationToken)
        {
            var nesopsRole = new NesopsRole()
            {
                ConcurrencyStamp = Guid.NewGuid().ToString(),
                Description      = createModel.Description,
                DisplayName      = createModel.DisplayName,
                Name             = createModel.Name
            };
            var result = await _authorizeService.CreateRoleAsync(nesopsRole);

            if (result.Succeeded)
            {
                return(Ok(new BaseResponseModel <NesopsRole> {
                    message = "Create Role Successful", data = nesopsRole, code = 200
                }));
            }
            var responseModel = new BaseResponseModel <object> {
                message = "Create Role Fail", code = 400
            };

            foreach (var err in result.Errors)
            {
                responseModel.SetError(err.Code, err.Description);
            }
            return(BadRequest(responseModel));
        }
Ejemplo n.º 2
0
        public async Task <IdentityResult> CreateRoleAsync(NesopsRole role)
        {
            var result = await _roleManager.CreateAsync(role);

            return(result);
        }