Exemple #1
0
        private async Task CleanupUserSettingsIfUserHasNoOtherTenants(UserTenantModel userTenantModel)
        {
            if (userTenantModel != null)
            {
                bool userHasOtherTenants = await this.DoesUserHaveAnyOtherTenants(userTenantModel.UserId);

                if (!userHasOtherTenants)
                {
                    UserSettingsInput settingsInput = new UserSettingsInput();
                    settingsInput.UserId = userTenantModel.UserId;
                    UserSettingsListModel userSettings = await this.settingsContainer.GetAllAsync(settingsInput);

                    if (userSettings != null && userSettings.Models != null)
                    {
                        foreach (UserSettingsModel settingsModel in userSettings.Models)
                        {
                            settingsInput.UserId     = settingsModel.UserId;
                            settingsInput.SettingKey = settingsModel.SettingKey;
                            await this.settingsContainer.DeleteAsync(settingsInput);
                        }
                    }
                }
            }
        }
        public virtual async Task <UserSettingsListModel> UpdateUserIdAsync(string oldUserId, string newUserId)
        {
            TableQuery <UserSettingsModel> query       = new TableQuery <UserSettingsModel>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, oldUserId));
            List <UserSettingsModel>       queryResult = await this.TableStorageClient.QueryAsync <UserSettingsModel>(this.TableName, query);

            UserSettingsListModel entries = new UserSettingsListModel("Get", queryResult);

            List <UserSettingsModel> resultList = new List <UserSettingsModel>();

            foreach (UserSettingsModel model in entries.Models)
            {
                UserSettingsInput userSettingsInput = new UserSettingsInput()
                {
                    UserId     = newUserId,
                    SettingKey = model.SettingKey,
                    Value      = model.Value,
                };
                resultList.Add(await this.UpdateAsync(userSettingsInput));
                userSettingsInput.UserId = oldUserId;
                await this.DeleteAsync(userSettingsInput);
            }

            return(new UserSettingsListModel("Get", resultList));
        }