public PartialViewResult showOrderHistPartialView(int?customerId, DateTime?fromDate, DateTime?toDate, string sortOrder, int?currentPageIndex) { var ctx = new SmsContext(); if (fromDate == null) { fromDate = SystemConstant.MIN_DATE; } if (toDate == null) { toDate = SystemConstant.MAX_DATE; } var orderList = ctx.GET_HOA_DON(fromDate, toDate, customerId).ToList <GET_HOA_DON_Result>(); if (string.IsNullOrEmpty(sortOrder)) { sortOrder = "date_desc"; } else { sortOrder = "date"; } ViewBag.SortOrder = sortOrder; IPagedList <GET_HOA_DON_Result> khachHangHists = null; int pageSize = SystemConstant.ROWS; int pageIndex = currentPageIndex == null ? 1 : (int)currentPageIndex; ViewBag.Count = orderList.Count(); switch (sortOrder) { case "date": khachHangHists = orderList.OrderBy(KhachHangHist => KhachHangHist.NGAY_BAN).ToList().ToPagedList(pageIndex, pageSize); break; case "date_desc": khachHangHists = orderList.OrderByDescending(KhachHangHist => KhachHangHist.NGAY_BAN).ToList().ToPagedList(pageIndex, pageSize); break; default: khachHangHists = orderList.OrderBy(KhachHangHist => KhachHangHist.NGAY_BAN).ToList().ToPagedList(pageIndex, pageSize); break; } KhachHangModel KhachHang = new KhachHangModel(); KhachHang.OrderHist = khachHangHists; var total = ctx.GET_SUM_HOA_DON_BY_CUS_ID(fromDate, toDate, customerId).ToList().First(); KhachHang.Total = total; ViewBag.CustomerId = customerId; ViewBag.FromDate = ((DateTime)fromDate).ToString("dd/MM/yyyy"); ViewBag.ToDate = ((DateTime)toDate).ToString("dd/MM/yyyy"); ViewBag.currentPageIndex = currentPageIndex; ctx.Dispose(); return(PartialView("showOrderHistPartialView", KhachHang)); }