public JsonResult Create(Knowlege entity) { if (entity != null) { string Title = entity.Title; string Author = entity.Author; string UpdateTime = entity.UpdateTime.Value.ToShortDateString(); string KeyWords = entity.KeyWords; string Content = entity.Content; entity.AllContent = string.Format("{0}|{1}|{2}|{3}", Title, Author, KeyWords, Content); if (Content != null && Content.Length > 300) { Content = Content.Substring(0, 300); } entity.Summary = string.Format("{0}<br/>{1}<br/>{2} {3} {4}", Content, KeyWords, Title, Author, UpdateTime); } using (MBREntities db = new MBREntities()) { KnowlegeService us = new KnowlegeService(db); if (us.Create(ref errors, entity)) { LogHandler.WriteServiceLog(LogonUser.RealName, "KnowlegeID:" + entity.KnowlegeID + ",Title:" + entity.Title, Resource.InsertSucceed, Resource.Create, "专家库管理"); return(Json(JsonHandler.CreateMessage(1, Resource.InsertSucceed), JsonRequestBehavior.AllowGet)); } else { string ErrorCol = errors.Error; LogHandler.WriteServiceLog(LogonUser.RealName, "KnowlegeID:" + entity.KnowlegeID + ",Title:" + entity.Title, Resource.InsertFail, Resource.Create, "专家库管理"); return(Json(JsonHandler.CreateMessage(0, Resource.InsertFail + ErrorCol), JsonRequestBehavior.AllowGet)); } } }
public JsonResult GetList(GridPager pager) { Expression <Func <Knowlege, bool> > predicate = null; if (!string.IsNullOrEmpty(Request["search[value]"])) { string value = Request["search[value]"]; predicate = m => m.AllContent.Contains(value); } using (MBREntities db = new MBREntities()) { KnowlegeService us = new KnowlegeService(db); var query = us.GetList(ref pager, predicate); var json = new { draw = pager.draw, recordsTotal = pager.recordsFiltered, recordsFiltered = pager.recordsTotal, data = query.Select(m => new { m.KnowlegeID, m.Title, m.KeyWords, m.Content, m.Author, m.UpdateTime, m.AllContent, m.Summary }) }; return(Json(json, JsonRequestBehavior.AllowGet)); } }
public ActionResult Details(int id) { using (MBREntities db = new MBREntities()) { KnowlegeService us = new KnowlegeService(db); Knowlege entity = us.GetById(id); return(View(entity)); } }
public JsonResult Delete(int id) { using (MBREntities db = new MBREntities()) { KnowlegeService us = new KnowlegeService(db); if (us.Delete(ref errors, id)) { LogHandler.WriteServiceLog(LogonUser.RealName, "KnowlegeID:" + id, Resource.DeleteSucceed, Resource.Delete, "专家库管理"); return(Json(JsonHandler.CreateMessage(1, Resource.DeleteSucceed))); } else { string ErrorCol = errors.Error; LogHandler.WriteServiceLog(LogonUser.RealName, "KnowlegeID:" + id, Resource.DeleteFail, Resource.Delete, "专家库管理"); return(Json(JsonHandler.CreateMessage(0, Resource.DeleteFail + ErrorCol))); } } }