//Here the IsMatch calls promotionCodeCorrection which reverses the last three charachter of the onlinepromotion code public bool IsMatch(OnlinePromotion onlinePromotion, Promotion promotion) { bool IsMatchFlag = false; try { //IsMatchFlag = promotion.PromotionCode == promotionCodeCorrection(onlinePromotion.PromotionCode) ? true : false ; if (promotion.PromotionCode == promotionCodeCorrection(onlinePromotion.PromotionCode)) { IsMatchFlag = true; } } catch (Exception ex) { Console.Write("An error occurred:" + ex.Message); } return IsMatchFlag; }
//Here IsMatch remove all the punctuation in both promotion, onlinepromotion name and address and compare them //Note that the punctuation except % and $ is replaced by null to make it easy for comparing and this must be done in both promotion and online promotion to enhance the accuracy public bool IsMatch(OnlinePromotion onlinePromotion, Promotion promotion) { bool IsMatchFlag = false; try { //Apply the filtering Regex regex = new Regex(REGEXP, RegexOptions.IgnoreCase); //Remove all punctuation except $ and % from onlinepromotion name and adderss string onlinePromotionNamePunctuationless = regex.Replace(onlinePromotion.Name, string.Empty); string promotionNamePunctuationless = regex.Replace(promotion.Name, string.Empty); //Remove all punctuation except $ and % from promotion name and adderss string onlinePromotionAddressPunctuationless = regex.Replace(onlinePromotion.Address.Street+","+onlinePromotion.Address.Suburb+","+onlinePromotion.Address.Postcode, " "); string promotionAddressPunctuationless = regex.Replace(promotion.Address.Street+","+ promotion.Address.Suburb+","+promotion.Address.Postcode, " "); //Campare the name and address of onlinepromotion and promotion if (String.Compare(onlinePromotionNamePunctuationless, promotionNamePunctuationless, true) == 1 && String.Compare(onlinePromotionAddressPunctuationless, promotionAddressPunctuationless, true) == 1) { IsMatchFlag = true; } } catch(Exception ex) { Console.Write("An error occurred:" + ex.Message); } return IsMatchFlag; }
static void Main(string[] args) { //Data from promotion sites Address address = new Address(); address.Street = "22 Balmaringa"; address.Suburb = "Gordon!"; address.Postcode = "2072"; address.Latitude = +40.689060m; address.Longitude = -74.044636m; OnlinePromotion onlinepromotion = new OnlinePromotion(); onlinepromotion.Name = "Nike*-40% Off Storewide!"; onlinepromotion.Address = address; onlinepromotion.PromotionCode = "124REZ"; onlinepromotion.ProviderKey = "1"; //Getting data from database Address situation = new Address(); situation.Street = "22 Balmaringa!"; situation.Suburb = "Gordon!"; situation.Postcode = "2072"; situation.Latitude = +40.689060m; situation.Longitude = -74.044636m; Promotion promotion = new Promotion(); promotion.Address = situation; promotion.Name = "Nike 40% Off Storewide"; promotion.PromotionCode = "124ZER"; //Test case 1 IPromotionMatcher objOzSite; objOzSite = PromotionCollection.getPromotionObj("Oz Winner"); Console.Write(objOzSite.IsMatch(onlinepromotion, promotion)); //Test case 2 IPromotionMatcher objSpSite; objSpSite = PromotionCollection.getPromotionObj("Surface Promotion"); Console.Write(objSpSite.IsMatch(onlinepromotion, promotion)); //Test case 3 IPromotionMatcher objHopSite; objHopSite = PromotionCollection.getPromotionObj("Hopeless Online Promotion"); Console.Write(objHopSite.IsMatch(onlinepromotion, promotion)); //To view Console.ReadLine(); }
//Here IsMatch calls the distance method to calculate the distance and compare than with DISTANCE=500m public bool IsMatch(OnlinePromotion onlinePromotion, Promotion promotion) { bool IsMatchFlag = false; try { //Check the promotion code and the distance if (promotion.PromotionCode == onlinePromotion.PromotionCode && DISTANCE > distance(Convert.ToDouble(onlinePromotion.Address.Latitude), Convert.ToDouble(onlinePromotion.Address.Longitude), Convert.ToDouble(promotion.Address.Latitude), Convert.ToDouble(promotion.Address.Longitude))) { IsMatchFlag = true; } } catch (Exception ex) { Console.Write("An error occurred:" + ex.Message); } return IsMatchFlag; }