Ejemplo n.º 1
0
        public async Task <UserProfileResponse> Add(UserProfile?userProfile)
        {
            if (userProfile == null)
            {
                _logger.Warning(NullInput, nameof(userProfile));
                return(new UserProfileResponse(HttpBadRequest));
            }
            TrimWhitespaceInUserProfile(userProfile);
            if (IsBadAddProfile(userProfile))
            {
                _logger.Warning(InvalidInput, nameof(userProfile), userProfile);
                return(new UserProfileResponse(HttpBadRequest, BadRequestMsg));
            }
            try
            {
                var userAuthentication = _passwordService.HashPassword(userProfile.Password);
                var response           = await _profileDataService.Add(userProfile, userAuthentication);

                if (response.ApiFeedback.HttpCode == HttpBadRequest)
                {
                }
                if (response.ApiFeedback.HttpCode != HttpOk)
                {
                    return(new UserProfileResponse(response.ApiFeedback.HttpCode, response.ApiFeedback?.Explanation));
                }
                return(new UserProfileResponse(HttpOk, userProfile));
            }
            catch (SqlException e)
            {
                var msg = e.Message;
                if (msg.Contains("duplicate", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (msg.Contains("email", StringComparison.InvariantCultureIgnoreCase))
                    {
                        _logger.Debug(FailedToAddDuplicate, nameof(UserProfile.Email), userProfile);
                        return(new UserProfileResponse(HttpBadRequest, DuplicateEmail));
                    }
                    if (msg.Contains("username", StringComparison.InvariantCultureIgnoreCase))
                    {
                        _logger.Debug(FailedToAddDuplicate, nameof(UserProfile.Username), userProfile);
                        return(new UserProfileResponse(HttpBadRequest, DuplicateUserName));
                    }
                    _logger.Error(e, FailedToAddDuplicate, "Unkonwn column", userProfile);
                    throw;
                }
                _logger.Error(e, FailedToAdd, nameof(UserProfile), userProfile);
                return(new UserProfileResponse(HttpInternalServerError, InternalServerErrorMsg));
            }
            catch (Exception e)
            {
                _logger.Error(e, FailedToAdd, nameof(UserProfile), userProfile);
                return(new UserProfileResponse(HttpInternalServerError, InternalServerErrorMsg));
            }
        }
Ejemplo n.º 2
0
        public Dto.Profile Add(
            string firebaseId,
            string displayName,
            string notes)
        {
            var profile = GenerateProfile(firebaseId, displayName, notes);

            _profileDataService.Add(profile);

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