public IQueryable <Product> SearchProducts(ProductOptions opt) // search function { string optCustomerMinPrice = Convert.ToString(opt.MinPrice); string optCustomerMaxPrice = Convert.ToString(opt.MaxPrice); string optProductId = Convert.ToString(opt.ProductId); if (!(optProductId == "0")) { var queryId = db_ .Set <Product>() .AsQueryable(); queryId = queryId.Where(p => p.ProductId == opt.ProductId); return(queryId); } else { var query = db_ .Set <Product>() .AsQueryable(); if (!String.IsNullOrWhiteSpace(optCustomerMinPrice) && !String.IsNullOrWhiteSpace(optCustomerMaxPrice)) { query = query.Where(p => p.Price >= opt.MinPrice && p.Price <= opt.MaxPrice); query.Take(500); return(query); } return(query); } }
// find for specific orders public List <Order> SearchOrders(SearchOrderOptions opt) { if (opt == null) { return(null); } var customers = db_.Set <Customer>() .Where(ord => opt.CustomerId == ord.CustomerId) .Include(c => c.Orders) .ToList(); if (customers.Count() > 0) { var orders = new List <Order>(); foreach (var c in customers) { foreach (var el in c.Orders) { orders.Add(el); } } return(orders); } else { return(null); } }
public IQueryable <Customer> SearchCustomers(CustomerOptions opt) // search function { //string optCustomerId = Convert.ToString(opt.CustomerId); //string optCustomerDateFrom = Convert.ToString(opt.CreatedFrom); //string optCustomerDateTo = Convert.ToString(opt.CreatedTo); if (opt.CustomerId != null) // ean exei dosei id o xrhsths sto UI tha epistrepsei to monadiko record { var queryId = db_ .Set <Customer>() .AsQueryable(); queryId = queryId.Where(c => c.CustomerId == opt.CustomerId); //Console.WriteLine($"id pelati einai {opt.CustomerId}"); return(queryId); } else { var query = db_ .Set <Customer>() .AsQueryable(); if (!String.IsNullOrWhiteSpace(opt.LastName)) { query = query.Where(c => c.LastName == opt.LastName); } if (!String.IsNullOrWhiteSpace(opt.FirstName)) { query = query.Where(c => c.FirstName == opt.FirstName); } if (!String.IsNullOrWhiteSpace(opt.VatNumber)) { query = query.Where(c => c.VatNumber == opt.VatNumber); } // if (!String.IsNullOrWhiteSpace(opt.CreatedFrom) && !String.IsNullOrWhiteSpace(optCustomerDateTo)) //{ // query = query.Where(c => c.Created >= opt.CreatedFrom && c.Created <= opt.CreatedTo); // } query.Take(500); return(query); } }