public string Insert() { try { var infoList = JsonConvert.DeserializeObject <Dictionary <String, Object> >(HttpUtility.UrlDecode(Request.Form.ToString())); var title = infoList["title"].ToString(); var content = infoList["content"].ToString(); var contentCount = 0; int.TryParse(infoList["contentCount"].ToString(), out contentCount); Models.NoticeInfo noticeInfo = new Models.NoticeInfo(); noticeInfo.NoticeTitle = title; noticeInfo.Content = content; noticeInfo.ContentCount = contentCount; noticeInfo.InsertPersonID = (Session["user"] as Models.UserInfo).UserID; noticeInfo.InsertDate = DateTime.Now; db.NoticeInfo.Add(noticeInfo); if (db.SaveChanges() == 1) { return("ok"); } else { return("error"); } } catch (Exception e) { return(e.Message); } }
public ActionResult AddNotice(Models.NoticeInfo obj) { //var sr = new System.IO.StreamReader(Request.InputStream); //var jss = new JavaScriptSerializer(); //var obj = jss.Deserialize<Models.NoticeInfo>(sr.ReadToEnd());///前台传来的数据 var rst = Json(new { success = true, message = 1 }, JsonRequestBehavior.AllowGet); try { Models.NoticeInfo noticeInfo = new Models.NoticeInfo(); noticeInfo.Notice = obj.Notice; noticeInfo.Title = obj.Title; noticeInfo.Name = obj.Name; noticeInfo.DateTime = DateTime.Now.ToString(); db.NoticeInfo.Add(noticeInfo); db.SaveChanges(); } catch (Exception) { rst = Json(new { success = true, message = 0 }, JsonRequestBehavior.AllowGet); } return(rst); }
public string SearchTool(Models.NoticeInfo obj) { //var sr = new System.IO.StreamReader(Request.InputStream); var jss = new JavaScriptSerializer(); //var obj = jss.Deserialize<Models.NoticeInfo>(sr.ReadToEnd());///前台传来的数据 //var studentInfo = db.StudentInfo.Where(p => p.StudentId == obj.StudentId).FirstOrDefault(); //List<Models.NoticeInfo> noticeInfos = new List<Models.NoticeInfo>(db.NoticeInfo.Where(p => p.Title == obj.Title)); var noticeInfos = (from a in db.NoticeInfo where (a.Title.IndexOf(obj.Title) >= 0) select a).ToList(); StringBuilder sb = new StringBuilder(); String json = jss.Serialize(noticeInfos).ToString(); return(json); }