public override IEnumerable <ProductModel> GetCampaignProducts() { if (Model != null) { var model = (IEnumerable <PriceByProductCampaignItemModel>)Model; var campaignModel = new PriceByProductCampaignModel(model); IList <EntityProduct> products = campaignModel.Select(item => Repository.Data.Get <EntityProduct>().Where(x => x.Id == item.Id && x.Published).FirstOrDefault().Value).ToList(); IList <ProductModel> productModels = products.ConvertAll().ToList(); ApplyCampaign(productModels); return(productModels); } return(new List <ProductModel>()); }
public override void ApplyCampaign(IList <ProductModel> products) { foreach (var product in products.Where(x => x.Published)) { var model = (IEnumerable <PriceByProductCampaignItemModel>)Model; var campaignModel = new PriceByProductCampaignModel(model); if (campaignModel.ContainsKey(product.Id)) { product.IsInCampaign = true; product.CampaignPrice = campaignModel[product.Id].CampaignPrice; } } }