/// <summary> /// Constructs the object and returns as Json /// </summary> /// <param name="id"></param> /// <returns></returns> public virtual JsonResult getJson(int id) { EL model = (EL)db.dbSets[this.className].Find(id); if (model.status != -1 && (model.authorId == User.Identity.Name || model.isPublic == 1)) { string message = "Successfully retrieved " + this.className + ", subsections (" + model.subsections + ")"; // Parse subsection Id's and Retrieve any relevant children string[] subsections = model.subsections.Split(','); try { // Append all children (that extend from Container) for (int s = 0; s < subsections.Length; s++) { var child = db.dbSets["Container"].Find(Int32.Parse(subsections[s])); EL ch = (EL)child; if (ch.getAuthorId() == User.Identity.Name || ch.isPublic == 1) { model.addChild(child); } } } catch (Exception ex) { /*message += "\n No children exist or " + ex.Message; */ } this.attachFormPost(model, model.data, model.dataId); this.attachFormPost(model, model.attributes, model.attributesId); this.attachFormPost(model, model.meta, model.metaId); // Return the fully constructed model return(Json(new Payload( 1, this.className, model, message ), JsonRequestBehavior.AllowGet)); } else { string message = User.Identity.Name + ", You do not have permission to access this " + this.className; return(Json(new Payload(0, new Exception(message), message), JsonRequestBehavior.AllowGet)); } }