public EditSchemaViewModel(int id) { using (var context = new DataContext()) { TheSchema = context.Schemas.FirstOrDefault(x => x.SchemaId == id); TheSchema.JSONData = TheSchema.JSONData ?? "{ }"; } }
public ActionResult NewSchema() { // Create a new Content Page to be passed to the edit content action using (DataContext context = new DataContext()) { var schema = new Schema() { DisplayName = "New Schema " }; context.Schemas.Add(schema); context.SaveChanges(); // Update the DisplayName with the new id we now have schema.DisplayName = schema.DisplayName + schema.SchemaId; context.SaveChanges(); return RedirectToAction("EditSchema", "Admin", new { id = schema.SchemaId }); } }