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