Exemplo n.º 1
0
        public IQueryable <Customer> SearchCustomers(
            SearchCustomerOptions options)
        {
            if (options == null)
            {
                return(null);
            }

            var query = context
                        .Set <Customer>()
                        .AsQueryable();

            if (!string.IsNullOrWhiteSpace(options.Firstname))
            {
                query = query.Where(c => c.Firstname == options.Firstname);
            }

            if (!string.IsNullOrWhiteSpace(options.Lastname))
            {
                query = query.Where(c => c.Lastname == options.Lastname);
            }

            if (!string.IsNullOrWhiteSpace(options.VatNumber))
            {
                query = query.Where(c => c.VatNumber == options.VatNumber);
            }

            if (!string.IsNullOrWhiteSpace(options.Email))
            {
                query = query.Where(c => c.Email == options.Email);
            }

            if (options.CustomerId != null)
            {
                query = query.Where(c => c.CustomerId == options.CustomerId.Value);
            }

            if (options.CreateFrom != null)
            {
                query = query.Where(c => c.Created >= options.CreateFrom);
            }

            if (options.CreateTo != null)
            {
                query = query.Where(c => c.Created <= options.CreateTo);
            }

            query = query.Take(500);

            return(query);
        }
Exemplo n.º 2
0
        public static IQueryable <Product> SearchProducts(ProductOptions productOptions, TinyCrmDbContext dbContext)
        {
            if (productOptions.PriceFrom != null &&
                productOptions.PriceTo != null &&
                productOptions.PriceFrom > productOptions.PriceTo)
            {
                return(null);
            }

            var query = dbContext.Set <Product>().AsQueryable();

            if (productOptions.ProductId != null)
            {
                query = query.Where(p => p.ProductId == productOptions.ProductId);
            }

            if (productOptions.Categories != null && productOptions.Categories.Any())
            {
                query = query.Where(p => productOptions.Categories.Contains(p.Category));
            }

            if (productOptions.PriceFrom != null)
            {
                query = query.Where(p => p.Price >= productOptions.PriceFrom);
            }

            if (productOptions.PriceTo != null)
            {
                query = query.Where(p => p.Price <= productOptions.PriceTo);
            }

            query = query.Take(500);
            return(query);
        }
Exemplo n.º 3
0
        public IQueryable <Order> SearchOrders(
            SearchOrderOptions options)
        {
            if (options == null)
            {
                return(null);
            }

            var query = context
                        .Set <Order>()
                        .AsQueryable();

            if (options.OrderId != null)
            {
                query = query.Where(ord => ord.OrderId == options.OrderId);
            }

            if (options.CreatedFrom != null)
            {
                query = query.Where(ord => ord.Created >= options.CreatedFrom);
            }

            if (options.CreatedTo != null)
            {
                query = query.Where(ord => ord.Created <= options.CreatedTo);
            }

            if (!string.IsNullOrWhiteSpace(options.DeliveryAddress))
            {
                query = query.Where(ord => ord.DeliveryAddress == options.DeliveryAddress);
            }


            return(query);
        }
Exemplo n.º 4
0
        public IQueryable<Product> SearchProducts(
            SearchProductOptions options)
        {
            if (options == null)
            {
                return null;
            }

            var query = context
                .Set<Product>()
                .AsQueryable();

            if (!string.IsNullOrWhiteSpace(options.ProductId))
            {
                query = query.Where(prod => prod.ProductId == options.ProductId);
            }

            if (!string.IsNullOrWhiteSpace(options.Description))
            {
                query = query.Where(prod => prod.Description == options.Description);
            }

            if (!string.IsNullOrWhiteSpace(options.Name))
            {
                query = query.Where(prod => prod.Name == options.Name);
            }

            if (options.PriceFrom != null)
            {
                query = query.Where(prod => prod.Price >= options.PriceFrom);
            }

            if (options.PriceTo != null)
            {
                query = query.Where(prod => prod.Price <= options.PriceTo);
            }

            if (options.Category != null)
            {
                query = query.Where(prod => prod.Category == options.Category);
            }

            query = query.Take(500);

            return query;
        }
Exemplo n.º 5
0
        public static IQueryable <Customer> SearchCustomers(CustomerOptions customerOptions, TinyCrmDbContext dbContext)
        {
            if (customerOptions.CreatedFrom != null &&
                customerOptions.CreatedTo != null &&
                customerOptions.CreatedFrom > customerOptions.CreatedTo)
            {
                return(null);
            }

            var query = dbContext.Set <Customer>().AsQueryable();

            if (customerOptions.CustomerId != null)
            {
                query = query.Where(c => c.CustomerId == customerOptions.CustomerId);
            }

            if (customerOptions.VatNumber != null)
            {
                query = query.Where(c => c.VatNumber == customerOptions.VatNumber);
            }

            if (customerOptions.CreatedFrom != null)
            {
                query = query.Where(c => c.Created >= customerOptions.CreatedFrom);
            }

            if (customerOptions.CreatedTo != null)
            {
                query = query.Where(c => c.Created <= customerOptions.CreatedTo);
            }

            if (!String.IsNullOrWhiteSpace(customerOptions.FirstName))
            {
                query = query.Where(c => c.FirstName.Contains(customerOptions.FirstName));
            }

            if (!String.IsNullOrWhiteSpace(customerOptions.LastName))
            {
                query = query.Where(c => c.LastName.Contains(customerOptions.LastName));
            }

            query = query.Take(500);
            return(query);
        }