Exemple #1
0
        public async Task <IActionResult> PatchUser([FromBody] JsonPatchDocument <UpdateUserDto> userPatch)
        {
            var user = await _userManager.FindByIdAsync(User.FindFirstValue(ClaimTypes.NameIdentifier));

            var userDto = _mapper.Map <UpdateUserDto>(user);

            userPatch.ApplyTo(userDto, ModelState);

            TryValidateModel(userDto);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _mapper.Map(userDto, user);

            var result = await _userManager.UpdateAsync(user);

            var mappedUser = _mapper.Map <UserDto>(user);

            if (!result.Succeeded)
            {
                return(BadRequest(result));
            }

            UserDtoI userDtoI = _mapper.Map <UserDtoI>(mappedUser);

            _messageBus.Publish(userDtoI, "exc.User", RabbitExchangeType.DirectExchange, $"Update:{userDtoI.Id}");

            return(Ok(mappedUser));
        }
Exemple #2
0
        public async Task <IActionResult> PutUser([FromBody] UpdateUserDto userDto)
        {
            var user = await _userManager.FindByIdAsync(User.FindFirstValue(ClaimTypes.NameIdentifier));

            var map = _mapper.Map(userDto, user);

            var result = await _userManager.UpdateAsync(map);

            if (!result.Succeeded)
            {
                return(BadRequest(result));
            }

            var mappedUser = _mapper.Map <UserDto>(user);

            UserDtoI userDtoI = _mapper.Map <UserDtoI>(mappedUser);

            _messageBus.Publish(userDtoI, "exc.User", RabbitExchangeType.DirectExchange, $"Update:{userDtoI.Id}");

            return(Ok(mappedUser));
        }