public IActionResult Post([FromBody] dynamic value) { string postedData = value.ToString(); Table sysData = JsonConvert.DeserializeObject <Table>(postedData); sysData.ID = Guid.NewGuid().ToString(); js.Add(sysData); js.SaveChanges(); return(StatusCode(201, sysData)); }
public IActionResult Post([FromBody] List <Change> value) { List <Change> changes = value; changes.ForEach(c => c.ID = Guid.NewGuid().ToString()); changes.ForEach(c => c.ObjectReference = js.Single <Element>(c.ElementID)); foreach (Change c in changes) { js.Add(c); } js.SaveChanges(); return(StatusCode(201)); }
private void SaveTableToFile(string filename) { Table tbl = new Table(); string jsonData; using (StreamReader sr = new StreamReader("wwwroot\\" + filename)) { jsonData = sr.ReadToEnd(); } Newtonsoft.Json.Linq.JObject JsonObj = JsonConvert.DeserializeObject <Newtonsoft.Json.Linq.JObject>(jsonData); var proep = JsonObj.Properties(); foreach (Newtonsoft.Json.Linq.JProperty p in proep) { if (!(p.Name.Equals("acronym") | p.Name.Equals("content"))) { tbl.TableProperties.Add(p.Name, p.Value.ToString()); } else if (p.Name.Equals("acronym")) { tbl.ID = p.Value.ToString(); } else if (p.Name.Equals("content")) { Element e; Newtonsoft.Json.Linq.JArray v = (Newtonsoft.Json.Linq.JArray)p.Value; foreach (var attributex in v) { e = new Element(); foreach (Newtonsoft.Json.Linq.JProperty t in attributex) { if (t.Name.Equals("identifier")) { e.ID = t.Value.ToString(); } e.Values.Add(t.Name, t.Value.ToString()); } tbl.TableElements.Add(e.ID, e); } } } js.Add(tbl); js.SaveChanges(); }