public static webModel.SearchResult ToWebModel(this coreModel.SearchResult result) { var retVal = new webModel.SearchResult(); retVal.InjectFrom(result); retVal.CustomerOrders = result.CustomerOrders.Select(x => x.ToWebModel()).ToList(); return(retVal); }
public SearchResult Search(SearchCriteria criteria) { SearchResult retVal = null; using (var repository = _orderRepositoryFactory()) { var query = repository.CustomerOrders; if (!string.IsNullOrEmpty(criteria.Keyword)) { query = query.Where(x => x.Number.Contains(criteria.Keyword) || x.CustomerName.Contains(criteria.Keyword)); } if (criteria.CustomerId != null) { query = query.Where(x => x.CustomerId == criteria.CustomerId); } if (criteria.StoreIds != null && criteria.StoreIds.Any()) { query = query.Where(x => criteria.StoreIds.Contains(x.StoreId)); } if (criteria.EmployeeId != null) { query = query.Where(x => x.EmployeeId == criteria.EmployeeId); } if (criteria.StartDate != null) { query = query.Where(x => x.CreatedDate >= criteria.StartDate); } if (criteria.EndDate != null) { query = query.Where(x => x.CreatedDate <= criteria.EndDate); } if ((criteria.ResponseGroup & ResponseGroup.WithDiscounts) == ResponseGroup.WithDiscounts) { query = query.Include(x => x.Discounts); } if ((criteria.ResponseGroup & ResponseGroup.WithAddresses) == ResponseGroup.WithAddresses) { query = query.Include(x => x.Addresses); } if ((criteria.ResponseGroup & ResponseGroup.WithItems) == ResponseGroup.WithItems) { query = query.Include(x => x.Items); if ((criteria.ResponseGroup & ResponseGroup.WithDiscounts) == ResponseGroup.WithDiscounts) { query = query.Include(x => x.Items.Select(y=>y.Discounts)); } } if ((criteria.ResponseGroup & ResponseGroup.WithInPayments) == ResponseGroup.WithInPayments) { query = query.Include(x => x.InPayments); } if ((criteria.ResponseGroup & ResponseGroup.WithShipments) == ResponseGroup.WithShipments) { query = query.Include(x => x.Shipments); if ((criteria.ResponseGroup & ResponseGroup.WithItems) == ResponseGroup.WithItems) { query = query.Include(x => x.Shipments.Select(y => y.Items)); } if ((criteria.ResponseGroup & ResponseGroup.WithDiscounts) == ResponseGroup.WithDiscounts) { query = query.Include(x => x.Shipments.Select(y => y.Discounts)); } if ((criteria.ResponseGroup & ResponseGroup.WithAddresses) == ResponseGroup.WithAddresses) { query = query.Include(x => x.Shipments.Select(y=>y.Addresses)); } } retVal = new SearchResult { TotalCount = query.Count(), CustomerOrders = query.OrderByDescending(x => x.CreatedDate) .Skip(criteria.Start) .Take(criteria.Count) .ToArray() .Select(x => x.ToCoreModel(_shippingMethodsService.GetAllShippingMethods(), _paymentMethodsService.GetAllPaymentMethods())) .ToList() }; } return retVal; }
public SearchResult Search(SearchCriteria criteria) { SearchResult retVal = null; using (var repository = _orderRepositoryFactory()) { var query = repository.CustomerOrders; if (criteria.CustomerId != null) { query = query.Where(x => x.CustomerId == criteria.CustomerId); } if (criteria.StoreId != null) { query = query.Where(x => x.StoreId == criteria.StoreId); } if (criteria.StartDate != null) { query = query.Where(x => x.CreatedDate >= criteria.StartDate); } if (criteria.EndDate != null) { query = query.Where(x => x.CreatedDate <= criteria.EndDate); } if ((criteria.ResponseGroup & ResponseGroup.WithDiscounts) == ResponseGroup.WithDiscounts) { query = query.Include(x => x.Discounts); } if ((criteria.ResponseGroup & ResponseGroup.WithAddresses) == ResponseGroup.WithAddresses) { query = query.Include(x => x.Addresses); } if ((criteria.ResponseGroup & ResponseGroup.WithItems) == ResponseGroup.WithItems) { query = query.Include(x => x.Items); if ((criteria.ResponseGroup & ResponseGroup.WithDiscounts) == ResponseGroup.WithDiscounts) { query = query.Include(x => x.Items.Select(y=>y.Discounts)); } } if ((criteria.ResponseGroup & ResponseGroup.WithInPayments) == ResponseGroup.WithInPayments) { query = query.Include(x => x.InPayments); } if ((criteria.ResponseGroup & ResponseGroup.WithShipments) == ResponseGroup.WithShipments) { query = query.Include(x => x.Shipments); if ((criteria.ResponseGroup & ResponseGroup.WithItems) == ResponseGroup.WithItems) { query = query.Include(x => x.Shipments.Select(y => y.Items)); } if ((criteria.ResponseGroup & ResponseGroup.WithDiscounts) == ResponseGroup.WithDiscounts) { query = query.Include(x => x.Shipments.Select(y => y.Discounts)); } if ((criteria.ResponseGroup & ResponseGroup.WithAddresses) == ResponseGroup.WithAddresses) { query = query.Include(x => x.Shipments.Select(y=>y.Addresses)); } } retVal = new SearchResult { TotalCount = query.Count(), CustomerOrders = query.OrderByDescending(x => x.CreatedDate) .Skip(criteria.Start) .Take(criteria.Count) .ToArray() .Select(x => x.ToCoreModel()) .ToList() }; } return retVal; }