public ActionResult AddColumn(DataSetSchemaColumn column, string schemaName, string categoryName) { try { var schemaDetails = _dataSetSchemaService.Get(schemaName); if (!ModelState.IsValid) { ViewBag.SchemaName = schemaName; ViewBag.CategoryName = categoryName; ViewBag.AlreadySorted = IsAlreadySorted(schemaName); ViewBag.IsError = true; return(View("AddColumn", column)); } column.SchemaDefinition = schemaDetails.Definition; _dataSetSchemaColumnService.Create(column); return(Redirect(string.Format("/Admin/Schema/{0}/{1}/Edit?showfields=2", categoryName, schemaName))); } catch (Exception ex) { Elmah.ErrorLog.GetDefault(null).Log(new Elmah.Error(ex)); ViewBag.SchemaName = schemaName; ViewBag.CategoryName = categoryName; ViewBag.AlreadySorted = IsAlreadySorted(schemaName); ViewBag.Message = string.Format("<p class='warning'>Unable to create field definition. {0}</p>", ex.Message); return(View()); } }
public ImportDataSetSchemaResult ImportFromUrl(DataSetSchema schema) { var xml = _xmlToObjectService.GetXmlFromUrl(schema.SchemaDefinitionFromUrl); if (xml == "") { return(ReturnWithErrorMessage(schema, "Error loading schema from " + schema.SchemaDefinitionFromUrl)); } var deserializedSchema = _xmlToObjectService.ConvertXml <SchemaRestDefinition>(xml); if (deserializedSchema == null) { return(ReturnWithErrorMessage(schema, "No definition found at " + schema.SchemaDefinitionFromUrl)); } if (!String.IsNullOrEmpty(deserializedSchema.ErrorMessage)) { return(ReturnWithErrorMessage(schema, deserializedSchema.ErrorMessage)); } if (deserializedSchema.RestSchema == null) { return(ReturnWithErrorMessage(schema, "No schema found at " + schema.SchemaDefinitionFromUrl)); } if (deserializedSchema.RestColumnDefinitions == null) { return(ReturnWithErrorMessage(schema, "No schema found at " + schema.SchemaDefinitionFromUrl)); } if (deserializedSchema.RestColumnDefinitions.ColumnDefinitions != null && deserializedSchema.RestColumnDefinitions .ColumnDefinitions.Any(x => x.Name.ToLowerInvariant().Contains("publisher uri") || x.Name.ToLowerInvariant().Contains("publisheruri") || x.Name.ToLowerInvariant().Contains("publisher label") || x.Name.ToLowerInvariant().Contains("publisherlabel"))) { return(ReturnWithErrorMessage(schema, "Error: Columns cannot contain reserved column names - PublisherUri/PublisherLabel/Publisher Uri/Publisher Label. " + schema.SchemaDefinitionFromUrl)); } schema = CreateTable(schema, deserializedSchema); //create each columns foreach (var col in deserializedSchema.RestColumnDefinitions.ColumnDefinitions) { var newCol = InitializeColumn(col); schema.Definition.Columns = schema.Definition.Columns ?? new List <DataSetSchemaColumn>(); newCol.SchemaDefinition = schema.Definition; _dataSetSchemaColumnService.Create(newCol); } //populate esd links schema.CurrentMappedEsdFunctionService = deserializedSchema.EsdLinks.Links.Select(x => x.Type + x.Id.ToString()).ToList(); //save esd links in the front mvc as this need the esd functions list. return(new ImportDataSetSchemaResult() { DataSetSchema = schema, ErrorMessage = "" }); }