public string Search(Models.VisitInfo obj) { List <Models.VisitInfo> visits = new List <Models.VisitInfo>(db.VisitInfo.Where(s => s.StudentName == obj.StudentName).OrderByDescending(x => x.DateTime).Take(10)); JavaScriptSerializer jss = new JavaScriptSerializer(); StringBuilder sb = new StringBuilder(); String json = jss.Serialize(visits).ToString(); return(json); }
public ActionResult AddVisit(Models.VisitInfo obj) { if (obj != null) { Models.VisitInfo visit = new Models.VisitInfo(); visit.StudentId = obj.StudentId; visit.DateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); visit.StudentName = obj.StudentName; visit.Remarks = obj.Remarks; visit.InOut = obj.InOut; db.VisitInfo.Add(visit); db.SaveChanges(); } var rst = Json(new { success = true, message = 1 }, JsonRequestBehavior.AllowGet); return(rst); }