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();
                }
            }
        }
 public CategoriesRepository(SemplestModel.Semplest dbcontext)
 {
     _dbcontext = dbcontext;
 }
 private Promotion GetPromoitionFromCampaign(SemplestModel.Semplest dbcontext, int customerFK, CampaignSetupModel model)
 {
     var queryProd = (from c in dbcontext.ProductGroups
                      where
                          c.CustomerFK == customerFK &&
                          c.ProductGroupName == model.ProductGroup.ProductGroupName
                      select c).Single();
     return GetPromotionFromProductGroup(queryProd, model.ProductGroup.ProductPromotionName);
 }
        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 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 PromotionRepository(SemplestModel.Semplest dbcontext)
 {
     _dbcontext = dbcontext;
 }
 public CreditCardRepository(SemplestModel.Semplest dbcontext)
 {
     _dbcontext = dbcontext;
 }
 public BillTypeRepository(SemplestModel.Semplest dbcontext)
 {
     _dbcontext = dbcontext;
 }
Beispiel #9
0
 public StateRepository(SemplestModel.Semplest dbContext)
 {
     _dbContext = dbContext;
 }
 public KeyWordRepository(SemplestModel.Semplest dbcontext)
 {
     _dbcontext = dbcontext;
 }