public ReturnState ChargeCreditCard(CustomerObject co, Promotion promo, int payTypeFk, decimal budget) { var sw = new ServiceClientWrapper(); var gr = sw.CreateProfile(co); if (gr != null && gr.isGood && !gr.isError) { var refNum = gr.CustomerRefNum; gr = sw.AuthorizeAndCapture(refNum, double.Parse(budget.ToString())); if (gr != null && gr.isApproved && !gr.isError && gr.ResponseCode == "00") { var tr = new TransactionRepository(_dbcontext); var amount = decimal.Parse(gr.amountRedeemedNoDecimal); var cp = _dbcontext.CreditCardProfiles.Add(new CreditCardProfile { CustomerRefNum = refNum, CustomerFK = promo.ProductGroup.CustomerFK }); var tran = _dbcontext.Transactions.Add(new Transaction { CreatedDate = DateTime.Now, Amount = amount, CreditCardProfileFK = cp.CreditCardProfilePK, AuthCode = gr.AuthCode, TxRefNum = gr.TxRefNum }); tran.SemplestTransactions.Add(new SemplestTransaction { CreatedDate = DateTime.Now, Amount = amount, TransactionTypeFK = tr.GetTransactionTypeCode("MediaSpend") }); promo.RemainingBudgetInCycle += amount; promo.StartBudgetInCycle += amount; promo.CreditCardProfileFK = cp.CreditCardProfilePK; _dbcontext.PromotionBudgets.Add(new PromotionBudget { TransactionsFK = tran.TransactionsPK, PromotionFK = promo.PromotionPK, BudgetCarryOverAmount = 0, BudgetToAddAmount = amount, BudgetToAddDate = DateTime.Now, CreatedDate = DateTime.Now, IsValid = true, IsAppliedToPromotion = true }); return new ReturnState(false, false, string.Empty, null); } return gr == null ? new ReturnState(true, false, "Server Exception", null) : new ReturnState(true, true, gr.Message, null); } return gr == null ? new ReturnState(true, false, "Server Exception", null) : new ReturnState(true, true, "Card Declined", null); }
public List<CampaignSetupModel.KeywordsModel> SaveNegativeKeywords(SmartWordSetupModel model, int customerFk, Promotion promo) { RefreshKeywords(model, promo); model.AllKeywords.Clear(); model.AllKeywords.AddRange( _dbcontext.PromotionKeywordAssociations.Where( key => !key.IsDeleted && !key.IsNegative && key.PromotionFK == promo.PromotionPK).Select( key => new CampaignSetupModel.KeywordsModel {Name = key.Keyword.Keyword1, Id = key.Keyword.KeywordPK})); return model.AllKeywords; }
private void RefreshKeywords(SmartWordSetupModel model, Promotion promo) { IEnumerable<PromotionKeywordAssociation> qry = _dbcontext.PromotionKeywordAssociations.Where(key => key.PromotionFK == promo.PromotionPK).ToList(); var kpos = new List<KeywordProbabilityObject>(); KeywordProbabilityObject kpo; foreach (PromotionKeywordAssociation pka in qry) { kpo = new KeywordProbabilityObject { keyword = pka.Keyword.Keyword1, semplestProbability = pka.SemplestProbability == null ? 0 : pka.SemplestProbability.Value, isTargetMSN = pka.IsTargetMSN, isTargetGoogle = pka.IsTargetGoogle, isDeleted = pka.IsDeleted, id = pka.KeywordFK }; kpos.Add(kpo); } SaveKeywords(promo.PromotionPK, kpos, model.NegativeKeywords, model.ProductGroup.ProductGroupName, model.ProductGroup.ProductPromotionName); }
public bool AddGeoTargetingToPromotion(Promotion promo, CampaignSetupModel model, int customerFk, CampaignSetupModel oldModel, out GeoTargetTableType gtt) { bool shouldUpdateGeoTargeting = false; gtt = new GeoTargetTableType(); GeoTargetTableTypeRow gtr; if (model.AdModelProp.Addresses != null) { foreach (GeoTargeting geo in model.AdModelProp.Addresses) { gtr = gtt.NewRow(); if (geo.Delete & !geo.HasBeenSaved) { var gt = promo.GeoTargetings.FirstOrDefault(x => x.GeoTargetingPK == geo.GeoTargetingPK); if (gt != null) { gtr.PKEY = geo.GeoTargetingPK; gtr.Operation = "D"; shouldUpdateGeoTargeting = true; } } else if (geo.GeoTargetingPK == 0 && !geo.IsCountry & !geo.HasBeenSaved) { shouldUpdateGeoTargeting = true; gtr.Address = geo.Address; gtr.City = geo.City; gtr.StateCodeFK = geo.StateCodeFK == int.MinValue ? null: geo.StateCodeFK; gtr.Zip = geo.Zip; gtr.ProximityRadius = geo.ProximityRadius; gtr.Latitude = geo.Latitude; gtr.Longitude = geo.Longitude; gtr.UID = geo.UID; gtr.Operation = "I"; } else if (!geo.IsCountry) { GeoTargeting geoOld = oldModel.AdModelProp.Addresses.SingleOrDefault(x => x.GeoTargetingPK == geo.GeoTargetingPK); if (geoOld.Address != geo.Address || geoOld.City != geo.City || geoOld.Latitude != geo.Latitude || geoOld.Longitude != geo.Longitude || geoOld.ProximityRadius != geo.ProximityRadius || geoOld.Zip != geo.Zip || geoOld.StateCodeFK != geo.StateCodeFK) { shouldUpdateGeoTargeting = true; gtr.Address = geo.Address; gtr.City = geo.City; gtr.Latitude = geo.Latitude; gtr.Longitude = geo.Longitude; gtr.ProximityRadius = geo.ProximityRadius; gtr.Zip = geo.Zip; gtr.StateCodeFK = geo.StateCodeFK == int.MinValue ? null : geo.StateCodeFK; gtr.PKEY = geo.GeoTargetingPK; gtr.Operation = "U"; } } if (!string.IsNullOrEmpty(gtr.Operation)) gtt.Add(gtr); } } return shouldUpdateGeoTargeting; }
public void SavePromotionAdEngineSelected(Promotion promo, CampaignSetupModel model, SemplestModel.Semplest dbcontext) { var existingAdenginesSeleccted = dbcontext.PromotionAdEngineSelecteds.Where(m => m.PromotionFK == promo.PromotionPK); var templist = new List<int>(); model.ProductGroup.AdEnginesList.ForEach(t => templist.Add(Convert.ToInt32(t))); var dn = existingAdenginesSeleccted.Where(t => !templist.Contains(t.AdvertisingEngineFK)); foreach (var adsel in dn) dbcontext.PromotionAdEngineSelecteds.Remove(adsel); foreach (int aes in model.ProductGroup.AdEnginesList) { int adengineid = Convert.ToInt32(aes); var proAdEng = dbcontext.AdvertisingEngines.FirstOrDefault(m => m.AdvertisingEnginePK == adengineid); if (proAdEng != null) { var adEngSelQuery = existingAdenginesSeleccted.FirstOrDefault( m => m.AdvertisingEngineFK == proAdEng.AdvertisingEnginePK); if (adEngSelQuery == null) { var adEngineSel = new PromotionAdEngineSelected { AdvertisingEngineFK = proAdEng.AdvertisingEnginePK, PromotionFK = promo.PromotionPK }; dbcontext.PromotionAdEngineSelecteds.Add(adEngineSel); } //dbcontext.SaveChanges(); } } }
private void UpdatePromotionFromModel(Promotion updatePromotion, CampaignSetupModel model, decimal customerDefaultPerCampaignFlatFeeAmount) { model.AdModelProp.LandingUrl = model.AdModelProp.LandingUrl.Trim(); model.AdModelProp.DisplayUrl = string.IsNullOrEmpty(model.AdModelProp.DisplayUrl) ? string.Empty : model.AdModelProp.DisplayUrl.Trim(); updatePromotion.LandingPageURL = model.AdModelProp.LandingUrl; updatePromotion.DisplayURL = model.AdModelProp.DisplayUrl; updatePromotion.PromotionDescription = model.ProductGroup.Words; updatePromotion.PromotionBudgetAmount = model.ProductGroup.Budget; updatePromotion.PromotionStartDate = Convert.ToDateTime(model.ProductGroup.StartDate, new CultureInfo("en-Us")); updatePromotion.CycleStartDate = Convert.ToDateTime(model.ProductGroup.StartDate, new CultureInfo("en-Us")); updatePromotion.PromotionEndDate = string.IsNullOrEmpty(model.ProductGroup.EndDate) ? (DateTime?) null : Convert.ToDateTime(model.ProductGroup.EndDate, new CultureInfo("en-Us")); updatePromotion.CycleEndDate = Convert.ToDateTime(model.ProductGroup.StartDate, new CultureInfo("en-Us")).AddMonths(1); updatePromotion.StartBudgetInCycle = model.ProductGroup.Budget - customerDefaultPerCampaignFlatFeeAmount; updatePromotion.RemainingBudgetInCycle = model.ProductGroup.Budget - customerDefaultPerCampaignFlatFeeAmount; updatePromotion.IsAutobid = model.ProductGroup.IsAutoBid; updatePromotion.AutoBidMaxCPC = model.ProductGroup.AutoBidMaxCPC; }
public Promotion CreatePromotionFromModel(CampaignSetupModel model, decimal customerDefaultPerCampaignFlatFeeAmount) { if (model.AdModelProp.LandingUrl != null && model.AdModelProp.DisplayUrl != null) { model.AdModelProp.LandingUrl = model.AdModelProp.LandingUrl.Trim(); model.AdModelProp.DisplayUrl = model.AdModelProp.DisplayUrl.Trim(); } var promo = new Promotion { //no whitespace in database PromotionName = model.ProductGroup.ProductPromotionName, LandingPageURL = model.AdModelProp.LandingUrl, DisplayURL = model.AdModelProp.DisplayUrl, PromotionDescription = model.ProductGroup.Words, PromotionBudgetAmount = model.ProductGroup.Budget, BudgetCycleFK = GetBudgetCycleId("Monthly"), PromotionEndDate = string.IsNullOrEmpty(model.ProductGroup.EndDate) ? (DateTime?)null : Convert.ToDateTime(model.ProductGroup.EndDate, new CultureInfo("en-Us")), CycleEndDate = Convert.ToDateTime(model.ProductGroup.StartDate, new CultureInfo("en-Us")).AddMonths(1), StartBudgetInCycle = model.ProductGroup.Budget - customerDefaultPerCampaignFlatFeeAmount, RemainingBudgetInCycle = model.ProductGroup.Budget - customerDefaultPerCampaignFlatFeeAmount, PromotionStartDate = Convert.ToDateTime(model.ProductGroup.StartDate, new CultureInfo("en-Us")), CycleStartDate = Convert.ToDateTime(model.ProductGroup.StartDate, new CultureInfo("en-Us")), IsPaused = false, IsCompleted = false, IsLaunched = false, CreatedDate = DateTime.Now, IsAutobid = model.ProductGroup.IsAutoBid, AutoBidMaxCPC = model.ProductGroup.AutoBidMaxCPC }; return promo; }
private static bool AddPromotionAdsToPromotion(Promotion promo, CampaignSetupModel model, int customerFk, CampaignSetupModel oldModel, out List<PromotionAd> addAds, out List<int> updateAds, out List<int> deleteAds) { deleteAds = new List<int>(); updateAds = new List<int>(); addAds = new List<PromotionAd>(); bool shouldscheduleAds = false; foreach (PromotionAd pad in model.AdModelProp.Ads) { if (pad.Delete && pad.PromotionAdsPK != 0 && !pad.HasBeenSaved) { var singlePromo = promo.PromotionAds.Single(id => id.PromotionAdsPK == pad.PromotionAdsPK); if (singlePromo != null) { deleteAds.Add(pad.PromotionAdsPK); shouldscheduleAds = true; } } else if (!pad.Delete && pad.PromotionAdsPK == 0 && !pad.HasBeenSaved) { shouldscheduleAds = true; addAds.Add(pad); pad.AdTextLine1 = pad.AdTextLine1; pad.AdTextLine2 = pad.AdTextLine2; pad.AdTitle = pad.AdTitle; var cad = new PromotionAd { AdTextLine1 = pad.AdTextLine1, AdTextLine2 = pad.AdTextLine2, AdTitle = pad.AdTitle, PromotionAdsPK = pad.PromotionAdsPK, CreatedDate = DateTime.Now }; promo.PromotionAds.Add(cad); } else if (!pad.Delete && pad.PromotionAdsPK != 0) { var padOld = oldModel.AdModelProp.Ads.Single(x => x.PromotionAdsPK == pad.PromotionAdsPK); if (padOld != null) { if (padOld.AdTextLine1 != pad.AdTextLine1 || padOld.AdTextLine2 != pad.AdTextLine2 || padOld.AdTitle != pad.AdTitle) { shouldscheduleAds = true; updateAds.Add(pad.PromotionAdsPK); var pa = promo.PromotionAds.Single(x => x.PromotionAdsPK == pad.PromotionAdsPK); pa.AdTextLine1 = pad.AdTextLine1; pa.AdTextLine2 = pad.AdTextLine2; pa.AdTitle = pad.AdTitle; } } } } return shouldscheduleAds; }
private bool AddSiteLinksToPromotion(Promotion promo, CampaignSetupModel model, int customerFk, System.Data.Objects.ObjectContext context, CampaignSetupModel oldModel) { bool shouldRefreshSiteLinks = false; if (model.SiteLinks != null) foreach (var sitelink in model.SiteLinks) { if (sitelink.Delete && !sitelink.SiteLinksSaved) { var sl = promo.SiteLinks.SingleOrDefault(x => x.SiteLInkPK == sitelink.SiteLInkPK); if (sl != null) { context.DeleteObject(sl); shouldRefreshSiteLinks = true; } } //TODO remove when the validation is added //if (!string.IsNullOrEmpty(sitelink.LinkText) && !string.IsNullOrEmpty((sitelink.LinkURL))) else if (sitelink.SiteLInkPK == 0 && !sitelink.SiteLinksSaved) { shouldRefreshSiteLinks = true; var slink = new SiteLink { LinkText = sitelink.LinkText, LinkURL = sitelink.LinkURL, PromotionFK = promo.PromotionPK }; promo.SiteLinks.Add(slink); } else { var siteOld = oldModel.SiteLinks.Single(x => x.SiteLInkPK == sitelink.SiteLInkPK); if (siteOld.LinkText != sitelink.LinkText || siteOld.LinkURL != sitelink.LinkURL) { shouldRefreshSiteLinks = true; var sl = promo.SiteLinks.Single(x => x.SiteLInkPK== sitelink.SiteLInkPK); sl.LinkText = sitelink.LinkText; sl.LinkURL = sitelink.LinkURL; } } } return shouldRefreshSiteLinks; }
public void SaveNegativeKeywords(Promotion promo, CampaignSetupModel model, SemplestModel.Semplest dbcontext) { IEnumerable<PromotionKeywordAssociation> qry = dbcontext.PromotionKeywordAssociations.Where(key => key.PromotionFK == promo.PromotionPK).ToList(); var kpos = new List<KeywordProbabilityObject>(); KeywordProbabilityObject kpo; foreach (PromotionKeywordAssociation pka in qry) { kpo = new KeywordProbabilityObject { keyword = pka.Keyword.Keyword1, semplestProbability = pka.SemplestProbability == null ? 0 : pka.SemplestProbability.Value, isTargetMSN = pka.IsTargetMSN, isTargetGoogle = pka.IsTargetGoogle }; kpos.Add(kpo); } if (model.AdModelProp.NegativeKeywords != null) foreach (string negativeKeyword in model.AdModelProp.NegativeKeywords) { if (!qry.Any(key => key.Keyword.Keyword1 == negativeKeyword)) { kpo = new KeywordProbabilityObject { keyword = negativeKeyword }; kpos.Add(kpo); } } SaveKeywords(promo.PromotionPK, kpos, model.AdModelProp.NegativeKeywords, model.ProductGroup.ProductGroupName, model.ProductGroup.ProductPromotionName); }
public void AddPromotionAdsToPromotion(Promotion promo, CampaignSetupModel model, int customerFk) { foreach (PromotionAd pad in model.AdModelProp.Ads.Where(t => !t.Delete)) { var cad = new PromotionAd { AdTextLine1 = pad.AdTextLine1, AdTextLine2 = pad.AdTextLine2, AdTitle = pad.AdTitle }; //if (pad.SiteLinks != null) //{ // // add sitelinks // foreach (SiteLink slink in pad.SiteLinks) // { // // this is check should be removed once we fix the logic in partialview and model // if (!String.IsNullOrEmpty(slink.LinkText) && !String.IsNullOrEmpty(slink.LinkURL)) // { // var slinkobj = new SiteLink { LinkText = slink.LinkText, LinkURL = slink.LinkURL }; // cad.SiteLinks.Add(slinkobj); // } // } //} promo.PromotionAds.Add(cad); try { var sw = new ServiceClientWrapper(); var adEngines = new List<string>(); var promoAds = new List<int>(); if (promo.IsLaunched) { adEngines.AddRange(promo.PromotionAdEngineSelecteds.Select(pades => pades.AdvertisingEngine.AdvertisingEngine1)); promoAds.AddRange(promo.PromotionAds.Select(pa => pa.PromotionAdsPK)); sw.scheduleAds(customerFk, promo.PromotionPK, promoAds, adEngines, true); } } catch (Exception ex) { SharedResources.Helpers.ExceptionHelper.LogException(ex.ToString()); } } }
public void AddSiteLinksToPromotion(Promotion promo, CampaignSetupModel model, int customerFk) { if (model.SiteLinks != null) foreach (var sitelink in model.SiteLinks) { var slink = new SiteLink { LinkText = sitelink.LinkText, LinkURL = sitelink.LinkURL, PromotionFK = promo.PromotionPK }; promo.SiteLinks.Add(slink); try { var sw = new ServiceClientWrapper(); var adEngines = new List<string>(); if (promo.IsLaunched) { adEngines.AddRange(promo.PromotionAdEngineSelecteds.Select(pades => pades.AdvertisingEngine.AdvertisingEngine1)); sw.scheduleRefreshSiteLinksForAd(customerFk, promo.PromotionPK, adEngines); } } catch (Exception ex) { SharedResources.Helpers.ExceptionHelper.LogException(ex.ToString()); } } }
public void AddGeoTargetingToPromotion(Promotion promo, CampaignSetupModel model, int customerFk) { if (model.AdModelProp.Addresses != null) { foreach (GeoTargeting geo in model.AdModelProp.Addresses) { // this is check should be removed once we fix the logic in partialview and model if (!String.IsNullOrEmpty(geo.Zip) || (!String.IsNullOrEmpty(geo.City) && geo.StateCodeFK > 0)) { if (geo.StateCodeFK < 0) geo.StateCodeFK = null; var geotarget = new GeoTargeting { Address = geo.Address, City = geo.City, StateCodeFK = geo.StateCodeFK, Zip = geo.Zip, ProximityRadius = geo.ProximityRadius, Latitude = geo.Latitude, Longitude = geo.Longitude }; promo.GeoTargetings.Add(geotarget); try { var sw = new ServiceClientWrapper(); var adEngines = new List<string>(); if (promo.IsLaunched) { adEngines.AddRange(promo.PromotionAdEngineSelecteds.Select(pades => pades.AdvertisingEngine.AdvertisingEngine1)); sw.scheduleUpdateGeoTargeting(customerFk, promo.PromotionPK, adEngines); } } catch (Exception ex) { SharedResources.Helpers.ExceptionHelper.LogException(ex.ToString()); } } } } }
public void UpdatePromotionFromModel(Promotion updatePromotion, CampaignSetupModel model, SemplestModel.Semplest dbcontext, int customerFk) { var configuration = dbcontext.Configurations.First(); updatePromotion.LandingPageURL = model.AdModelProp.LandingUrl; updatePromotion.DisplayURL = model.AdModelProp.DisplayUrl; updatePromotion.PromotionDescription = model.ProductGroup.Words; updatePromotion.PromotionBudgetAmount = model.ProductGroup.Budget; updatePromotion.PromotionStartDate = Convert.ToDateTime(model.ProductGroup.StartDate, new CultureInfo("en-Us")); updatePromotion.CycleStartDate = Convert.ToDateTime(model.ProductGroup.StartDate, new CultureInfo("en-Us")); updatePromotion.CycleEndDate = string.IsNullOrEmpty(model.ProductGroup.EndDate) ? Convert.ToDateTime(model.ProductGroup.StartDate, new CultureInfo("en-Us")).AddMonths(1) : Convert.ToDateTime(model.ProductGroup.EndDate, new CultureInfo("en-Us")); updatePromotion.StartBudgetInCycle = model.ProductGroup.Budget - configuration.CustomerDefaultPerCampaignFlatFeeAmount; updatePromotion.RemainingBudgetInCycle = model.ProductGroup.Budget - configuration.CustomerDefaultPerCampaignFlatFeeAmount; updatePromotion.EditedDate = DateTime.Now; try { var sw = new ServiceClientWrapper(); var adEngines = new List<string>(); if (updatePromotion.IsLaunched) { adEngines.AddRange(updatePromotion.PromotionAdEngineSelecteds.Select(pades => pades.AdvertisingEngine.AdvertisingEngine1)); sw.scheduleUpdateBudget(customerFk, updatePromotion.PromotionPK, model.ProductGroup.Budget, adEngines); sw.scheduleChangePromotionStartDate(customerFk, updatePromotion.PromotionPK, updatePromotion.PromotionStartDate, adEngines); } } catch (Exception ex) { SharedResources.Helpers.ExceptionHelper.LogException(ex.ToString()); } // update Geotargeting foreach (GeoTargeting geo in updatePromotion.GeoTargetings.ToList()) { dbcontext.GeoTargetings.Remove(geo); } // update promotion ads; delete first and add them again foreach (PromotionAd pad in updatePromotion.PromotionAds.ToList()) { //foreach (SiteLink sli in pad.SiteLinks.ToList()) //{ // dbcontext.SiteLinks.Remove(sli); //} dbcontext.PromotionAds.Remove(pad); } // update sitelink; delet first and add them foreach (var slink in updatePromotion.SiteLinks.ToList()) { dbcontext.SiteLinks.Remove(slink); } SavePromotionAdEngineSelected(updatePromotion, model, dbcontext); AddGeoTargetingToPromotion(updatePromotion, model, customerFk); AddSiteLinksToPromotion(updatePromotion, model, customerFk); AddPromotionAdsToPromotion(updatePromotion, model, customerFk); SaveNegativeKeywords(updatePromotion, model, dbcontext); dbcontext.SaveChanges(); }
public Promotion CreatePromotionFromModel(CampaignSetupModel model, decimal customerDefaultPerCampaignFlatFeeAmount) { var promo = new Promotion { PromotionName = model.ProductGroup.ProductPromotionName, LandingPageURL = model.AdModelProp.LandingUrl, DisplayURL = model.AdModelProp.DisplayUrl, PromotionDescription = model.ProductGroup.Words, PromotionBudgetAmount = model.ProductGroup.Budget, BudgetCycleFK = GetBudgetCycleId("Monthly"), CycleStartDate = Convert.ToDateTime(model.ProductGroup.StartDate, new CultureInfo("en-Us")), CycleEndDate = string.IsNullOrEmpty(model.ProductGroup.EndDate) ? Convert.ToDateTime(model.ProductGroup.StartDate, new CultureInfo("en-Us")).AddMonths(1) : Convert.ToDateTime(model.ProductGroup.EndDate, new CultureInfo("en-Us")), StartBudgetInCycle = model.ProductGroup.Budget - customerDefaultPerCampaignFlatFeeAmount, RemainingBudgetInCycle = model.ProductGroup.Budget - customerDefaultPerCampaignFlatFeeAmount, PromotionStartDate = Convert.ToDateTime(model.ProductGroup.StartDate, new CultureInfo("en-Us")), IsPaused = false, IsCompleted = false, IsLaunched = false, CreatedDate = DateTime.Now }; return promo; }
private bool AddSiteLinksToPromotion(Promotion promo, CampaignSetupModel model, int customerFk, System.Data.Objects.ObjectContext context, CampaignSetupModel oldModel, out SiteLinksTableType st) { bool shouldRefreshSiteLinks = false; st = new SiteLinksTableType(); if (model.SiteLinks != null) foreach (var sitelink in model.SiteLinks) { SiteLinksTableTypeRow str = st.NewRow(); if (sitelink.Delete && !sitelink.SiteLinksSaved) { var sl = promo.SiteLinks.SingleOrDefault(x => x.SiteLInkPK == sitelink.SiteLInkPK); if (sl != null) { str.Operation = "D"; str.PKEY = sl.SiteLInkPK; context.DeleteObject(sl); shouldRefreshSiteLinks = true; } } //TODO remove when the validation is added //if (!string.IsNullOrEmpty(sitelink.LinkText) && !string.IsNullOrEmpty((sitelink.LinkURL))) else if (sitelink.SiteLInkPK == 0 && !sitelink.SiteLinksSaved) { shouldRefreshSiteLinks = true; str.LinkText = sitelink.LinkText; str.LinkUrl = sitelink.LinkURL; str.UID = sitelink.UID; str.Operation = "I"; } else { var siteOld = oldModel.SiteLinks.Single(x => x.SiteLInkPK == sitelink.SiteLInkPK); if (siteOld.LinkText != sitelink.LinkText || siteOld.LinkURL != sitelink.LinkURL) { shouldRefreshSiteLinks = true; str.LinkText = sitelink.LinkText; str.LinkUrl = sitelink.LinkURL; str.PKEY = sitelink.SiteLInkPK; str.Operation = "U"; } } if (!string.IsNullOrEmpty(str.Operation)) st.Add(str); } return shouldRefreshSiteLinks; }
private static bool AddPromotionAdsToPromotion(Promotion promo, CampaignSetupModel model, int customerFk, CampaignSetupModel oldModel, out List<PromotionAd> addAds, out List<int> updateAds, out List<int> deleteAds, out PromoAdTableType att) { deleteAds = new List<int>(); updateAds = new List<int>(); addAds = new List<PromotionAd>(); bool shouldscheduleAds = false; att = new PromoAdTableType(); PromoAdTableTypeRow atr; foreach (PromotionAd pad in model.AdModelProp.Ads) { atr = att.NewRow(); if (pad.Delete && pad.PromotionAdsPK != 0) { var singlePromo = promo.PromotionAds.Single(id => id.PromotionAdsPK == pad.PromotionAdsPK); if (singlePromo != null) { if (!promo.IsLaunched) { atr.PKEY = pad.PromotionAdsPK; atr.Operation = "D"; } deleteAds.Add(pad.PromotionAdsPK); shouldscheduleAds = true; } } else if (!pad.Delete && pad.PromotionAdsPK == 0) { shouldscheduleAds = true; addAds.Add(pad); atr.AdTextLine1 = pad.AdTextLine1; atr.AdTextLine2 = pad.AdTextLine2; atr.AdTitle = pad.AdTitle; atr.UID = pad.UID; atr.Operation = "I"; } else if (!pad.Delete && pad.PromotionAdsPK != 0) { var oldAd = oldModel.AdModelProp.Ads.SingleOrDefault(x => x.PromotionAdsPK == pad.PromotionAdsPK); if (oldAd.AdTextLine1 != pad.AdTextLine1 || oldAd.AdTextLine2 != pad.AdTextLine2 || oldAd.AdTitle != pad.AdTitle) { shouldscheduleAds = true; updateAds.Add(pad.PromotionAdsPK); atr.AdTextLine1 = pad.AdTextLine1; atr.AdTextLine2 = pad.AdTextLine2; atr.AdTitle = pad.AdTitle; atr.PKEY = pad.PromotionAdsPK; atr.Operation = "U"; } } if (!string.IsNullOrEmpty(atr.Operation)) att.Add(atr); } return shouldscheduleAds; }
public bool AddGeoTargetingToPromotion(Promotion promo, CampaignSetupModel model, int customerFk, CampaignSetupModel oldModel, System.Data.Objects.ObjectContext context) { bool shouldUpdateGeoTargeting = false; if (model.AdModelProp.Addresses != null) { var modelIds = new List<int>(); foreach (GeoTargeting geo in model.AdModelProp.Addresses) { if (geo.Delete && !geo.HasBeenSaved) { var gt = promo.GeoTargetings.FirstOrDefault(x => x.GeoTargetingPK == geo.GeoTargetingPK); if (gt != null) { context.DeleteObject(gt); shouldUpdateGeoTargeting = true; } } else if (geo.GeoTargetingPK == 0 && !geo.IsCountry && !geo.HasBeenSaved) { shouldUpdateGeoTargeting = true; var geotarget = new GeoTargeting { Address = geo.Address, City = geo.City, StateCodeFK = geo.StateCodeFK, Zip = geo.Zip, ProximityRadius = geo.ProximityRadius, Latitude = geo.Latitude, Longitude = geo.Longitude }; promo.GeoTargetings.Add(geotarget); } else { GeoTargeting geo1 = geo; modelIds.Add(geo1.GeoTargetingPK); var geoOld = oldModel.AdModelProp.Addresses.FirstOrDefault(x => x.GeoTargetingPK == geo1.GeoTargetingPK); if (geoOld != null) { if (geoOld.Address != geo1.Address || geoOld.City != geo1.City || geoOld.Latitude != geo1.Latitude || geoOld.Longitude != geo1.Longitude || geoOld.ProximityRadius != geo1.ProximityRadius || geoOld.Zip != geo1.Zip || geoOld.StateCode.StateAbbrPK != geo1.StateCodeFK || geoOld.Promotion.PromotionName != model.ProductGroup.ProductPromotionName) { shouldUpdateGeoTargeting = true; var gt = promo.GeoTargetings.Single(x => x.GeoTargetingPK == geo1.GeoTargetingPK); gt.Address = geo1.Address; gt.City = geo1.City; gt.Latitude = geo1.Latitude; gt.Longitude = geo1.Longitude; gt.ProximityRadius = geo1.ProximityRadius; gt.Zip = geo1.Zip; gt.StateCodeFK = geo1.StateCodeFK; } } } } } return shouldUpdateGeoTargeting; }