private async Task CheckUserProfile(string userId) { var profileExists = await _settingsStore.DoesExistAsync(userId); if (!profileExists) { throw new NotFoundException(new ErrorDto(ErrorCode.NotFound, "User settings do not exist.")); } }
public async Task <UserSettingsResponse> CreateUserSettingsAsync(UserProfileRequest request) { Ensure.That(request, nameof(request)).IsNotNull(); var settingsExist = await _store.DoesExistAsync(request.UserId); if (settingsExist) { throw new ConflictException(new ErrorDto(ErrorCode.ConflictError, "User profile already exists.")); } var profile = Mapper.Map <UserProfileRequest, UserSettings>(request); profile.Settings = GetDefaultSettings(); var newProfile = await _store.SaveAsync(profile); return(Mapper.Map <UserSettings, UserSettingsResponse>(newProfile)); }
public Task <bool> DoesExistAsync(string userId) { return(_cache.TryGetValue(GetKey(userId), out _) ? Task.FromResult(true) : _originalDataStore.DoesExistAsync(userId)); }