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 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()); } } }