Esempio n. 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));
        }
Esempio n. 2
0
        private static IEnumerable <OrderSearchItem> Search(IEnumerable <OrderSearchItem> items, OrderSearchArgs args)
        {
            if (args.Search == null)
            {
                return(items);
            }

            if (string.IsNullOrEmpty(args.Search.Value))
            {
                return(items);
            }

            if (args.Columns == null)
            {
                return(items);
            }

            var result = items.Where(x => PurchaseOrderSearchUtility.GetSearchText(x, args).Contains(args.Search.Value.ToLower()));

            return(result);
        }
Esempio n. 3
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()
            });
        }
Esempio n. 4
0
        private SearchResult <OrderSearchItem> GetOrderResultFromSession(OrderSearchArgs args)
        {
            IEnumerable <OrderSearchItem> items;

            items = GetItemsFromSession();

            if (items == null)
            {
                items = GetItemsFromDatabase(args);
                SetSession(items);
            }

            int recordsTotal = items.Count();

            items = Search(items, args);

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

            if (args.EndDate.HasValue)
            {
                items = items.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)
            {
                items = items.Where(x => new[] { clientId, otherClientId }.Contains(x.ClientID));
            }

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

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

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

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

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

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

            int recordsFiltered = items.Count();

            items = Order(items, args);

            var take = args.Length > 0 ? args.Length : 10; // default is 10 rows

            OrderSearchItem[] data;

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

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