public UserSettings GetUserSettings(Guid userId) { var found = _cache.TryGetValue($"{userId}:settings", out UserSettings userSettings); if (!found) { var query = DatabaseQueryMaker.CreateSelectUserSettings(userId); userSettings = DatabaseQueryExecutor.Query <UserSettings>(_connectionString, query); if (userSettings == null) { throw new Exception("user not found"); } _cache.Set($"{userId}:settings", userSettings, new MemoryCacheEntryOptions() .SetSlidingExpiration(TimeSpan.FromHours(1))); return(userSettings); } else { return(userSettings); } }
public void SaveUserSettings(UserSettings userSettings) { // Last minute feature/hack. // Sounds familiar ? var alias = userSettings.Alias; if (alias.Length < 5 || !Regex.IsMatch(alias, "^[a-zA-Z][a-zA-Z0-9]*$")) { alias = AliasGenerator.New(); } var userId = userSettings.UserId; var selectQuery = DatabaseQueryMaker.CreateSelectUserSettings(userId); var selectedUserSettings = DatabaseQueryExecutor.Query <UserSettings>(_connectionString, selectQuery); if (selectedUserSettings != null) { var updateCommand = DatabaseQueryMaker.CreateUpdateUserSettings(userId, alias, selectedUserSettings.SendNewsletter); DatabaseQueryExecutor.Update <UserSettings>(_connectionString, updateCommand); } else { var insertCommand = DatabaseQueryMaker.CreateInsertUserSettings(userId, alias, userSettings.SendNewsletter); DatabaseQueryExecutor.Insert <UserSettings>(_connectionString, insertCommand); } }
public virtual void Update(UserSettings item) { var updateCommand = DatabaseQueryMaker.CreateUpdateUserSettings(item.UserId, item.Alias, item.SendNewsletter); DatabaseQueryExecutor.Update <UserSettings>(_connectionString, updateCommand); }
public virtual void Add(UserSettings item) { var insertCommand = DatabaseQueryMaker.CreateInsertUserSettings(item.UserId, item.Alias, item.SendNewsletter); DatabaseQueryExecutor.Insert <UserSettings>(_connectionString, insertCommand); }
public UserSettings Get(Guid id) { var query = DatabaseQueryMaker.CreateSelectUserSettings(id); return(DatabaseQueryExecutor.Query <UserSettings>(_connectionString, query)); }