Пример #1
0
        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));
            }
        }
Пример #2
0
        public Dto.Profile Update(
            string firebaseId,
            int profileId,
            string displayName,
            string notes)
        {
            var profile = _profileDataService.Get(profileId);

            profile.DisplayName = displayName;
            profile.Notes       = notes;

            profile.AddTimestamp(firebaseId);

            _profileDataService.Update(profile);

            return(_mapper.Map <Dto.Profile>(profile));
        }