public ActionResult ViewBO(int id) { var root = _BODdb.BOD_Items.Where(r => r.ParentItem_Id == null && r.BOD_BO_Id == id).First(); BOD_Item_Model m = createModel(root); return(View(m)); }
/* * 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); }
public ActionResult ItemDetail(int boid, int id, int parentId) { BOD_Item_Model m; var parent = _BODdb.BOD_Items.Find(boid, parentId); if (id < 0) { m = new BOD_Item_Model() { IsArray = parent.Type == POD_DataTypes._array, boid = boid, Id = -1, Name = "", Type = POD_DataTypes._string, ChildItems = new List <BOD_Item_Model>(), ParentId = parentId }; } else { var item = _BODdb.BOD_Items.Where(r => r.Id == id && r.BOD_BO_Id == boid).First(); m = new BOD_Item_Model() { IsArray = parent.Type == POD_DataTypes._array, boid = boid, Id = item.Id, Name = item.Name, Type = item.Type, ChildItems = new List <BOD_Item_Model>(), ParentId = item.ParentItem_Id }; } return(PartialView(m)); }
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 })); }