public bool IsBannerActive(BannerInfo objBanner) { bool blnValid = true; if (Null.IsNull(objBanner.StartDate) == false && DateTime.Now < objBanner.StartDate) { blnValid = false; } if (blnValid) { switch (objBanner.Criteria) { case 0: if (objBanner.Impressions < objBanner.Views && objBanner.Impressions != 0) { blnValid = false; } break; case 1: if ((objBanner.Impressions < objBanner.Views && objBanner.Impressions != 0) || (DateTime.Now > objBanner.EndDate && Null.IsNull(objBanner.EndDate) == false)) { blnValid = false; } break; } } return(blnValid); }
public ArrayList LoadBanners(int PortalId, int ModuleId, int BannerTypeId, string GroupName, int Banners) { if (GroupName == null) { GroupName = Null.NullString; } string cacheKey = string.Format(DataCache.BannersCacheKey, PortalId, BannerTypeId, GroupName); List <BannerInfo> bannersList = CBO.GetCachedObject <List <BannerInfo> >(new CacheItemArgs(cacheKey, DataCache.BannersCacheTimeOut, DataCache.BannersCachePriority, PortalId, BannerTypeId, GroupName), LoadBannersCallback); ArrayList arReturnBanners = new ArrayList(Banners); if (bannersList.Count > 0) { if (Banners > bannersList.Count) { Banners = bannersList.Count; } int intIndex = new Random().Next(0, bannersList.Count); int intCounter = 1; while (intCounter <= bannersList.Count && arReturnBanners.Count != Banners) { intIndex += 1; if (intIndex > (bannersList.Count - 1)) { intIndex = 0; } BannerInfo objBanner = bannersList[intIndex]; arReturnBanners.Add(objBanner); objBanner.Views += 1; if (Null.IsNull(objBanner.StartDate)) { objBanner.StartDate = DateTime.Now; } if (Null.IsNull(objBanner.EndDate) && objBanner.Views >= objBanner.Impressions && objBanner.Impressions != 0) { objBanner.EndDate = DateTime.Now; } DataProvider.Instance().UpdateBannerViews(objBanner.BannerId, objBanner.StartDate, objBanner.EndDate); if (!IsBannerActive(objBanner)) { DataCache.RemoveCache(cacheKey); } intCounter += 1; } } return(arReturnBanners); }
public void UpdateBanner(BannerInfo objBannerInfo) { DataProvider.Instance().UpdateBanner(objBannerInfo.BannerId, objBannerInfo.BannerName, objBannerInfo.ImageFile, objBannerInfo.URL, objBannerInfo.Impressions, objBannerInfo.CPM, objBannerInfo.StartDate, objBannerInfo.EndDate, objBannerInfo.CreatedByUser, objBannerInfo.BannerTypeId, objBannerInfo.Description, objBannerInfo.GroupName, objBannerInfo.Criteria, objBannerInfo.Width, objBannerInfo.Height); ClearBannerCache(); }