// Search in db deals that match the user preferences and create list of objects with necesary info to show on map the pub's with deals and deals's info public SearchResults SearchResults(SearchPreferences searchPreferences) { SearchResults searchresults = new SearchResults(); try { //Search algorithm var priceDecimal = SearchPreferences.PriceMaxToDecimal(searchPreferences.PriceMax); //Distance var maxDistance = SearchPreferences.DistanceMaxToDecimal(searchPreferences.MaxDistance); var DealsArea = db.Deals.Where(deal => deal.Pub.Area == searchPreferences.Area); var DealsAreaPrice = DealsArea.Where(deal => deal.Price <= priceDecimal); var DealsAreaPriceDistance = DealsAreaPrice.Where(deal => deal.Pub.DistanceTillAreaCenter <= maxDistance); var DealsAreaPriceTimeDistance = DealsAreaPrice.Where(deal => deal.EndDate >= DateTime.Now); foreach (var deal in DealsAreaPriceTimeDistance) { //Vouchers left? if ((deal.VouchersForSale - deal.VouchersSold >= 1)) { SearchResult searchResult = new SearchResult(); var image = GetImageIfExistBinaryFormat(deal.Id); if (image != null) { searchResult.DealImage = image; } searchResult.PubAddress = deal.Pub.Address; searchResult.PubName = deal.Pub.Name; searchResult.Description = deal.Description; searchResult.LatLng = deal.Pub.LatLng; // to pass to deatils view searchResult.DealId = deal.Id; //set content string for google maps api searchResult.SetContentString(); // Add deal data to list of results searchresults.AddResult(searchResult); } } } catch (Exception e) { Console.WriteLine("{0} Exception caught.", e); } return(searchresults); }
public SearchResults SearchResults(SearchPreferences searchPreferences) { //Search algorithm var priceDecimal = SearchPreferences.PriceMaxToDecimal(searchPreferences.PriceMax); var DealsArea = dealFakeTable.Where(deal => deal.Pub.Area == searchPreferences.Area); var DealsAreaPrice = DealsArea.Where(deal => deal.Price <= priceDecimal); var DealsAreaPriceTime = DealsAreaPrice.Where(deal => deal.EndDate >= DateTime.Now); SearchResults searchresults = new SearchResults(); foreach (var deal in DealsAreaPriceTime) { SearchResult searchResult = new SearchResult(); //looking for related EEVAs var RelatedEEVAs = dealEEVAFakeTable.Where(eeva => eeva.FK_Deal == deal.Id); //look for DealImage if esxist var imageEEVA = RelatedEEVAs.FirstOrDefault(eeva => eeva.Attribute == "DealImage"); if (imageEEVA != null) { string imageName = imageEEVA.Value; //tke name if exists the image var image = imageFakeTable.FirstOrDefault(img => img.Name == imageName); if (image != null) { searchResult.DealImage = image.BinaryImage; } } searchResult.PubAddress = deal.Pub.Address; searchResult.PubName = deal.Pub.Name; searchResult.Description = deal.Description; searchResult.LatLng = deal.Pub.LatLng; //set content string for google maps api searchResult.SetContentString(); // Add deal data to list of results searchresults.AddResult(searchResult); } return(searchresults); }