public ImportResult AddSchema(Schema schemaModel) { try { var schema = Mapper.Map <Schema, DirigoEdgeCore.Data.Entities.Schema>(schemaModel); var existingSchema = _context.Schemas.FirstOrDefault(s => s.DisplayName == schemaModel.DisplayName); _context.Schemas.Add(schema); _context.SaveChanges(); if (existingSchema != null) { schema.DisplayName = schema.DisplayName + " " + schema.SchemaId; } return(new ImportResult { Id = schema.SchemaId, Name = schema.DisplayName, Message = "Success" }); } catch (Exception ex) { Log.Error("Error Importing Schema named " + schemaModel.DisplayName, ex); return(new ImportResult { Name = schemaModel.DisplayName, Message = "Error: " + ex.Message }); } }
public ImportResult AddSchema(Schema schemaModel) { try { var schema = Mapper.Map<Schema, DirigoEdgeCore.Data.Entities.Schema>(schemaModel); var existingSchema = _context.Schemas.FirstOrDefault(s => s.DisplayName == schemaModel.DisplayName); _context.Schemas.Add(schema); _context.SaveChanges(); if (existingSchema != null) { schema.DisplayName = schema.DisplayName + " " + schema.SchemaId; } return new ImportResult { Id = schema.SchemaId, Name = schema.DisplayName, Message = "Success" }; } catch (Exception ex) { Log.Error("Error Importing Schema named " + schemaModel.DisplayName, ex); return new ImportResult { Name = schemaModel.DisplayName, Message = "Error: " + ex.Message }; } }