public DTOConfigurationSaveResults Post([FromBody] DTOConfigurationIncludingSchemaDetails configurationDetails) { try { ConfigurationNew newRecord = new ConfigurationNew() { JSONSchema = configurationDetails.JSONSchema, Name = configurationDetails.Name, SystemName = configurationDetails.SystemName, XML = configurationDetails.XML, XMLSchema = configurationDetails.XMLSchema, Tags = configurationDetails.Tags }; if (configurationDetails.Id.HasValue && configurationDetails.Id.Value != 0) { return(_convertSaveResults(_dataStore.UpdateConfigurationSection(configurationDetails.Id.Value, newRecord))); } else { return(_convertSaveResults(_dataStore.AddConfigurationSection(newRecord))); } } catch (Exception exc) { throw; } }
public ConfigurationSaveResults UpdateConfigurationSection(int id, ConfigurationNew configuration) { throw new NotImplementedException(); }
public ConfigurationSaveResults AddConfigurationSection(ConfigurationNew section) { throw new NotImplementedException(); }
public ConfigurationSaveResults UpdateConfigurationSection(int id, ConfigurationNew newConfiguration) { return AddUpdateConfigurationSection(id, newConfiguration); }
public ConfigurationSaveResults AddConfigurationSection(ConfigurationNew newConfiguration) { return AddUpdateConfigurationSection(null, newConfiguration); }
private ConfigurationSaveResults AddUpdateConfigurationSection(int? id, ConfigurationNew newConfiguration) { var results = new ConfigurationSaveResults() { }; if (string.IsNullOrWhiteSpace(newConfiguration.Name)) { results.AddError("The Name field cannot be empty", DataStorageError.MissingNameField); } else { ConfigurationValue record = new ConfigurationValue(); var existingRecordByNames = GetConfigurationSection(newConfiguration.Name, newConfiguration.SystemName); if (id.HasValue) { record = GetConfigurationSection(id.Value); if (record == null) { results.AddError("Record not found for the requested id", DataStorageError.RecordNotFound); return results; } else if (existingRecordByNames != null && record.Id == existingRecordByNames.Id) { //This means the existing record by this name matches, otherwise the logic below will return the existing name error existingRecordByNames = null; } } //Previously deleted, will be brought back, it history should be maintained in the history tables. if (existingRecordByNames != null && existingRecordByNames.Deleted) { record = existingRecordByNames; existingRecordByNames = null; } if (existingRecordByNames == null) { record.JSONSchema = newConfiguration.JSONSchema; record.Name = newConfiguration.Name; record.SystemName = newConfiguration.SystemName; record.XML = newConfiguration.XML; record.XMLSchema = newConfiguration.XMLSchema; record.Deleted = false; //Tags taken care of below var xmlSchema = GetSchema(record.XMLSchema); if (xmlSchema != null) { XmlDocument document = null; if (ValidateXml(record.XML, xmlSchema, out document)) { this.AssignJsonArrayAttributes(document, document.ChildNodes); string json = JsonConvert.SerializeXmlNode(document, Newtonsoft.Json.Formatting.Indented, false); if (ValidateJson(json, record.JSONSchema)) { record.JSON = json; if (id.HasValue) { Context.SetModified(record); } else { Context.ConfigurationValues.Add(record); Context.SetAdded(record); } var tagErrors = this.AddUpdateTagsConfigurationTags(record, newConfiguration.Tags); if (tagErrors == null) { var changes = Context.SaveChanges(); if (changes == 0) results.AddError("No records were removed ensure the id is correct.", DataStorageError.RecordsUnchanged); else results.Record = record; } else { results.Errors.Add(tagErrors); } } else { results.AddError("The Json does not match the schema", DataStorageError.DoesNotMatchJsonSchema); } } else { results.AddError("The Xml does not match the schema", DataStorageError.DoesNotMatchXMlSchema); } } else { results.AddError("The Xml Schema is invalid", DataStorageError.InvalidXmlSchema); } } else { results.AddError("Name and System Name already exist", DataStorageError.AlreadyExists); } } if(!results.Successful) { Context.ClearChanges(); } return results; }