Example #1
0
        private IEnumerable <OrderSearchItem> GetItemsFromDatabase(OrderSearchArgs args)
        {
            var query = DataSession.Query <Ordering.PurchaseOrderSearch>();

            var statusIds = args.GetStatusIds();

            if (statusIds.Length > 0)
            {
                query = query.Where(x => statusIds.Contains(x.StatusID));
            }

            return(PurchaseOrderSearchUtility.CreateOrderItems(query, args.DisplayOption));
        }
Example #2
0
        private SearchResult <OrderSearchItem> GetOrderResultFromDatabase(OrderSearchArgs args)
        {
            var builder = DataSession.QueryBuilder <Ordering.PurchaseOrderSearch>();

            var statusIds = args.GetStatusIds();

            if (statusIds.Length > 0)
            {
                builder.Where(builder.Restriction(x => x.StatusID).In(statusIds));
            }

            int recordsTotal = builder.Count();

            PurchaseOrderSearchUtility.SetSearch(builder, args);

            if (args.StartDate.HasValue)
            {
                builder.Where(x => x.CreatedDate >= args.StartDate.Value);
            }

            if (args.EndDate.HasValue)
            {
                builder.Where(x => x.CreatedDate < args.EndDate.Value);
            }

            //IncludeMyself comes from a checkbox
            //ClientID comes from the logged in user
            int clientId = (args.IncludeSelf) ? args.ClientID : -999;

            //OtherClientID comes from a dropdownlist where "View All" = -1
            int otherClientId = (args.OtherClientID > 0) ? args.OtherClientID : -999;

            if (otherClientId > 0)
            {
                builder.Where(builder.Restriction(x => x.ClientID).In(new[] { clientId, otherClientId }));
            }

            if (!string.IsNullOrEmpty(args.VendorName))
            {
                builder.Where(builder.Restriction(x => x.CleanVendorName).Contains(PurchaseOrderSearchUtility.CleanString(args.VendorName)));
            }

            if (args.VendorID > 0)
            {
                builder.Where(x => x.VendorID == args.VendorID);
            }

            if (!string.IsNullOrEmpty(args.Keywords))
            {
                builder.Where(builder.Restriction(x => x.Description).Contains(args.Keywords));
            }

            if (!string.IsNullOrEmpty(args.PartNumber))
            {
                builder.Where(builder.Restriction(x => x.PartNum).Contains(args.PartNumber));
            }

            if (args.POID > 0)
            {
                builder.Where(x => x.POID == args.POID);
            }

            if (!string.IsNullOrEmpty(args.ShortCode))
            {
                builder.Where(builder.Restriction(x => x.ShortCode).Contains(args.ShortCode));
            }

            int recordsFiltered = builder.Count();

            PurchaseOrderSearchUtility.SetOrder(builder, args);

            IList <Ordering.PurchaseOrderSearch> data;

            if (args.Length > 0)
            {
                data = builder.Skip(args.Start).Take(args.Length).List();
            }
            else
            {
                data = builder.Skip(args.Start).List();
            }

            return(new SearchResult <OrderSearchItem>()
            {
                Draw = args.Draw,
                RecordsTotal = recordsTotal,
                RecordsFiltered = recordsFiltered,
                Data = PurchaseOrderSearchUtility.CreateOrderItems(data, args.DisplayOption).ToArray()
            });
        }