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);
            }
        }
Exemple #2
0
        public virtual void Update(UserSettings item)
        {
            var updateCommand = DatabaseQueryMaker.CreateUpdateUserSettings(item.UserId,
                                                                            item.Alias,
                                                                            item.SendNewsletter);

            DatabaseQueryExecutor.Update <UserSettings>(_connectionString, updateCommand);
        }