public string SaveSiteLinks(CampaignSetupModel model, int customerFk, CampaignSetupModel oldModel)
        {
            bool shouldRefreshSiteLinks = false;
            var rString = new System.Text.StringBuilder();
            using (var dbcontext = new SemplestModel.Semplest())
            {
                var queryProd = (from c in dbcontext.ProductGroups
                                 where
                                     c.CustomerFK == customerFk &&
                                     c.ProductGroupName == model.ProductGroup.ProductGroupName
                                 select c).Single();
                var promo = GetPromotionFromProductGroup(queryProd, model.ProductGroup.ProductPromotionName);
                List<GoogleSiteLink> sl =
                                          model.SiteLinks.Where(t => !t.Delete).Select(row => new GoogleSiteLink
                                          {
                                              LinkText = row.LinkText,
                                              LinkURL = row.LinkURL
                                          }).ToList();
                if (sl.Any())
                {
                    GoogleViolation[] gv = ValidateSiteLinks(sl);
                    if (gv.Length > 0)
                        throw new Exception(gv.First().shortFieldPath + ": " + gv.First().errorMessage);
                }
                SiteLinksTableType st;
                shouldRefreshSiteLinks = AddSiteLinksToPromotion(promo, model, customerFk, ((IObjectContextAdapter)dbcontext).ObjectContext, oldModel, out st);

                var parameter = new SqlParameter("PromotionPK", promo.PromotionPK) { SqlDbType = SqlDbType.Int };
                var parameter2 = new SqlParameter("SlTVP", st) { SqlDbType = SqlDbType.Structured, TypeName = "SiteLinksTableType" };
                var parameters = new object[] { parameter, parameter2 };
                var results = ((IObjectContextAdapter)dbcontext).ObjectContext.ExecuteStoreQuery<RVal>("exec UpdateSiteLinks @PromotionPK, @SlTVP", parameters);
                _savedCampaign = true;
                foreach (var r in results)
                {
                    rString.Append(r.UID);
                    rString.Append("=");
                    rString.Append(r.PKEY);
                    rString.Append(",");
                }
                _savedCampaign = true;
                try
                {
                    var adEngines = new List<string>();
                    if (promo.IsLaunched && shouldRefreshSiteLinks)
                    {
                        adEngines.AddRange(
                            promo.PromotionAdEngineSelecteds.Select(pades => pades.AdvertisingEngine.AdvertisingEngine1));
                        var sw = new ServiceClientWrapper();
                        sw.scheduleRefreshSiteLinks(promo.PromotionPK, adEngines);
                    }
                }
                catch (Exception ex)
                {
                    SharedResources.Helpers.ExceptionHelper.LogException(ex);
                }
            }
            return string.IsNullOrEmpty(rString.ToString()) ? String.Empty : rString.ToString().Substring(0, rString.ToString().Length - 1);
        }
 public void SaveSiteLinks(CampaignSetupModel model, int customerFk, CampaignSetupModel oldModel)
 {
     bool shouldRefreshSiteLinks = false;
     using (var dbcontext = new SemplestModel.Semplest())
     {
         var queryProd = (from c in dbcontext.ProductGroups
                          where
                              c.CustomerFK == customerFk &&
                              c.ProductGroupName == model.ProductGroup.ProductGroupName
                          select c).Single();
         var promo = GetPromotionFromProductGroup(queryProd, model.ProductGroup.ProductPromotionName);
         List<GoogleSiteLink> sl =
                                   model.SiteLinks.Where(t => !t.Delete).Select(row => new GoogleSiteLink
                                   {
                                       LinkText = row.LinkText,
                                       LinkURL = row.LinkURL
                                   }).ToList();
         if (sl.Any())
         {
             GoogleViolation[] gv = ValidateSiteLinks(sl);
             if (gv.Length > 0)
                 throw new Exception(gv.First().shortFieldPath + ": " + gv.First().errorMessage);
         }
         shouldRefreshSiteLinks = AddSiteLinksToPromotion(promo, model, customerFk, ((IObjectContextAdapter)dbcontext).ObjectContext, oldModel);
         dbcontext.SaveChanges();
         _savedCampaign = true;
         try
         {
             var adEngines = new List<string>();
             if (promo.IsLaunched && shouldRefreshSiteLinks)
             {
                 adEngines.AddRange(
                     promo.PromotionAdEngineSelecteds.Select(pades => pades.AdvertisingEngine.AdvertisingEngine1));
                 var sw = new ServiceClientWrapper();
                 sw.scheduleRefreshSiteLinks(promo.PromotionPK, adEngines);
             }
         }
         catch (Exception ex)
         {
             SharedResources.Helpers.ExceptionHelper.LogException(ex);
         }
     }
 }