/// <summary> /// Creates an advertisement zone. /// </summary> /// <param name="Name">Name of the zone</param> /// <param name="Status"></param> /// <param name="Width">Width to auto resize related images</param> /// <param name="Height">Height to auto resize related images</param> /// <param name="Description">Description, used internaly to describe how and where this zone is used.</param> /// <returns>The ZoneId</returns> public int CreateZone(string Name, bool Status, short?Width, short?Height, string Description) { var q = from _zone in GetZones() where _zone.Name == Name select _zone; if (q.Count() > 0) { return(-1); } Ads_Zone zone = new Ads_Zone { Name = Name, Alias = StringUtils.ToURL(Name), Status = Status, Width = Width, Height = Height, Description = Description, }; AdsData.Ads_Zones.InsertOnSubmit(zone); AdsData.SubmitChanges(); return(zone.ZoneId); }
private void onAdWatched(VideoResult result) { if (result.Success) { AdsData customData = (AdsData)result.CustomData; Player player = GameLogic.Binder.GameState.Player; this.sendAdViewEvent(player, customData.AdReward, customData.AdZone, "finish"); this.sendCrmEvent(player, "crm_ad_view_watch"); } }
public bool DeleteKeyword(int KeywordId) { Ads_Keyword keyword = AdsData.Ads_Keywords.Single( temp => temp.KeywordId == KeywordId); if (keyword != null) { AdsData.Ads_Keywords.DeleteOnSubmit(keyword); AdsData.SubmitChanges(); } return(true); }
private AdsData GetAdsDataByName(string name) { AdsData result = new AdsData("default"); foreach (var ads in adsCollection) { if (ads.adsName == name) { result = ads; } } return(result); }
public void DeleteZone(int ZoneId) { var ads = from ad in AdsData.Ads where ad.ZoneId == ZoneId select ad; foreach (Ad ad in ads) { DeleteAd(new int[] { ad.AdId }); } var zone = AdsData.Ads_Zones.Single(z => z.ZoneId == ZoneId); AdsData.Ads_Zones.DeleteOnSubmit(zone); AdsData.SubmitChanges(); }
public int CreateKeyword(string Name) { var q = from key in GetKeywords() where key.Keyword == Name select key; if (q.Count() > 0) { return(-1); } int?KeywordId = 0; AdsData.Ads_CreateKeyword(Name.Trim(), ref KeywordId); return(KeywordId.Value); }
public int UpdateKeyword(int KeywordId, string Name) { var query = from key in AdsData.Ads_Keywords where key.Keyword == Name && key.KeywordId != KeywordId select key; if (query.Count() > 0) { return(-1); } Ads_Keyword keyword = AdsData.Ads_Keywords.Single( key => key.KeywordId == KeywordId); keyword.Keyword = Name; AdsData.SubmitChanges(); return(keyword.KeywordId); }
public void DeleteAd(int[] AdIds) { var q = from ad in AdsData.Ads where AdIds.Contains(ad.AdId) select ad; foreach (Ad ad in q.AsEnumerable()) { if (!String.IsNullOrEmpty(ad.Image)) { string path = string.Format("{0}/{1}/{2}", WebContext.Root, Folders.AdsFolder, ad.Image); path = WebContext.Server.MapPath(path); if (File.Exists(path)) { File.Delete(path); } } } AdsData.Ads.DeleteAllOnSubmit(q); AdsData.SubmitChanges(); }
public int UpdateZone(int ZoneId, string Name, bool Status, short?Width, short?Height, string Description) { var q = from _zone in GetZones() where _zone.Name == Name && _zone.ZoneId != ZoneId select _zone; if (q.Count() > 0) { return(-1); } Ads_Zone zone = AdsData.Ads_Zones.Single(z => z.ZoneId == ZoneId); zone.Name = Name; zone.Alias = StringUtils.ToURL(Name); zone.Status = Status; zone.Width = Width; zone.Height = Height; zone.Description = Description; AdsData.SubmitChanges(); return(zone.ZoneId); }
public void UpdateAdClicks(int AdId) { AdsData.Ads_UpdateImpressions(AdId, true); }
public int GetAdsCooldownSecond(string adsName) { AdsData ads = GetAdsDataByName(adsName); return(ads.GetAdsCooldownSecond()); }
public void ResetAdsCount(string adsName) { AdsData ads = GetAdsDataByName(adsName); ads.adsCount = 0; }
public void OnWatchAdsCompleted(string adsName) { AdsData ads = GetAdsDataByName(adsName); ads.OnShowAds(); }
public bool CanShowAds(string adsName) { AdsData ads = GetAdsDataByName(adsName); return(ads.CanShowAds()); }
public void UpdateAdImpressions(int AdId) { AdsData.Ads_UpdateImpressions(AdId, false); }
/// <summary> /// Creates an advertisement /// </summary> /// <param name="Name">Display Name</param> /// <param name="AdvertiserId">Member Id</param> /// <param name="Status">lw.CTE.Enum.AdStatus</param> /// <param name="ZoneId">Zone</param> /// <param name="StartDate">Start Date</param> /// <param name="EndDate">End Date</param> /// <param name="PaymentType">lw.CTE.Enum.AdPaymentTypes</param> /// <param name="UnitsPurchased">Number of purchased units will be used against number of impressions depending on Payment Type and CostPerUnit</param> /// <param name="CostPerUnit">Cost per purchased unit</param> /// <param name="Image">Ad Image</param> /// <param name="AutoResize">AutoResize if true the image will be automatically resized to the Zone dimensions</param> /// <param name="Description">Descritpion (can appear on the title or alt tag)</param> /// <param name="HtmlCode">HtmlCode we can display it as html on the website</param> /// <param name="Url">The Ad URL</param> /// <param name="NewWindow">if the Ad should open in a new window</param> /// <param name="Weight">the more weight the more the add is important and can be displayed more frequently</param> /// <param name="MaxImpressionPerHour">MaxImpressionsPerHour</param> /// <param name="MaxImpressionPerDay">MaxImpressionsPerHour</param> /// <param name="Keywords">Related keywords, new keywords are automatically created and inserted into the Ad_Keywords Table</param> /// <returns>Created AD ID</returns> public int CreateAd(string Name, int?AdvertiserId, AdStatus?Status, int?ZoneId, DateTime?StartDate, DateTime?EndDate, AdPaymentTypes?PaymentType, int?UnitsPurchased, int?CostPerUnit, HttpPostedFile Image, bool?AutoResize, string Description, string HtmlCode, string Url, bool?NewWindow, short?Weight, int?MaxImpressionPerHour, int?MaxImpressionPerDay, string Keywords) { if (StringUtils.IsNullOrWhiteSpace(Name)) { return(-1); } var q = from _ad in GetAds() where _ad.Name == Name select _ad; if (q.Count() > 0) { return(-1); } Ad ad = new Ad { Name = Name, AdvertiserId = AdvertiserId, Status = (short)Status, ZoneId = ZoneId, StartDate = StartDate, EndDate = EndDate, PaymentType = (short)PaymentType, UnitsPurchased = UnitsPurchased, CostPerUnit = CostPerUnit, Image = "", Description = Description, HtmlCode = HtmlCode, URL = Url, NewWindow = NewWindow, Weight = Weight, MaxImpressionPerHour = MaxImpressionPerHour, MaxImpressionPerDay = MaxImpressionPerDay, DateCreated = DateTime.Now, DateModified = DateTime.Now }; AdsData.Ads.InsertOnSubmit(ad); AdsData.SubmitChanges(); if (Image != null && Image.ContentLength > 0) { string ImageName = Path.GetFileNameWithoutExtension(Image.FileName); ImageName = string.Format("{0}_{1}{2}", ImageName, ad.AdId, Path.GetExtension(Image.FileName)); string path = WebContext.Server.MapPath(Path.Combine(WebContext.StartDir, Folders.AdsFolder)); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path = Path.Combine(path, ImageName); Image.SaveAs(path); if (AutoResize != null && AutoResize.Value == true) { Ads_Zone zone = GetZone(ZoneId); if (zone.Width > 0 && zone.Height > 0) { ImageUtils.Resize(path, path, (int)zone.Width, (int)zone.Height); } } ad.Image = ImageName; AdsData.SubmitChanges(); } if (!String.IsNullOrEmpty(Keywords)) { string[] keywords = Keywords.Split(new char[] { ',', ' ', ';' }); var keywordsQuery = from keyword in AdsData.Ads_Keywords where keywords.Contains(keyword.Keyword) select keyword; foreach (string key in keywords) { Ads_AdKeywordRelation rel; if (keywordsQuery.Where(temp => temp.Keyword == key).Count() > 0) { rel = new Ads_AdKeywordRelation { AdId = ad.AdId, KeywordId = keywordsQuery.Single(temp => temp.Keyword == key).KeywordId }; } else { rel = new Ads_AdKeywordRelation { AdId = ad.AdId, KeywordId = CreateKeyword(key) }; } AdsData.Ads_AdKeywordRelations.InsertOnSubmit(rel); } AdsData.SubmitChanges(); } return(ad.AdId); }
/// <summary> /// Creates an advertisement /// </summary> /// <param name="AdId">AD ID</param> /// <param name="Name">Display Name</param> /// <param name="AdvertiserId">Member Id</param> /// <param name="Status">lw.CTE.Enum.AdStatus</param> /// <param name="ZoneId">Zone</param> /// <param name="StartDate">Start Date</param> /// <param name="EndDate">End Date</param> /// <param name="PaymentType">lw.CTE.Enum.AdPaymentTypes</param> /// <param name="UnitsPurchased">Number of purchased units will be used against number of impressions depending on Payment Type and CostPerUnit</param> /// <param name="CostPerUnit">Cost per purchased unit</param> /// <param name="Image">Ad Image</param> /// <param name="DeleteOldImage">Delete Old Image flag, if true the image will deleted, if we have new image the parameter is ignored.</param> /// <param name="AutoResize">AutoResize if true the image will be automatically resized to the Zone dimensions</param> /// <param name="Description">Descritpion (can appear on the title or alt tag)</param> /// <param name="HtmlCode">HtmlCode we can display it as html on the website</param> /// <param name="Url">The Ad URL</param> /// <param name="NewWindow">if the Ad should open in a new window</param> /// <param name="Weight">the more weight the more the add is important and can be displayed more frequently</param> /// <param name="MaxImpressionPerHour">MaxImpressionsPerHour</param> /// <param name="MaxImpressionPerDay">MaxImpressionsPerHour</param> /// <param name="Keywords">Related keywords, new keywords are automatically created and inserted into the Ad_Keywords Table</param> /// <returns>AD ID or -1 in case of error</returns> public int UpdateAd(int AdId, string Name, int?AdvertiserId, AdStatus?Status, int?ZoneId, DateTime?StartDate, DateTime?EndDate, AdPaymentTypes?PaymentType, int?UnitsPurchased, int?CostPerUnit, HttpPostedFile Image, bool?AutoResize, bool DeleteOldImage, string Description, string HtmlCode, string Url, bool?NewWindow, short?Weight, int?MaxImpressionPerHour, int?MaxImpressionPerDay, string Keywords) { var q = from _ad in GetAds() where _ad.Name == Name && _ad.AdId != AdId select _ad; if (q.Count() > 0) { return(-1); } Ad ad = AdsData.Ads.Single(temp => temp.AdId == AdId); ad.Name = Name; ad.AdvertiserId = AdvertiserId; ad.Status = (short)Status; ad.ZoneId = ZoneId; ad.StartDate = StartDate; ad.EndDate = EndDate; ad.PaymentType = (short)PaymentType; ad.UnitsPurchased = UnitsPurchased; ad.CostPerUnit = CostPerUnit; ad.Description = Description; ad.HtmlCode = HtmlCode; ad.URL = Url; ad.NewWindow = NewWindow; ad.Weight = Weight; ad.MaxImpressionPerHour = MaxImpressionPerHour; ad.MaxImpressionPerDay = MaxImpressionPerDay; ad.DateModified = DateTime.Now; string path = WebContext.Server.MapPath(Path.Combine(WebContext.StartDir, Folders.AdsFolder)); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var oldImage = ad.Image; if (Image != null && Image.ContentLength > 0) { DeleteOldImage = true; string ImageName = Path.GetFileNameWithoutExtension(Image.FileName); ImageName = string.Format("{0}_{1}{2}", ImageName, ad.AdId, Path.GetExtension(Image.FileName)); string _path = Path.Combine(path, ImageName); Image.SaveAs(_path); if (AutoResize != null && AutoResize.Value) { Ads_Zone zone = GetZone(ZoneId); if (zone.Width > 0 && zone.Height > 0) { ImageUtils.Resize(_path, _path, (int)zone.Width, (int)zone.Height); } } if (ImageName == ad.Image) { DeleteOldImage = false; } ad.Image = ImageName; AdsData.SubmitChanges(); } if (DeleteOldImage) { path = Path.Combine(path, oldImage); if (File.Exists(path)) { File.Delete(path); } } List <int> thisAdKeywords = new List <int>(); if (!String.IsNullOrEmpty(Keywords)) { string[] keywords = Keywords.Split(','); var keywordsQuery = from keyword in AdsData.Ads_Keywords where keywords.Contains(keyword.Keyword) select keyword; foreach (string key in keywords) { Ads_AdKeywordRelation rel; if (keywordsQuery.Where(temp => temp.Keyword == key).Count() > 0) { int _keyId = keywordsQuery.Single(temp => temp.Keyword == key).KeywordId; if (!AdInKeyword(AdId, _keyId)) { rel = new Ads_AdKeywordRelation { AdId = ad.AdId, KeywordId = _keyId }; AdsData.Ads_AdKeywordRelations.InsertOnSubmit(rel); } thisAdKeywords.Add(_keyId); } else { rel = new Ads_AdKeywordRelation { AdId = ad.AdId, KeywordId = CreateKeyword(key) }; thisAdKeywords.Add(rel.KeywordId); AdsData.Ads_AdKeywordRelations.InsertOnSubmit(rel); } } } var deleteQuery = from relation in AdsData.Ads_AdKeywordRelations where !thisAdKeywords.Contains(relation.KeywordId) && relation.AdId == AdId select relation; AdsData.Ads_AdKeywordRelations.DeleteAllOnSubmit(deleteQuery); AdsData.SubmitChanges(); return(AdId); }