示例#1
0
        public async Task <IActionResult> PostUserRoles([FromBody] UserRoleApiDto <TUserDtoKey, TRoleDtoKey> role)
        {
            var userRolesDto = _mapper.Map <TUserRolesDto>(role);
            await _identityService.CreateUserRoleAsync(userRolesDto);

            return(Ok());
        }
示例#2
0
        public async Task <ActionResult <TUserDto> > PostCustomer([FromBody] UserPasswordDto userPasswordDto)
        {
            if (!EqualityComparer <TUserDtoKey> .Default.Equals(userPasswordDto.user.Id, default))
            {
                return(BadRequest(_errorResources.CannotSetId()));
            }

            var(identityResult, userId) = await _identityService.CreateUserAsync(userPasswordDto.user);

            var createdUser = await _identityService.GetUserAsync(userId.ToString());

            //Add Role to the new User
            var role = await _identityService.GetRoleAsync("b66e640a-b235-49d9-96e5-d51e97255701");

            var userAndRole = new UserRoleApiDto <TUserDtoKey, TRoleDtoKey>();

            userAndRole.UserId = createdUser.Id;
            userAndRole.RoleId = role.Id;

            var userRolesDto = _mapper.Map <TUserRolesDto>(userAndRole);
            await _identityService.CreateUserRoleAsync(userRolesDto);

            //Set User Password
            userPasswordDto.password.UserId = createdUser.Id;
            var userChangePasswordDto = _mapper.Map <TUserChangePasswordDto>(userPasswordDto.password);
            await _identityService.UserChangePasswordAsync(userChangePasswordDto);

            return(CreatedAtAction(nameof(Get), new { id = createdUser.Id }, createdUser));
        }
示例#3
0
        public async Task <IActionResult> DeleteUserRoles([FromBody] UserRoleApiDto <TUserDtoKey, TRoleDtoKey> role)
        {
            var userRolesDto = _mapper.Map <TUserRolesDto>(role);

            await _identityService.GetUserAsync(userRolesDto.UserId.ToString());

            await _identityService.GetRoleAsync(userRolesDto.RoleId.ToString());

            await _identityService.DeleteUserRoleAsync(userRolesDto);

            return(Ok());
        }