public Model2Html(int id) { this.BOid = id; db = new BODdb(); bo = db.BOD_BOs.Find(id); root = db.BOD_Items.Where(r => r.BOD_BO_Id == id && r.ParentItem == null).First(); }
private BOD_Item getRoot(BOD_Item item) { if(item.ParentItem == null) { return item; } if(item.ParentItem.Type == POD_DataTypes._array) { return item; } return getRoot(item.ParentItem); }
public ActionResult newBO() { cleanBOs(); BOD_BO bo = new BOD_BO() { Name = "NEWBO" }; _BODdb.BOD_BOs.Add(bo); _BODdb.SaveChanges(); BOD_Item root = new BOD_Item() { BO = bo, Name = "schema1", Type = POD_DataTypes._object, Id = 0 }; _BODdb.BOD_Items.Add(root); _BODdb.SaveChanges(); return RedirectToAction("ViewBO", new { id = bo.Id }); }
private string getPath(BOD_Item item, BOD_Item root) { string path = ""; /*if (item.ParentItem == null) return "Model." + item.Name; else */ if (item.ParentItem == root) { if(item.ParentItem.ParentItem == null) return item.Name; else return root.Name + "." + item.Name; } else { return getPath(item.ParentItem, root) + "." + item.Name; } }
private string createHtmlEditor(BOD_Item i, string path) { string ed = ""; if (i.Type == POD_DataTypes._object) { ed = createObject(i, i); } else if (i.Type == POD_DataTypes._array) { string p = i.ChildItems.First().Name; ed = string.Format(cshtmlforeach, p, path, string.Format(htmlTableItem, p, createHtmlEditor(i.ChildItems.First(), p))); } else { ed = string.Format(cshtmleditorfor, path); } return ed; }
private string createDataObjectItems(BOD_Item item) { string data = ""; foreach (var i in item.ChildItems) { if (i.Type == POD_DataTypes._array) { data = data + createDataArray(i); } else if (i.Type == POD_DataTypes._object) { data = data + createDataObject(i); } else { data = data + string.Format(_data, i.Name, getDefaultValue(i)); } } return data; }
private string createPropertySimple(BOD_Item item) { string prop; prop = string.Format(_propertysimple, item.Name, bod_Type_toString(item.Type)); return prop; }
private string createPropertyArray(BOD_Item item) { string prop; string items; var itemsdef = item.ChildItems.First(); if (itemsdef.Type == POD_DataTypes._object) { items = string.Format(_arrayItemObject, createPropertyList(itemsdef)); } else { items = string.Format(_arrayItemSimple, bod_Type_toString(itemsdef.Type)); } prop = string.Format(_array, item.Name, items); return prop; }
public ActionResult ItemDetail(BOD_Item_Model model) { int boid; if (model.Id < 0) { var parent = _BODdb.BOD_Items.Find(model.boid, model.ParentId); boid = parent.BOD_BO_Id; BOD_Item newitem = new BOD_Item() { BO = parent.BO, Type = getType(model.Type_String), ParentItem = parent, Name = model.Name, Id = IdHelper.getBODItemId(_BODdb, model.boid) }; if (newitem.Type == POD_DataTypes._array) { BOD_Item listDefinition = new BOD_Item() { BO = newitem.BO, Type = POD_DataTypes._string, ParentItem = newitem, Name = "item", Id = IdHelper.getBODItemId(_BODdb, model.boid) + 1 }; _BODdb.BOD_Items.Add(listDefinition); } _BODdb.BOD_Items.Add(newitem); _BODdb.SaveChanges(); } else { var item = _BODdb.BOD_Items.Find(model.boid, model.Id); var parent = _BODdb.BOD_Items.Find(model.boid, item.ParentItem_Id); BOD_Item_Model origm = new BOD_Item_Model() { IsArray = parent.Type == POD_DataTypes._array , boid = item.BOD_BO_Id, Id = item.Id, Name = item.Name, Type = item.Type }; boid = item.BOD_BO_Id; item.Name = model.Name; if (!origm.Type_String.Equals(model.Type_String)) { item.Type = getType(model.Type_String); if (item.Type == POD_DataTypes._array) { _BODdb.BOD_Items.RemoveRange(item.ChildItems); BOD_Item listDefinition = new BOD_Item() { BO = item.BO, Type = POD_DataTypes._string, ParentItem = item, Name = "item", Id = IdHelper.getBODItemId(_BODdb, model.boid) }; _BODdb.BOD_Items.Add(listDefinition); } else if (item.Type != POD_DataTypes._object) { if (item.ChildItems.Count() > 0) { _BODdb.BOD_Items.RemoveRange(item.ChildItems); } } } _BODdb.SaveChanges(); } _BODdb.BOD_BOs.Find(model.boid).LastChange = DateTime.Now; _BODdb.SaveChanges(); return RedirectToAction("ViewBO", new { id = boid }); }
private string createPropertyList(BOD_Item item) { string list = ""; foreach (var i in item.ChildItems) { if (i.Type == POD_DataTypes._object) { list = list + createPropertyObject(i); } else if (i.Type == POD_DataTypes._array) { list = list + createPropertyArray(i); } else { list = list + createPropertySimple(i); } } return list; }
private string createDataObject(BOD_Item item) { string data = string.Format(_dataObject, item.Name, createDataObjectItems(item)); return data; }
private string createDataArray(BOD_Item i) { string data = ""; if (i.ChildItems.First().Type == POD_DataTypes._object) { data = string.Format(_dataArray, i.Name, "{" + createDataObjectItems(i.ChildItems.First()) + "}"); } else if( i.ChildItems.First().Type == POD_DataTypes._array) { data = data + createDataArray(i.ChildItems.First()); } else { data = string.Format(_dataArray, i.Name, getDefaultValue(i)); } return data; }
private string getDefaultValue(BOD_Item i) { if (i.Type == POD_DataTypes._boolean) { return "true"; } else if (i.Type == POD_DataTypes._integer) { return "0"; } else if (i.Type == POD_DataTypes._number) { return "0.0"; } else { return @"""abc"""; } }
/* public string ViewJsonSchema() { string m = ""; Model2JSON mj = new Model2JSON(2); m = mj.getSchema(); return m; } public string ViewJsonDefault() { string m = ""; Model2JSON mj = new Model2JSON(2); m = mj.getDefaultData(); return m; } public string ViewCSHtml() { string h = ""; Model2Html hj = new Model2Html(2); h = hj.getcsHTML(); return h; } */ private BOD_Item_Model createModel(BOD_Item item) { BOD_Item_Model m = new BOD_Item_Model() {IsArray = false, boid = item.BOD_BO_Id, Id = item.Id, Name = item.Name, Type = item.Type, ChildItems = new List<BOD_Item_Model>(), ParentId = item.ParentItem_Id }; if (item.ChildItems.Count > 0) { foreach (var child in item.ChildItems) { m.ChildItems.Add(createModel(child)); } } return m; }
private string createPropertyObject(BOD_Item item) { string prop; prop = string.Format(_object, item.Name, createPropertyList(item)); return prop; }
private string createObject(BOD_Item item, BOD_Item root) { string html = ""; string items = ""; foreach (var i in item.ChildItems) { string path = getPath(i, getRoot(i)); items = items + string.Format(htmlTableItem, path, createHtmlEditor(i, path)); } html = string.Format(htmlTable, items); return html; }
private void deleteItemRec(BOD_Item item) { if (item.ChildItems.Count() > 0) { List<BOD_Item> items = item.ChildItems.ToList(); foreach (var i in items) { deleteItemRec(i); } } _BODdb.BOD_Items.Remove(item); }