Example #1
0
        /// <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);
        }
Example #2
0
        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);
        }
Example #3
0
        /// <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);
        }
Example #4
0
        /// <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);
        }