예제 #1
0
        /// <summary>
        /// Does the check.
        /// </summary>
        /// <param name="personOfferor">The person offer.</param>
        /// <param name="auction">The auction.</param>
        /// <param name="offerorAuctions">The offer person auctions.</param>
        /// <param name="allProducts">All products.</param>
        /// <returns>
        /// true if the auction can be posted.
        /// </returns>
        public static bool DoCheck(PersonOfferor personOfferor, Auction auction, List <Auction> offerorAuctions, List <Product> allProducts)
        {
            PersonOfferorService offerorService = new PersonOfferorService(personOfferor);

            //// if it's banned.
            if (offerorService.IsBanned)
            {
                return(false);
            }

            //// can't have more than this.
            bool hasMaxAuctions = offerorService.DidPersonHitMaxListLimit(personOfferor, offerorAuctions);

            if (hasMaxAuctions)
            {
                return(false);
            }

            //// can't have more than this in specified category.
            List <Auction> offerorCategoryAuctions = new List <Auction>();

            foreach (Auction listed_auction in offerorAuctions)
            {
                if (listed_auction.Product.Category.Name.Equals(auction.Product.Category.Name))
                {
                    offerorCategoryAuctions.Add(listed_auction);
                }
            }

            bool hasMaxInCategory = offerorService.DidPersonHitMaxCategoryListLimit(personOfferor, auction.Product.Category, offerorCategoryAuctions);

            if (hasMaxInCategory)
            {
                return(false);
            }

            AuctionService auctionService = new AuctionService(auction);

            //// if it's older
            if (DateTime.Now.CompareTo(auction.StartDate) > 0)
            {
                //// it should not be older than 5 min.
                bool olderThanMinutes = (DateTime.Now - auction.StartDate).TotalMinutes > 5;
                if (olderThanMinutes)
                {
                    ////return false;
                }
            }

            bool anySimilarExists = ExistsAnySimilarProductCheck.DoCheck(auction.Product, allProducts);

            //// should not be similar.
            if (anySimilarExists)
            {
                Log.Info(auction.Product.Name + " already exists due to LevensteinDistance!");
                return(false);
            }

            return(true);
        }
예제 #2
0
        /// <summary>
        /// Posts the mark.
        /// </summary>
        /// <param name="fromPerson">From person.</param>
        /// <param name="toPerson">To person.</param>
        /// <param name="mark">The mark.</param>
        /// <exception cref="System.Exception">A PERSON IS NOT REGISTERED!</exception>
        public void PostMark(Person fromPerson, Person toPerson, int mark)
        {
            IPersonOfferorTable personOfferorTable = this.tablesProvider.GetPersonOfferorTable();
            IPersonMarkTable    personMarkTable    = this.tablesProvider.GetPersonMarkTable();

            fromPerson.ValidateObject();
            toPerson.ValidateObject();

            if (fromPerson.IdPerson == 0 || toPerson.IdPerson == 0)
            {
                throw new Exception("A PERSON IS NOT REGISTERED!");
            }

            PersonOfferor offeror = personOfferorTable.FetchPersonOfferorByPerson(toPerson);

            if (mark > MaxMarkRating || mark < MinMarkRating)
            {
                throw new Exception("BadRating");
            }

            PersonOfferorMark markObj = new PersonOfferorMark()
            {
                DateOccur = DateTime.Now, Mark = mark, Receiver = offeror, Sender = fromPerson
            };

            personMarkTable.InsertPersonMark(markObj);

            Log.Info("mark registered!");

            PersonOfferorService offerorService = new PersonOfferorService(offeror);

            List <PersonOfferorMark> marks = personMarkTable.FetchPersonOfferorMarks(offeror);

            offerorService.UpdateRatingBasedOnMarks(marks);

            if (offerorService.Rating < minRatingAllowedForBidding)
            {
                offeror.LastBannedDate = DateTime.Now;
                offerorService.UpdateIsBanned();
                personOfferorTable.UpdatePersonOfferor(offeror);
            }
        }