private IEnumerable<AdminRetrieveOrdersViewModel> AssignOrderList(List<OrderViewModel> records)
        {
            if (records == null)
                return null;

            var itemList = new List<AdminRetrieveOrdersViewModel>();

            foreach (var item in records)
            {
                int commission = (from c in db.Commissions
                                  join mc in db.ModelCommissions on c.CommissionId equals mc.CommissionId
                                  join m in db.Models on mc.ModelId equals m.ModelId
                                  join o in db.Orders on m.ModelId equals o.ModelId
                                  where o.OrderId == item.OrderId
                                  select c.Percentage).FirstOrDefault();

                int unitPrice = (from o in db.Orders
                                 where o.OrderId == item.OrderId
                                 select o.UnitPrice).FirstOrDefault();

                var orderItem = new AdminRetrieveOrdersViewModel()
                {
                    OrderId = item.OrderId,
                    ModelId = item.ModelId,
                    CustomerId = item.CustomerId,
                    CustomerName = (from u in db.Users
                                    join o in db.Orders on u.Id equals o.CustomerUserId
                                    where o.OrderId == item.OrderId
                                    select u.Name).FirstOrDefault(),

                    ModelNumber = (from m in db.Models
                                   where m.ModelId == item.ModelId
                                   select m.ModelNumber).FirstOrDefault(),
                    SupplierName = (from c in db.Suppliers
                                    where c.SupplierId == item.SupplierId
                                    select c.Name).FirstOrDefault(),
                    Status = item.Status,
                    DtCreated = item.DtCreated
                };
                itemList.Add(orderItem);
            }
            if (itemList == null)
                return null;

            return itemList;
        }
        public ActionResult SearchOrders(Nullable<DateTime> fromDate, Nullable<DateTime> toDate, int? page)
        {
            try
            {
                if (fromDate == null)
                    fromDate = DateTime.Today;
                if (toDate == null)
                    toDate = DateTime.Today;

                var searchResult = from o in db.Orders
                                   where o.DtCreated >= fromDate
                                   && o.DtCreated <= toDate
                                   select o;

                var itemList = new List<AdminRetrieveOrdersViewModel>();
                foreach (var item in searchResult)
                {
                    int unitPrice = (from o in db.Orders
                                     where o.OrderId == item.OrderId
                                     select o.UnitPrice).FirstOrDefault();

                    var orderItem = new AdminRetrieveOrdersViewModel()
                    {
                        OrderId = item.OrderId,
                        ModelId = item.ModelId,
                        CustomerId = item.CustomerId,
                        CustomerName = (from u in db.Users
                                        join o in db.Orders on u.Id equals o.CustomerUserId
                                        where o.OrderId == item.OrderId
                                        select u.Name).FirstOrDefault(),

                        ModelNumber = (from m in db.Models
                                       where m.ModelId == item.ModelId
                                       select m.ModelNumber).FirstOrDefault(),
                        SupplierName = (from c in db.Suppliers
                                        where c.SupplierId == item.SupplierId
                                        select c.Name).FirstOrDefault(),
                        Status = item.Status,
                        DtCreated = item.DtCreated,
                        SupplierId = item.SupplierId,
                        Price = unitPrice
                    };
                    itemList.Add(orderItem);
                }
                if (itemList == null)
                {
                    ViewBag.Title = "No Order for in that range found.";
                    return View("RetrieveOrders");
                }
                Session["ExcelData"] = itemList;

                //Paging Section
                var pageNumber = page ?? 1; // if no pagenumber is specified in the querystring, it will assign pageNumber to 1 by default
                var pageOfProducts = itemList.ToPagedList(pageNumber, 10); //set the number of records per page
                ViewBag.pageOfProducts = pageOfProducts;

                ViewBag.Title = "List Of Orders";

                return View("RetrieveOrders");
            }
            catch (Exception ex)
            {
                return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString());
            }
        }