/// <summary> /// 修改帮助 /// </summary> /// <param name="helpInfo">帮助实体</param> public int UpdateHelp(HelpInfo helpInfo) { using (DataContextDB DB = new DataContextDB()) { try { DB.GetTable<HelpInfo>().Attach(helpInfo, true); DB.SubmitChanges(); return 1; } catch (Exception e) { string error = e.Message; return -1; } } }
/// <summary> /// 添加帮助 /// </summary> /// <param name="helpInfo">帮助实体</param> public int InsertHelp(HelpInfo helpInfo) { using (DataContextDB DB = new DataContextDB()) { try { DB.GetTable<HelpInfo>().InsertOnSubmit(helpInfo); DB.SubmitChanges(); return 1; } catch (Exception e) { string error = e.Message; return -1; } } }
/// <summary> /// 获取帮助 /// </summary> /// <param name="helpInfo">帮助实体</param> /// <param name="pageInfo">分页实体</param> /// <returns></returns> public IList<HelpInfo> GetHelp(HelpInfo helpInfo, PageInfo pageInfo) { using (DataContextDB DB = new DataContextDB()) { IQueryable<HelpInfo> helpInfos = ( from item in DB.GetTable<HelpInfo>() orderby item.ID descending select item ); if (helpInfo != null && helpInfo.ID != 0) helpInfos = helpInfos.Where<HelpInfo>(m => m.ID == helpInfo.ID); if (pageInfo != null) { pageInfo.TotalRecord = helpInfos.Count(); return helpInfos.Skip(pageInfo.PageSize * (pageInfo.PageIndex - 1)).Take(pageInfo.PageSize).ToList<HelpInfo>(); } else return helpInfos.ToList<HelpInfo>(); } }
public ActionResult Help(HelpInfo helpInfo) { if (helpInfo == null) return Json(new FeedbackInfo { Success = -1, Message = "获取实体出错" }); if (string.IsNullOrWhiteSpace(helpInfo.Name)) return Json(new FeedbackInfo { Success = -1, Message = "请输入名称" }); if (string.IsNullOrWhiteSpace(helpInfo.Memo)) return Json(new FeedbackInfo { Success = -1, Message = "请输入内容" }); //新建 int result = 0; if (helpInfo.ID == 0) { helpInfo.Date = DateTime.Now; result = Start.DatabaseProvider.Instance().InsertHelp(helpInfo); if (result == 1) return Json(new FeedbackInfo { Success = 1, Message = "添加成功" }); else return Json(new FeedbackInfo { Success = -1, Message = "添加失败" }); } else //编辑 { result = Start.DatabaseProvider.Instance().UpdateHelp(helpInfo); if (result == 1) return Json(new FeedbackInfo { Success = 1, Message = "修改成功" }); else return Json(new FeedbackInfo { Success = -1, Message = "修改失败" }); } }
public ActionResult Help(int? id) { HelpInfo helpInfo = null; if (id != null && id.Value != 0) helpInfo = Start.DatabaseProvider.Instance().GetHelpByID(id.Value); if (helpInfo == null) helpInfo = new HelpInfo(); return View(helpInfo); }
public ActionResult HelpList(int id = 0, int pageIndex = 1) { PageInfo pageInfo = new PageInfo { PageIndex = pageIndex }; HelpInfo helpInfo = new HelpInfo { ID = id }; IList<HelpInfo> helpInfos = Start.DatabaseProvider.Instance().GetHelp(helpInfo, pageInfo); PagedList<HelpInfo> pagedList = new PagedList<HelpInfo>(helpInfos, pageInfo.PageIndex, pageInfo.PageSize, pageInfo.TotalRecord); ViewBag.HelpInfo = helpInfo; return View(pagedList); }