/* P R I V A T E */
        // Refactored for testing!!! Should be made private! But I am using this from a test case
        public AjaxOrdersViewModel BuildAjaxOrdersViewModel(int traderId, DateTime filterByOrderDate)
        {
            if (filterByOrderDate == null)
                throw new Exception("Boundary Date is mandatory!!");

            Expression<Func<Order, bool>> filter = o => (o.Buyer.Id == traderId || o.Seller.Id == traderId) && o.OrderDate.Month == filterByOrderDate.Month && o.OrderDate.Year == filterByOrderDate.Year;
            var model = new AjaxOrdersViewModel();
            model.Items = new List<OrderViewModel>();
            var orders = _ordersRepository.Search(filter, 0, 0, o => o.OrderDate, true).ToList();
            foreach (Order order in orders)
            {
                model.Items.Add(new OrderViewModel(traderId, order));
            }

            return model;
        }
        // Refactored for testing!!! Should be made private! But I am using this from a test case
        public AjaxOrdersViewModel BuildAjaxOrdersViewModel(int traderId, int filterByStatus, string filterByTraderIds,
															 DateTime filterByOrderDate, bool filterBySeller, int page,
															 int pageSize)
        {
            if (filterByOrderDate == null)
                throw new Exception("Boundary Date is mandatory!!");

            List<int> intTraderIds = RetrieveTraderIds(filterByTraderIds);
            Expression<Func<Order, bool>> filter = null;
            if (filterByStatus == Order.Submitted)
            {
                filter = o => ((filterBySeller ? o.Seller.Id == traderId : o.Buyer.Id == traderId) &&

                    //((intTraderIds.Count == 0) ? true : IsInTraderList(intTraderIds, o.Seller.Id)) &&
                               o.Status == Order.Submitted &&
                               o.OrderDate >= filterByOrderDate);
            }
            else if (filterByStatus == Order.Quoted)
            {
                filter = o => ((filterBySeller ? o.Seller.Id == traderId : o.Buyer.Id == traderId) &&

                    //((intTraderIds.Count == 0) ? true : IsInTraderList(intTraderIds, o.Buyer.Id)) &&
                               o.Status == Order.Quoted &&
                               o.OrderDate >= filterByOrderDate);
            }
            else if (filterByStatus == Order.Approved)
            {
                filter = o => ((filterBySeller ? o.Seller.Id == traderId : o.Buyer.Id == traderId) &&

                    //(((intTraderIds.Count == 0) ? true : IsInTraderList(intTraderIds, o.Buyer.Id)) ||
                    //((intTraderIds.Count == 0) ? true : IsInTraderList(intTraderIds, o.Seller.Id))) &&
                               o.Status == Order.Approved &&
                               o.OrderDate >= filterByOrderDate);
            }
            else if (filterByStatus == Order.Fulfilled)
            {
                filter = o => ((filterBySeller ? o.Seller.Id == traderId : o.Buyer.Id == traderId) &&

                    //(((intTraderIds.Count == 0) ? true : IsInTraderList(intTraderIds, o.Buyer.Id)) ||
                    //((intTraderIds.Count == 0) ? true : IsInTraderList(intTraderIds, o.Seller.Id))) &&
                               o.Status == Order.Fulfilled &&
                               o.OrderDate >= filterByOrderDate);
            }

            var model = new AjaxOrdersViewModel();
            model.FilterByOrderDate = filterByOrderDate;
            model.FilterByStatus = filterByStatus;
            model.FilterByTraderIds = filterByTraderIds;
            model.FilterBySeller = filterBySeller;
            model.Items = new List<OrderViewModel>();
            var orders = _ordersRepository.Search(filter, page, pageSize, o => o.OrderDate, true).ToList();
            foreach (Order order in orders)
            {
                model.Items.Add(new OrderViewModel(traderId, order));
            }

            // Paginated and always descending by order date
            model.Page = page;
            model.Count = _ordersRepository.Count(filter);
            model.MaxPage = Math.Max((int)Math.Ceiling((double)_ordersRepository.Count(filter) / pageSize), 1);
            model.PageSize = pageSize;
            return model;
        }