public async Task <IActionResult> Update([FromRoute] string profileId, [FromBody] ProfileUpdateDto profileDto)
        {
            if (profileId != profileDto.Id)
            {
                return(BadRequest(new MessageObj("Invalid id(s)")));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(new { message = ModelState.Values.SelectMany(v => v.Errors).Select(e => e.ErrorMessage) }));
            }

            var updateProfile = _mapper.Map <Profile>(profileDto);

            try
            {
                Profile profile = await _profileService.UpdateProfile(updateProfile);

                return(Ok(profile));
            }
            catch (Exception e)
            {
                return(BadRequest(new MessageObj(e.Message)));
            }
        }
Пример #2
0
        public IActionResult UpdaeProfile(ProfileUpdateDto profile)
        {
            var claimsIdentity = User.Identity as ClaimsIdentity;
            var userDataClaim  = claimsIdentity?.FindFirst(ClaimTypes.UserData);
            var _userId        = userDataClaim?.Value;
            var user           = _usersService.UpdateProfile(_userId, profile);

            return(Ok(user));
        }