public async Task <ActionResult <AspNetRolesReadModel> > Add([FromBody] AspNetUsersCreateModel createModel, CancellationToken cancellationToken)
        {
            var user = new NesopsUser
            {
                UserName = createModel.UserName
            };
            var userRoles = new List <string>()
            {
                "ActiveUser"
            };
            var result = await _authorizeService.CreateUserAsync(user, createModel.Password, userRoles);

            if (result.Succeeded)
            {
                return(Ok(new BaseResponseModel <object> {
                    message = "Create User Successful", code = 200
                }));
            }
            var responseModel = new BaseResponseModel <object> {
                message = "Create User 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 <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));
        }