private IEnumerable <DirectoryModel> GetDirectories(ApplicationData application, string directoryName, bool includeSettings = false) { if (application == null) { throw new SettingsStoreException(Constants.ERROR_APPLICATION_NO_NAME); } string applicationName = application.Name; var data = GetDirectoriesData(application, directoryName); List <DirectoryModel> directories = new List <DirectoryModel>(); foreach (var item in data) { DirectoryModel model = new DirectoryModel(); model.AllowCreate = Auth.AllowCreateSetting(applicationName, item.Name); model.AllowDelete = Auth.AllowDeleteSetting(applicationName, item.Name); model.AllowWrite = Auth.AllowriteSetting(applicationName, item.Name); if (item.Description != null) { model.Description = item.Description.Trim(); } model.Name = item.Name.Trim(); directories.Add(model); } return(directories); }
public void SaveSettings(SettingStore store, IEnumerable <SettingModel> settings) { var currentSettings = GetSettingsFromStore(store); using (TransactionScope scope = TransactionScopeFactory.CreateReaduncommited()) { foreach (var item in settings) { if (item == null || string.IsNullOrWhiteSpace(item.Key)) { throw new SettingsStoreException(Constants.ERROR_SETTING_NO_KEY); } var existingOrNew = currentSettings.SingleOrDefault(s => s.Equals(item)); if (existingOrNew != null) { if (Auth.AllowriteSetting(store.ApplicationName, store.DirectoryName)) { existingOrNew.SettingInfo = item.Info; existingOrNew.SettingTypeInfo = item.TypeInfo; existingOrNew.SettingValue = item.Value; existingOrNew.Modified = DateTime.UtcNow; } else { throw new SettingsAuthorizationException(AuthorizationScope.Setting, AuthorizationLevel.Write, store.DirectoryName, Auth.CurrentIdentity.Id); } } else { if (Auth.AllowCreateSetting(store.ApplicationName, store.DirectoryName)) { if (!NameValidator.ValidateKey(item.Key)) { throw new SettingsStoreException(Constants.ERROR_SETTING_INVALID_KEY); } existingOrNew = CreateDataForStore(store); existingOrNew.SettingKey = item.Key.Trim().Replace(" ", " "); existingOrNew.SettingValue = item.Value; existingOrNew.SettingInfo = item.Info; existingOrNew.SettingTypeInfo = item.TypeInfo; existingOrNew.Created = DateTime.Now; existingOrNew.ObjecId = item.ObjectId; Store.Context.Settings.Add(existingOrNew); } else { throw new SettingsAuthorizationException(AuthorizationScope.Setting, AuthorizationLevel.Create, store.DirectoryName, Auth.CurrentIdentity.Id); } } } Store.Save(); scope.Complete(); } }