public JsonResult searchData(FormCollection form) { SYS_TINNHANBusiness = Get <SYS_TINNHANBusiness>(); var searchModel = SessionManager.GetValue("nofifSearch") as SYS_TINNHAN_SEARCH; if (searchModel == null) { searchModel = new SYS_TINNHAN_SEARCH(); searchModel.pageSize = 20; } searchModel.TIEUDE = string.IsNullOrEmpty(form["TIEUDE"]) ? form["TIEUDE"] : form["TIEUDE"].Trim(); if (!string.IsNullOrEmpty(form["TUNGAY"])) { searchModel.TUNGAY = form["TUNGAY"].ToDateTime(); } if (!string.IsNullOrEmpty(form["DENNGAY"])) { searchModel.DENNGAY = form["DENNGAY"].ToDateTime(); } if (!string.IsNullOrEmpty(form["TRANGTHAI"])) { searchModel.TRANGTHAI = form["TRANGTHAI"].Equals("1"); } SessionManager.SetValue("thuoctinhSearch", searchModel); var data = SYS_TINNHANBusiness.GetDaTaByPage(searchModel, searchModel.pageSize, 1); return(Json(data)); }
public ActionResult Index() { AssignUserInfo(); SYS_TINNHANBusiness = Get <SYS_TINNHANBusiness>(); SYS_TINNHAN_SEARCH searchModel = new SYS_TINNHAN_SEARCH(); searchModel.USER_ID = currentUser.ID; searchModel.pageSize = MaxPerpage; var data = SYS_TINNHANBusiness.GetDaTaByPage(searchModel, MaxPerpage); SessionManager.SetValue("nofifSearch", searchModel); return(View(data)); }
public JsonResult getData(int indexPage, string sortQuery, int pageSize) { SYS_TINNHANBusiness = Get <SYS_TINNHANBusiness>(); var searchModel = SessionManager.GetValue("nofifSearch") as SYS_TINNHAN_SEARCH; if (!string.IsNullOrEmpty(sortQuery)) { if (searchModel == null) { searchModel = new SYS_TINNHAN_SEARCH(); } searchModel.sortQuery = sortQuery; if (pageSize > 0) { searchModel.pageSize = pageSize; } SessionManager.SetValue("thuoctinhSearch", searchModel); } var data = SYS_TINNHANBusiness.GetDaTaByPage(searchModel, pageSize, indexPage); return(Json(data)); }
public PageListResultBO <SYS_TINNHAN_BO> GetDaTaByPage(SYS_TINNHAN_SEARCH searchModel, int pageSize = 20, int pageIndex = 1) { var query = from mes in this.context.SYS_TINNHAN join nguoidung in this.context.DM_NGUOIDUNG on mes.NGUOITAO equals nguoidung.ID into group1 from g1 in group1.DefaultIfEmpty() join nguoinhan in this.context.DM_NGUOIDUNG on mes.TO_USER_ID equals nguoinhan.ID into group2 from g2 in group1.DefaultIfEmpty() where searchModel.USER_ID == mes.TO_USER_ID select new SYS_TINNHAN_BO { FROM_USERNAME = mes.FROM_USERNAME, FROM_USER_ID = mes.FROM_USER_ID, ID = mes.ID, IS_READ = mes.IS_READ, NGAYTAO = mes.NGAYTAO, NGUOITAO = mes.NGUOITAO, NOIDUNG = mes.NOIDUNG, TEN_NGUOIGUI = g1.HOTEN, TEN_NGUOINHAN = g2.HOTEN, TIEUDE = mes.TIEUDE, TO_USERNAME = mes.TO_USERNAME, TO_USER_ID = mes.TO_USER_ID, URL = mes.URL }; if (searchModel != null) { if (!string.IsNullOrEmpty(searchModel.sortQuery)) { query = query.OrderBy(searchModel.sortQuery); } else { query = query.OrderByDescending(x => x.NGAYTAO); } if (!string.IsNullOrEmpty(searchModel.TIEUDE)) { query = query.Where(x => x.TIEUDE.ToLower().Trim().Contains(searchModel.TIEUDE.ToLower())); } if (searchModel.TUNGAY.HasValue) { query = query.Where(x => x.NGAYTAO >= searchModel.TUNGAY); } if (searchModel.DENNGAY.HasValue) { query = query.Where(x => x.NGAYTAO <= searchModel.DENNGAY); } if (searchModel.TRANGTHAI.HasValue) { query = query.Where(x => searchModel.TRANGTHAI == x.IS_READ); } } else { query = query.OrderByDescending(x => x.NGAYTAO); } var resultmodel = new PageListResultBO <SYS_TINNHAN_BO>(); var dataPageList = query.ToPagedList(pageIndex, pageSize); resultmodel.Count = dataPageList.TotalItemCount; resultmodel.TotalPage = dataPageList.PageCount; resultmodel.ListItem = dataPageList.ToList(); return(resultmodel); }