/// <summary> /// Returns the user preferences for a user, ensuring a value is returned /// </summary> /// <param name="userId">User ID</param> /// <param name="valueUpdate">Value Update Function</param> /// <returns>Task</returns> private async Task UpdateUserPreferences(string userId, Action <UserPreferences> valueUpdate) { bool isNewEntry = false; UserPreferences preferences = await _UserPreferencesCollection.Find(u => u.Id == userId).FirstOrDefaultAsync(); if (preferences == null) { preferences = UserPreferences.CreateDefaultUserPreferences(userId); isNewEntry = true; } valueUpdate(preferences); if (isNewEntry) { await _UserPreferencesCollection.InsertOneAsync(preferences); } else { await _UserPreferencesCollection.ReplaceOneAsync(u => u.Id == userId, preferences); } }