public ActionResult GetTanMu() { int id; if (!int.TryParse(Request["id"], out id)) { return(Content("{\"code\":1,\"danmaku\":\"\"")); } int max; if (!int.TryParse(Request["max"], out max)) { max = 100; } var list = db.zhancaiw_vyw_tanmu_video_user.Where(c => c.isShow == true && c.videoID == id).OrderByDescending(c => c.addTime).Skip(0).Take(max).ToList(); if (list.Count <= 0) { return(Content("{\"code\":1,\"danmaku\":\"\"")); } string[] str = { Request["id"] }; List <danmaku> newlist = new List <danmaku>(); foreach (var item in list) { danmaku model = new danmaku(); model.author = item.nickName == null ? item.email : item.nickName; model._id = item.ID.ToString(); model.text = item.text; model.time = (float)item.time; model.color = item.color; model.type = item.type; model.__v = 0; model.player = str; newlist.Add(model); } TanMu tanmu = new TanMu(); tanmu.code = 1; tanmu.danmaku = newlist; return(Content(JsonConvert.SerializeObject(tanmu))); }
public ActionResult GetTanMu(PostTanMu item) { if (item.text == null) { return(Content("{\"code\":1,\"data\":\"\"}")); } zhancaiw_tanmu model = new zhancaiw_tanmu(); model.color = item.color; model.text = item.text; model.time = Math.Round(Convert.ToDouble(item.time), 1); model.type = item.type; model.userID = 2; model.videoID = Convert.ToInt32(item.player); model.isShow = true; model.addTime = DateTime.Now; db.zhancaiw_tanmu.Add(model); db.Configuration.ValidateOnSaveEnabled = false; int count = db.SaveChanges(); db.Configuration.ValidateOnSaveEnabled = true; string[] str = { item.player }; danmaku newmodel = new danmaku(); newmodel.__v = 0; newmodel._id = item.player; newmodel.author = item.author; newmodel.color = item.color; newmodel.player = str; newmodel.text = item.text; newmodel.time = (float)Math.Round(Convert.ToDouble(item.time), 1); newmodel.type = item.type; return(Content("{\"code\":1,\"data\":" + JsonConvert.SerializeObject(newmodel) + "}")); }