示例#1
0
 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;
 }
示例#2
0
 public GeoTargeting MapGeoTargeting(GeoTargeting geoTargeting)
 {
     return new GeoTargeting();
 }
示例#3
0
        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()); }
                    }
                }
            }
        }