public async Task <UserProfileResponse> Update(UserProfile?inputUserProfile) { if (inputUserProfile == null) { _logger.Warning(NullInput, nameof(UserProfile)); return(new UserProfileResponse(HttpBadRequest, BadRequestMsg)); } TrimWhitespaceInUserProfile(inputUserProfile); if (IsBadUpdateProfile(inputUserProfile)) { return(new UserProfileResponse(HttpBadRequest, BadRequestMsg)); } try { var storedUserProfile = await _profileDataService.GetByUsername(inputUserProfile.Username); if (storedUserProfile?.Id == null) { return(new UserProfileResponse(HttpUnauthorized)); } ApplyUpdate(storedUserProfile, inputUserProfile); await _profileDataService.Update(storedUserProfile); return(new UserProfileResponse(HttpOk, storedUserProfile)); } catch (Exception e) { _logger.Error(e, FailedToUpdate, inputUserProfile.Username); return(new UserProfileResponse(HttpInternalServerError, InternalServerErrorMsg)); } }