// PUT odata/Weibo(5) public IHttpActionResult Put([FromODataUri] int key, WeiboFromBigData weibofrombigdata) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (key != weibofrombigdata.Id) { return BadRequest(); } db.Entry(weibofrombigdata).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!WeiboFromBigDataExists(key)) { return NotFound(); } else { throw; } } return Updated(weibofrombigdata); }
// POST odata/Weibo public IHttpActionResult Post(WeiboFromBigData weibofrombigdata) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.WeiboFromBigDatas.Add(weibofrombigdata); db.SaveChanges(); return Created(weibofrombigdata); }
private void ReadJsonFromFile(List<string> files) { int num = 0;//计数 JavaScriptSerializer serializer = new JavaScriptSerializer(); foreach (string filename in files) { string fileUrl = Server.MapPath("data/" + filename); //读取文件 StreamReader sr = new StreamReader(fileUrl, System.Text.Encoding.UTF8); try { if (sr != null) { string stringLine = sr.ReadLine(); WeiboFromBigData weibo = new WeiboFromBigData(); if (stringLine != null) { string result = ""; while (stringLine != null) { result = stringLine.Substring(1, stringLine.Length - 2); weibo = JsonConvert.DeserializeObject<WeiboFromBigData>(result); db.WeiboFromBigDatas.Add(weibo); db.SaveChanges(); num += 1; Console.Write("num:" + num); stringLine = sr.ReadLine(); } } } } catch (Exception e) { Console.Write(e.ToString()); } finally { sr.Close(); } } }