public SearchParcel ParcelPackage(SearchQueryPackage package) { SearchParcel result = new SearchParcel(); result.MinYear = int.MinValue; result.MaxYear = int.MaxValue; result.MinPrice = decimal.MinValue; result.MaxPrice = decimal.MaxValue; if (package.Keyword == null) { package.Keyword = ""; } if (package.MinYear == null) { package.MinYear = ""; } if (package.MaxYear == null) { package.MaxYear = ""; } if (package.MinPrice == null) { package.MinPrice = ""; } if (package.MaxPrice == null) { package.MaxPrice = ""; } if (package.Keyword.Length > 0) { result.HasKeyword(); } if (package.MinYear.Length > 0 || package.MaxYear.Length > 0) { result.HasYearQuery(); } if (package.MinPrice.Length > 0 || package.MaxPrice.Length > 0) { result.HasPriceQuery(); } int bottomYear = 0; int topYear = int.MaxValue; decimal bottomPrice = 0; decimal topPrice = decimal.MaxValue; if (package.MinYear.Length > 0) { int.TryParse(package.MinYear, out bottomYear); } if (package.MaxYear.Length > 0) { int.TryParse(package.MaxYear, out topYear); } if (package.MinPrice.Length > 0) { decimal.TryParse(package.MinPrice, out bottomPrice); } if (package.MaxPrice.Length > 0) { decimal.TryParse(package.MaxPrice, out topPrice); } result.Keyword = package.Keyword; result.MinYear = bottomYear; result.MaxYear = topYear; result.MinPrice = bottomPrice; result.MaxPrice = topPrice; result.InventoryType = package.InventoryType; return(result); }
public Courier <List <Vehicle> > GetSearchResult(SearchParcel parcel) { IEnumerable <Vehicle> list = repo.GetInventory(parcel.InventoryType); if (!string.IsNullOrWhiteSpace(parcel.Keyword)) { list = list.Where(v => v.Model.NameplateMarque.ToUpper().Contains(parcel.Keyword.ToUpper()) || v.Model.Manufacturer.ManufacturerName.ToUpper().Contains(parcel.Keyword.ToUpper()) || v.ProductionYear.ToString().Contains(parcel.Keyword)); } list = list.Where(v => v.ProductionYear <= parcel.MaxYear && v.ProductionYear >= parcel.MinYear); list = list.Where(v => (v.SalePrice <= parcel.MaxPrice && v.SalePrice >= parcel.MinPrice) || (v.MSRP <= parcel.MaxPrice && v.MSRP >= parcel.MinPrice)); Courier <List <Vehicle> > courier = new Courier <List <Vehicle> >(); courier.Package = list.ToList(); if (courier.Package.Count == 0) { courier.Success = false; courier.Message = "No results found given filter settings."; } else { courier.Success = true; } return(courier); //switch (parcel.GetParcelDirection()) //{ // case 1: // return ByPrice(parcel.MinPrice, parcel.MaxPrice, parcel.InventoryType); // case 10: // return ByYear(parcel.MinYear, parcel.MaxYear, parcel.InventoryType); // case 11: // return ByYearAndPrice(parcel); // case 100: // return ByKeyword(parcel.Keyword, parcel.InventoryType); // case 101: // return ByKeywordAndPrice(parcel); // case 110: // return ByKeywordAndYear(parcel); // case 111: // return FullSearch(parcel); // default: // return new Courier<SearchResultPackage>() { Success = true, Package = new SearchResultPackage() { Vehicles = repo.GetInventory(parcel.InventoryType).OrderByDescending(v => v.MSRP).Take(20).ToList() } }; //} //if (parcel.PackagedKeyword && parcel.PackagedYearRange && parcel.PackagedPriceRange) //{ // return FullSearch(parcel); //} //else if (parcel.PackagedKeyword && parcel.PackagedYearRange || parcel.PackagedKeyword && parcel.PackagedPriceRange) //{ // if (parcel.PackagedYearRange) // { // return ByKeywordAndYear(parcel); // } // else // { // return ByKeywordAndPrice(parcel); // } //} //else if (parcel.PackagedYearRange && parcel.PackagedPriceRange) //{ // return ByYearAndPrice(parcel); //} //else //{ // if (parcel.PackagedKeyword) // { // return ByKeyword(parcel.Keyword, parcel.InventoryType); // } // else if (parcel.PackagedYearRange) // { // return ByYear(parcel.MinYear, parcel.MaxYear, parcel.InventoryType); // } // else if (parcel.PackagedPriceRange) // { // return ByPrice(parcel.MinPrice, parcel.MaxPrice, parcel.InventoryType); // } // else // { // return new Courier<SearchResultPackage>() { Success = true, Package = new SearchResultPackage() { Vehicles = repo.GetInventory(parcel.InventoryType).OrderByDescending(v => v.MSRP).Take(20).ToList() } }; // } //} }