예제 #1
0
        public bool MyAdClose(int adId, string closingOptions, HttpServerUtilityBase server)
        {
            // get existing
            try
            {
                ClassifedAdAlias obj = null;
                switch (closingOptions)
                {
                case "Remove":
                    if (PromoManager.IsAdInCart(adId))
                    {
                        PromoManager.RemoveFromShoppingCart(adId);
                    }
                    obj = CurrentDbContext.ClassifiedDB
                          .Include("Poster")
                          .SingleOrDefault(x => x.Id == adId && x.Status != 1 && x.Status != 2 && x.Status != 3);
                    obj.Status       = 3;
                    obj.NeedApproval = true;
                    CurrentDbContext.SaveChanges();
                    break;

                case "Sold":
                    obj = CurrentDbContext.ClassifiedDB
                          .Include("Poster")
                          .SingleOrDefault(x => x.Id == adId && x.Status != 1 && x.Status != 2 && x.Status != 3);
                    if (obj == null && obj.Poster != CurrentUser)
                    {
                        return(false);
                    }
                    obj.Status       = 1;
                    obj.NeedApproval = true;
                    CurrentDbContext.SaveChanges();
                    goto default;

                case "Rented":
                    obj = CurrentDbContext.ClassifiedDB
                          .Include("Poster")
                          .SingleOrDefault(x => x.Id == adId && x.Status != 1 && x.Status != 2 && x.Status != 3);
                    if (obj == null && obj.Poster != CurrentUser)
                    {
                        return(false);
                    }
                    obj.Status       = 2;
                    obj.NeedApproval = true;
                    CurrentDbContext.SaveChanges();
                    goto default;

                default:
                    //LuceneSearch.AddUpdateLuceneIndex(obj);
                    break;
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
예제 #2
0
 private bool SetFeaturedPromotionAd(Trinbago_MVC5.Models.ClassifiedAd ad)
 {
     if (ad.AdPromotion.FeaturedAd != null && !ad.AdPromotion.FeaturedAd.Status && ad.AdPromotion.FeaturedAd.Duration > 0)
     {
         ad.AdPromotion.FeaturedAd.Status = true;
         ad.TimeStamp = DateTime.Now;
         ad.AdPromotion.FeaturedAd.StartDate = DateTime.Now;
         ad.AdPromotion.FeaturedAd.EndDate   = ad.AdPromotion.FeaturedAd.StartDate.Value.AddDays(PromotionStaticInfo.PromotionDuration.DurationRange.SingleOrDefault(x => x.Weeks == ad.AdPromotion.FeaturedAd.Duration).Days);
         ad.ExpiryTimeStamp = ad.TimeStamp.AddMonths(3);
         CurrentDbContext.SaveChanges();
         HangfireManager.ScheduleFeaturedAdExpiry(ad.Id, ad.AdPromotion.FeaturedAd.StartDate.Value, ad.AdPromotion.FeaturedAd.EndDate.Value);
         return(true);
     }
     return(false);
 }
예제 #3
0
        // Close a user posted ad
        public bool AdminCloseAd(int Id, string closingOptions, HttpServerUtilityBase server)
        {
            // get existing
            try
            {
                ClassifiedAdAlias obj = new ClassifiedAdAlias();

                switch (closingOptions)
                {
                case "None":
                    ClassifiedManager.RemoveClassifiedAd(Id);
                    break;

                case "Sold":
                    obj = CurrentDbContext.ClassifiedDB.Include("Poster").Include("Category").Include("SubCategory").SingleOrDefault(x => x.Id == Id && x.Status != 1 && x.Status != 2);
                    if (obj == null)
                    {
                        return(false);
                    }
                    obj.Status          = 1;
                    obj.ExpiryTimeStamp = DateTime.Now.AddDays(30);
                    CurrentDbContext.SaveChanges();
                    goto default;

                case "Rented":
                    obj = CurrentDbContext.ClassifiedDB.Include("Poster").Include("Category").Include("SubCategory").SingleOrDefault(x => x.Id == Id && x.Status != 1 && x.Status != 2);
                    if (obj == null)
                    {
                        return(false);
                    }
                    obj.Status          = 2;
                    obj.ExpiryTimeStamp = DateTime.Now.AddDays(30);
                    CurrentDbContext.SaveChanges();
                    goto default;

                default:
                    LuceneSearch.ClearLuceneIndexRecord(obj.Id);
                    LuceneSearch.AddUpdateLuceneIndex(obj);
                    break;
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
 internal static void AddUpdateLuceneIndex(ClassifiedAd sampleData)
 {
     AddUpdateLuceneIndex(new List <ClassifiedAd> {
         sampleData
     });
 }
        // Add to index
        internal static void _addToLuceneIndex(ClassifiedAd data, IndexWriter writer)
        {
            // remove older index entry
            var searchQuery = new TermQuery(new Term("Id", data.Id.ToString()));

            writer.DeleteDocuments(searchQuery);

            // add new index entry
            var doc = new Document();

            // add lucene fields mapped to db fields
            doc.Add(new Field("Id", data.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("StringId", data.StringId, Field.Store.YES, Field.Index.NOT_ANALYZED));
            // AdInfo
            foreach (var ai in data.AdInfo)
            {
                if (!String.IsNullOrEmpty(ai.Description))
                {
                    if (ai.Name.Equals("Mileage"))
                    {
                        var mil = new NumericField("Mileage", Field.Store.YES, true);
                        mil.SetIntValue(ai.IntDescription);
                        doc.Add(mil);
                    }
                    else if (ai.Name.Equals("Year"))
                    {
                        var yr = new NumericField("Year", Field.Store.YES, true);
                        yr.SetIntValue(ai.IntDescription);
                        doc.Add(yr);
                    }
                    else if (ai.Name.Equals("Size"))
                    {
                        var size = new NumericField("Size", Field.Store.YES, true);
                        size.SetIntValue(ai.IntDescription);
                        doc.Add(size);
                    }
                    else
                    {
                        doc.Add(new Field(ai.Name, ai.Description, Field.Store.YES, Field.Index.NOT_ANALYZED));
                    }
                }
            }
            // Photo
            if (data.AdPhotos != null)
            {
                if (data.AdPhotos.Count > 0)
                {
                    doc.Add(new Field("AdPhoto", data.AdPhotos.SingleOrDefault(x => x.SetThumbnail == true).FileName, Field.Store.YES, Field.Index.NOT_ANALYZED));
                }
            }
            // Default
            // Title
            doc.Add(new Field("Title", data.Title, Field.Store.YES, Field.Index.ANALYZED));
            // Descripton
            var hfd = HttpUtility.HtmlDecode(data.HtmlFreeDescription);

            doc.Add(new Field("HtmlFreeDescription", hfd, Field.Store.YES, Field.Index.ANALYZED));

            // Price
            var price = new NumericField("Price", Field.Store.YES, true);

            price.SetIntValue(data.Price);
            doc.Add(price);
            // Price Info
            doc.Add(new Field("PriceInfo", data.PriceInfo, Field.Store.YES, Field.Index.NOT_ANALYZED));
            // Status
            doc.Add(new Field("Status", data.Status.ToString(), Field.Store.YES, Field.Index.ANALYZED));
            // Ad Type
            doc.Add(new Field("AdType", data.AdType, Field.Store.YES, Field.Index.NOT_ANALYZED));
            // Featured Status
            doc.Add(new Field("FeaturedAdStatus", data.FeaturedAdStatus.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            // Top Ad Status
            doc.Add(new Field("TopAdStatus", data.TopAdStatus.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            // Urgent Ad Status
            doc.Add(new Field("UrgentAdStatus", data.UrgentAdStatus.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));

            // Category
            doc.Add(new Field("CategoryId", data.Category.Id.ToString(), Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("CategoryName", data.Category.Name, Field.Store.YES, Field.Index.ANALYZED));
            // SubCategory
            doc.Add(new Field("SubCategoryStringId", data.SubCategory.stringId, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("SubCategoryName", data.SubCategory.Name, Field.Store.YES, Field.Index.ANALYZED));
            // Time
            doc.Add(new Field("TimeStamp", data.TimeStamp.ToShortDateString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            // Time Tick
            var tick = new NumericField("EditTimeStampTicks", Field.Store.YES, true);

            tick.SetLongValue(data.EditTimeStamp.Ticks);
            doc.Add(tick);
            doc.Add(new Field("EditTimeStamp", data.EditTimeStamp.ToShortDateString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            // Location
            doc.Add(new Field("CountryId", data.Country.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("CountryName", data.Country.Name, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("RegionId", data.Region.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("RegionName", data.Region.Name, Field.Store.YES, Field.Index.ANALYZED));

            // add entry to index
            writer.AddDocument(doc);
        }