//END MONTHLY OFFER //----------------------------------------ADS------------------------------------------------------------------ public ViewResult Ads() { var ads = _context.Ads.ToList(); var newViewModel = new AdsView { TopAdsList = ads }; return(View(newViewModel)); }
public async void OnStart() { Initialize(); // Initialize ads await AdsView.Init(); // Delay so the ad doesn't appear immediately await Task.Delay(1000); // Start ads Ads.Start(); }
public ActionResult DeleteAdd(string id) { var idInt = int.Parse(id); var ads = _context.Ads.SingleOrDefault(x => x.Id == idInt); _context.Ads.Remove(ads ?? throw new InvalidOperationException()); _context.SaveChanges(); var adsFull = _context.Ads.ToList(); var newViewModel = new AdsView { TopAdsList = adsFull }; return(View("Ads", newViewModel)); }
public ActionResult AdsAdd(AdsView adsView) { var ads = _context.Ads.ToList(); ads.Add(new Ads { Id = adsView.TopAds.Id, Alt = adsView.TopAds.Alt, Title = adsView.TopAds.Title, ImgUrl = adsView.TopAds.ImgUrl, TopBottom = adsView.TopAds.TopBottom, Url = adsView.TopAds.Url }); _context.Ads.AddRange(ads); _context.SaveChanges(); var newViewModel = new AdsView { TopAdsList = ads }; return(View("Ads", newViewModel)); }
public override void DataBind() { if (_bound) { return; } _bound = true; CustomPage page = this.Page as CustomPage; string ids = ""; if (page != null) { if (page.PageContext[cte.AdsContext] != null) { ids = page.PageContext[cte.AdsContext].ToString(); } else { page.AddContext(cte.AdsContext, "", false); } } _ad = _aMgr.GetAd(Zone, Keywords, ids); if (_ad == null) { return; } AdsView ad = _ad; if (page != null) { page.AddContext(cte.AdsContext, string.Format("{0},{1}", page.PageContext[cte.AdsContext], ad.AdId), true); } switch (_type) { case AdRenderType.Image: if (string.IsNullOrEmpty(ad.Image)) { goto default; } if (string.IsNullOrEmpty(ad.URL)) { _render = string.Format("<img src=\"{0}\" alt=\"{1}\" />", ad.Image, ad.Description ); } else { _render = string.Format("<a href=\"{0}\" title=\"{1}\"{3}><img src=\"{2}\" alt=\"{1}\" /></a>", ad.URL, ad.Description, ad.Image, ad.NewWindow != null && ad.NewWindow.Value ? " target=\"_blank\"" : "" ); } break; case AdRenderType.Html: if (string.IsNullOrEmpty(ad.HtmlCode)) { goto default; } _render = ad.HtmlCode; break; case AdRenderType.Name: default: _render = string.Format("<a href=\"{0}\" title=\"{1}\">{1}</a>", ad.URL, ad.Description); break; } base.DataBind(); }
/// <summary> /// Get just one ad depending on zone and keywords /// </summary> /// <param name="Zone">Name of the Zone ex: left, top banner ...</param> /// <param name="Keywords">list of keywords</param> /// <param name="AdIds">optionnal: list of already displayed Ads to avoid repeated ads, this automaticcally acumulated with in the PageContext[cte.AdsContext]</param> /// <returns></returns> public AdsView GetAd(string Zone, string Keywords, string AdIds) { //We Need just one record StringBuilder sql = new StringBuilder("select top 1 AdsView.*, NewId() as Ran from AdsView where"); //Status have to be default or active sql.Append(string.Format(" Status in ({0}, {1})", (int)AdStatus.Active, (int)AdStatus.Default)); //Ad Zone if (!String.IsNullOrEmpty(Zone)) { sql.Append(string.Format(" and ZoneName=N'{0}'", StringUtils.SQLEncode(Zone))); } /* * Check for keywords * AdKeywordsRelations(AdId, KeywordId) link between ads and keywords */ if (!String.IsNullOrEmpty(Keywords)) { sql.Append(String.Format(@" and AdId in (select AdId from Ads_AdKeywordRelation where KeywordId in (select KeywordId from Ads_Keywords where Keyword in (select id from [dbo].[StringToTable]('{0}')) ) )" , StringUtils.SQLEncode(Keywords))); } //Date have to be between start and end date sql.Append(" and getDate() between IsNull(StartDate, getDate()) and IsNull(EndDate, getDate())"); // Check for payment types the units purchased must be more than impressions or clicks sql.Append(string.Format(" and (PaymentType={0} or", (int)AdPaymentTypes.None)); sql.Append(string.Format("(PaymentType={0} and UnitsPurchased*CostPerUnit < Impressions) or", (int)AdPaymentTypes.PerImpression)); sql.Append(string.Format("(PaymentType={0} and UnitsPurchased*CostPerUnit < Clicks))", (int)AdPaymentTypes.PerClick)); //GetThisHousImpression calculate data from Ads_Report sql.Append(" and (MaxImpressionPerHour is null or MaxImpressionPerHour = 0 or MaxImpressionPerHour > [dbo].GetThisHourImpressions(AdId))"); //GetThisDayImpressions calculate data from Ads_Report sql.Append(" and (MaxImpressionPerDay is null or MaxImpressionPerDay = 0 or MaxImpressionPerDay > [dbo].GetThisDayImpressions(AdId))"); /* * Check for ids that are already displayed * Are passed in the AdIds parameter * and are stored in page.PageContext["AdIds"] */ if (!String.IsNullOrEmpty(AdIds)) { sql.Append(string.Format(" and AdId not in (-1{0})", AdIds)); } /* * order by Status active = 2, default = 1 so active comes before default * Ran to randomize */ sql.Append("order by AdsView.Status Desc,Ran"); DataSet ds = DBUtils.GetDataSet(sql.ToString(), cte.lib); AdsView ad = null; if (ds.Tables[0].Rows.Count > 0) { DataRow row = ds.Tables[0].Rows[0]; ad = new AdsView { AdId = (int)row["AdId"], Name = row["Name"].ToString(), AdvertiserId = (int?)row["AdvertiserId"], Status = (short?)row["Status"], ZoneId = (int?)row["ZoneId"], StartDate = (DateTime?)(row["StartDate"] != DBNull.Value? row["StartDate"] : null), EndDate = (DateTime?)(row["EndDate"] != DBNull.Value? row["EndDate"]: null), PaymentType = (short?)(row["PaymentType"] != DBNull.Value? row["PaymentType"] :null), UnitsPurchased = (int?)(row["UnitsPurchased"] != DBNull.Value? row["UnitsPurchased"]: null), CostPerUnit = (decimal?)(row["CostPerUnit"] != DBNull.Value? row["CostPerUnit"]: null), Image = row["Image"].ToString(), Description = row["Description"].ToString(), HtmlCode = row["HtmlCode"].ToString(), URL = row["URL"].ToString(), NewWindow = (bool?)row["NewWindow"], Weight = (short?)(row["Weight"] != DBNull.Value? row["Weight"]: null), MaxImpressionPerDay = (int?)(row["MaxImpressionPerDay"] != DBNull.Value?row["MaxImpressionPerDay"] : null), MaxImpressionPerHour = (int?)(row["MaxImpressionPerHour"] != DBNull.Value? row["MaxImpressionPerHour"]: null), DateCreated = (DateTime?)row["DateCreated"], DateModified = (DateTime?)row["DateModified"] }; ad.Image = String.IsNullOrEmpty(ad.Image) ? ad.Image : String.Format("{0}/{1}/{2}", WebContext.Root, Folders.AdsFolder, ad.Image); if (!String.IsNullOrEmpty(ad.URL)) { ad.URL = String.IsNullOrEmpty(ad.URL) ? ad.URL : String.Format("{0}://{1}{2}/{3}?AdId={4}", WebContext.Protocol, WebContext.ServerName, WebContext.Root, Files.AdsHandler, ad.AdId); } /* * {ad:image} and {ad:url} can be used in html * and are automaticcally replaced by their dynamic alternatives. */ ad.HtmlCode = ad.HtmlCode.Replace("{ad:image}", string.Format("<img src=\"{0}\" alt=\"{1}\" />", ad.Image, ad.Description)); ad.HtmlCode = ad.HtmlCode.Replace("{ad:url}", ad.URL); } /* * update impression counter is called when the add is actually displayed and not here. * can be found uner lw.Controls.Ad (OnUnload) */ return(ad); }