Beispiel #1
0
        public async Task <ActionResult> Order(OrderViewModel order)
        {
            var       orderlist   = new List <OrderViewModel>();
            int       pageindex   = 1;
            var       recordCount = 0;
            const int PAGE_SZ     = 15;

            if (order.OrderDate == null && order.UserName != null)
            {
                orderlist = await _orderProvider.GetOrderByUserName(order.UserName);

                recordCount = orderlist.Count();
                if (Request.QueryString["page"] != null)
                {
                    pageindex = Convert.ToInt32(Request.QueryString["page"]);
                }
            }
            else if (order.OrderDate != null && order.UserName == null)
            {
                orderlist = await _orderProvider.GetOrderByDate(Convert.ToDateTime(order.OrderDate));

                recordCount = orderlist.Count();
                if (Request.QueryString["page"] != null)
                {
                    pageindex = Convert.ToInt32(Request.QueryString["page"]);
                }
            }
            else if (order.OrderDate != null && order.UserName != null)
            {
                orderlist = await _orderProvider.GetOrderByDateandName(Convert.ToDateTime(order.OrderDate), order.UserName);

                recordCount = orderlist.Count();
                if (Request.QueryString["page"] != null)
                {
                    pageindex = Convert.ToInt32(Request.QueryString["page"]);
                }
            }
            else
            {
                return(Redirect("Order"));
            }
            ViewBag.OrderList = orderlist.OrderByDescending(art => art.OrderGuid)
                                .Skip((pageindex - 1) * PAGE_SZ)
                                .Take(PAGE_SZ).ToList();
            ViewBag.Pager = new PagerHelper()
            {
                PageIndex   = pageindex,
                PageSize    = PAGE_SZ,
                RecordCount = recordCount,
            };
            return(View());
        }