本文整理汇总了C#中SemplestModel.Semplest.SetNegativeKeyword方法的典型用法代码示例。如果您正苦于以下问题:C# Semplest.SetNegativeKeyword方法的具体用法?C# Semplest.SetNegativeKeyword怎么用?C# Semplest.SetNegativeKeyword使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SemplestModel.Semplest
的用法示例。
在下文中一共展示了Semplest.SetNegativeKeyword方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveNegativeKeywords
public List<CampaignSetupModel.KeywordsModel> SaveNegativeKeywords(CampaignSetupModel model, int customerFk)
{
if (model.AdModelProp.NegativeKeywords.Any())
{
GoogleViolation[] gv = ValidateGoogleNegativeKeywords(model.AdModelProp.NegativeKeywords);
if (gv.Length > 0)
throw new Exception(gv.First().shortFieldPath + ": " + gv.First().errorMessage);
}
using (var dbcontext = new SemplestModel.Semplest())
{
var promo = GetPromoitionFromCampaign(dbcontext, customerFk, model);
if (!promo.IsLaunched)
{ RefreshKeywords(model, promo); }
else
{
var addKiops = new List<KeywordIdRemoveOppositePair>();
var addNewKiops = new List<string>();
var addDeletedKiops = new List<int>();
var qpka = promo.PromotionKeywordAssociations.ToList();
//check negative keywords that have been added to the gui
if (model.AdModelProp.NegativeKeywords != null)
{
foreach (string negativeKeyword in model.AdModelProp.NegativeKeywords)
{
var kiop = new KeywordIdRemoveOppositePair();
var pka = qpka.SingleOrDefault(key => key.Keyword.Keyword1 == negativeKeyword);
if (pka != null)
{
//means if the keyword existied and was positive it needs to be removed and added as a negative.
//if the keyword is already negative then do nothing because we've already added it
kiop.keywordId = pka.KeywordFK;
if (!pka.IsNegative)
{
kiop.removeOpposite = true;
addKiops.Add(kiop);
}
}
else
{
var kw = dbcontext.Keywords.SingleOrDefault(key => key.Keyword1 == negativeKeyword);
if (kw != null)
{
kiop.keywordId = kw.KeywordPK;
kiop.removeOpposite = false;
addKiops.Add(kiop);
}
else//this keyword doesn't exist in the database so when we call the stored proc get the id so it can be sent to the api
addNewKiops.Add(negativeKeyword);
}
}
}
//check for negative keywords that have been removed from the gui
foreach (PromotionKeywordAssociation k in qpka.Where(key => key.IsNegative == true).ToList())
{
if (!model.AdModelProp.NegativeKeywords.Contains(k.Keyword.Keyword1))
addDeletedKiops.Add(k.Keyword.KeywordPK);
}
List<int> deletedKeywords = new List<int>();
var op = new System.Data.Objects.ObjectParameter("NegativeKeywordID", typeof(int));
var op2 = new System.Data.Objects.ObjectParameter("Exists", typeof(int));
foreach (string kw in model.AdModelProp.NegativeKeywords)
{
//keywords that need to be deleted
var snr = dbcontext.SetNegativeKeyword(kw, promo.PromotionPK, op, op2).ToList();
if (snr.Any())
{
deletedKeywords.AddRange(snr.Select(ids => ids.KeywordPK));
}
if (!string.IsNullOrEmpty(op.Value.ToString()))
{
var kop = new KeywordIdRemoveOppositePair { keywordId = int.Parse(op.Value.ToString()), removeOpposite = bool.Parse(op2.Value.ToString()) };
addKiops.Add(kop);
}
}
foreach (int dk in addDeletedKiops)
promo.PromotionKeywordAssociations.Single(kw => kw.KeywordFK == dk).IsDeleted=true;
dbcontext.SaveChanges();
_savedCampaign = true;
var sw = new ServiceClientWrapper();
var adEngines = new List<string>();
adEngines.AddRange(
promo.PromotionAdEngineSelecteds.Select(pades => pades.AdvertisingEngine.AdvertisingEngine1));
if (addDeletedKiops.Any())
sw.DeleteNegativeKeywords(promo.PromotionPK, addDeletedKiops, adEngines);
if (addKiops.Any())
sw.AddNegativeKeywords(promo.PromotionPK, addKiops, adEngines);
if (deletedKeywords.Any())
sw.DeleteKeywords(promo.PromotionPK, deletedKeywords, adEngines);
}
model.AllKeywords.Clear();
model.AllKeywords.AddRange(
promo.PromotionKeywordAssociations.Where(key => !key.IsDeleted && !key.IsNegative).Select(
key =>
new CampaignSetupModel.KeywordsModel { Name = key.Keyword.Keyword1, Id = key.Keyword.KeywordPK }));
}
return model.AllKeywords;
}