Esempio n. 1
0
        public async Task <IActionResult> Patch([FromBody] UserPatchApiDto userPatchApiDto)
        {
            if (Request.Headers.TryGetValue("Authorization", out StringValues headerValues))
            {
                var token = _customEncoder.DecodeBearerAuth(headerValues.First());
                if (token != null)
                {
                    var user = await _userService.GetUserAsyncByToken(token);

                    if (user != null)
                    {
                        //Verify if the token exist and is not expire
                        if (await _authenticationService.CheckIfTokenIsValidAsync(token))
                        {
                            var userApiDto = await _userService.PatchUser(userPatchApiDto);

                            if (userApiDto == null)
                            {
                                return(StatusCode(404, "User not found."));
                            }
                            return(Ok(userApiDto));
                        }
                        return(StatusCode(401, "Invalid Token."));
                    }
                    return(StatusCode(403, "Invalid User."));
                }
                return(StatusCode(401, "Invalid Authorization."));
            }
            return(StatusCode(401, "Invalid Authorization."));
        }
Esempio n. 2
0
        /// <summary>
        /// Maps the user patch API dto to user.
        /// </summary>
        /// <returns>The user patch API dto to user.</returns>
        /// <param name="user">User.</param>
        /// <param name="userPatchApiDto">User patch API dto.</param>
        public User MapUserPatchApiDtoToUser(User user, UserPatchApiDto userPatchApiDto)
        {
            if (!string.IsNullOrEmpty(userPatchApiDto.PhoneNumber))
            {
                user.PhoneNumber = userPatchApiDto.PhoneNumber;
            }

            if (!string.IsNullOrEmpty(userPatchApiDto.City))
            {
                user.City = userPatchApiDto.City;
            }

            if (!string.IsNullOrEmpty(userPatchApiDto.Email))
            {
                user.Email = userPatchApiDto.Email;
            }

            if (!string.IsNullOrEmpty(userPatchApiDto.FirstName))
            {
                user.FirstName = userPatchApiDto.FirstName;
            }

            if (!string.IsNullOrEmpty(userPatchApiDto.LastName))
            {
                user.LastName = userPatchApiDto.LastName;
            }

            if (userPatchApiDto.IsAdmin.HasValue)
            {
                user.IsAdmin = userPatchApiDto.IsAdmin.Value;
            }

            if (userPatchApiDto.IsOwner.HasValue)
            {
                user.IsOwner = userPatchApiDto.IsOwner.Value;
            }

            if (userPatchApiDto.IsRoomer.HasValue)
            {
                user.IsRoomer = userPatchApiDto.IsRoomer.Value;
            }

            if (!string.IsNullOrEmpty(userPatchApiDto.PostalCode))
            {
                user.PostalCode = userPatchApiDto.PostalCode;
            }

            if (!string.IsNullOrEmpty(userPatchApiDto.Password))
            {
                user.Password = userPatchApiDto.Password;
            }

            if (!string.IsNullOrEmpty(userPatchApiDto.Description))
            {
                user.Description = userPatchApiDto.Description;
            }

            return(user);
        }
Esempio n. 3
0
 /// <summary>
 /// Patchs the user.
 /// </summary>
 /// <returns>The user.</returns>
 /// <param name="userPatchApiDto">User patch API dto.</param>
 public async Task <UserApiDto> PatchUser(UserPatchApiDto userPatchApiDto)
 {
     try
     {
         if (userPatchApiDto.UserId == null)
         {
             return(null);
         }
         return(await _dal.PatchUser(userPatchApiDto));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }