public ActionResult Index(string sortOrder, string CurrentSort, int?page) { int pageSize = 5; int pageIndex = 1; pageIndex = page.HasValue ? Convert.ToInt32(page) : 1; ViewBag.CurrentSort = sortOrder; //sortOrder = String.IsNullOrEmpty(sortOrder) ? "USER_NO" : sortOrder; IPagedList <TRN_USER_PROMO_ITEM> pagedSpecimens = null; IQueryable <TRN_USER_PROMO_ITEM> specimens = db.TRN_USER_PROMO_ITEM.AsQueryable(); ViewBag.ZonalUsers = db.SEC_USERS.Where(u => u.USER_TYPE_NO == 5); ViewBag.specs = db.SET_PROMO_ITEM.Where(s => s.IS_ACTIVE == 1); ViewBag.currentDate = DateTime.Now.ToString("yyyy-MM-dd"); ViewBag.futureDate = DateTime.Now.AddDays(60).ToString("yyyy-MM-dd"); PromotionalItemSearch specsearch = (Session["promotion_search"] == null) ? new PromotionalItemSearch() : (PromotionalItemSearch)Session["promotion_search"]; if (Request.QueryString.HasKeys() && !page.HasValue) { Tuple <PromotionalItemSearch, IQueryable <TRN_USER_PROMO_ITEM> > tmp = setSearch(specimens, specsearch, false); specimens = tmp.Item2; specsearch = tmp.Item1; } else if (page.HasValue && Session["promotion_search"] != null) { specsearch = (PromotionalItemSearch)Session["promotion_search"]; Tuple <PromotionalItemSearch, IQueryable <TRN_USER_PROMO_ITEM> > tmp = setSearch(specimens, specsearch, true); specimens = tmp.Item2; specsearch = tmp.Item1; } else if (page.HasValue && Session["promotion_search"] == null) { specsearch = new PromotionalItemSearch(); specsearch.isactive = "all"; } else { specsearch.isactive = "all"; } Session["promotion_search"] = specsearch; pagedSpecimens = specimens.OrderByDescending(m => m.INSERT_TIME).ToPagedList(pageIndex, pageSize); ViewBag.specSearch = specsearch; ViewBag.USER_NO = new SelectList(db.SEC_USERS.Where(a => a.USER_TYPE_NO == (decimal)EUserTypes.ZonalManager) .ToList(), "USER_NO", "USER_FULL_NAME"); return(View(pagedSpecimens)); }
// // GET: /PromotionalItemDistribution/ public Tuple <PromotionalItemSearch, IQueryable <TRN_USER_PROMO_ITEM> > setSearch(IQueryable <TRN_USER_PROMO_ITEM> specimens, PromotionalItemSearch specsearch, bool search) { specsearch = (specsearch.dirty) ? specsearch : new PromotionalItemSearch(); if (!string.IsNullOrEmpty(Request.QueryString["USER_NO"]) || search) { specsearch.userNo = (!search) ? decimal.Parse(Request.QueryString["USER_NO"].ToString()) : specsearch.userNo; if (!string.IsNullOrEmpty(specsearch.userNo.ToString())) { specimens = specimens.Where(s => s.SEC_USERS.USER_NO == specsearch.userNo); } } else { specsearch.userNo = null; } if (!string.IsNullOrEmpty(Request.QueryString["user_name"])) { specsearch.user_name = Request.QueryString["user_name"]; specimens = specimens.Where(s => s.SEC_USERS.USER_NAME.Contains(specsearch.user_name)); } else { specsearch.user_name = ""; } if (!string.IsNullOrEmpty(Request.QueryString["userno"])) { specsearch.userno = decimal.Parse(Request.QueryString["userno"]); if (specsearch.userno != 0) { specimens = specimens.Where(s => s.USER_NO == specsearch.userno); } } else { specsearch.userno = 0; } if (!string.IsNullOrEmpty(Request.QueryString["AssignDateFrom"])) { specsearch.AssignDateFrom = DateTime.Parse(Request.QueryString["AssignDateFrom"]); specimens = specimens.Where(s => s.ASSIGN_DATE >= specsearch.AssignDateFrom); } else { specsearch.AssignDateFrom = null; } if (!string.IsNullOrEmpty(Request.QueryString["AssignDateTo"])) { specsearch.AssignDateTo = DateTime.Parse(Request.QueryString["AssignDateTo"]); specimens = specimens.Where(s => s.ASSIGN_DATE == specsearch.AssignDateTo); } else { specsearch.AssignDateTo = null; } specsearch.isactive = (!string.IsNullOrEmpty(Request.QueryString["Search_Active"])) ? Request.QueryString["Search_Active"] : specsearch.isactive; if (specsearch.isactive != "all") { specimens = specimens.Where(s => s.IS_ACTIVE == ((specsearch.isactive == "active") ? 1 : 0)); } if (!string.IsNullOrEmpty(Request.QueryString["promotional_item_no"])) { specsearch.promotional_item_no = decimal.Parse(Request.QueryString["promotional_item_no"]); if (specsearch.promotional_item_no != 0) { specimens = specimens.Where(s => db.TRN_USER_PROMO_DET .Where(det => det.PROMO_ITEM_NO == specsearch.promotional_item_no) .Select(det => det.USER_PROMO_NO) .Contains(s.USER_PROMO_NO) ); } } else { specsearch.promotional_item_no = 0; } specsearch.dirty = true; return(new Tuple <PromotionalItemSearch, IQueryable <TRN_USER_PROMO_ITEM> >(specsearch, specimens)); }