コード例 #1
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);
            }
        }
コード例 #2
0
        /// <summary>
        /// Ends the auction.
        /// </summary>
        /// <param name="person">The person.</param>
        /// <param name="auction">The auction.</param>
        public void EndAuction(Person person, Auction auction)
        {
            IAuctionTable       auctionTable       = this.tablesProvider.GetAuctionTable();
            IPersonOfferorTable personOfferorTable = this.tablesProvider.GetPersonOfferorTable();

            try
            {
                PersonOfferor  offeror        = personOfferorTable.FetchPersonOfferorByPerson(person);
                AuctionService auctionService = new AuctionService(auction);

                auctionService.EndAuction(offeror);

                auctionTable.UpdateAuction(auctionService.Auction);
                Log.Info("auction ended!");
            }
            catch (Exception e)
            {
                Log.Info("EndAuction :" + e.Message);
                throw e;
            }
        }
コード例 #3
0
        /// <summary>
        /// Registers the auction.
        /// </summary>
        /// <param name="person">The person.</param>
        /// <param name="auction">The auction.</param>
        /// <returns>
        /// False if the register auction has failed.
        /// </returns>
        /// <exception cref="System.Exception">Person is not registered!</exception>
        public Auction RegisterAuction(Person person, Auction auction)
        {
            IPersonOfferorTable personOfferorTable = this.tablesProvider.GetPersonOfferorTable();
            IProductTable       productTable       = this.tablesProvider.GetProductTable();
            IAuctionTable       auctionTable       = this.tablesProvider.GetAuctionTable();

            PersonOfferor offeror = personOfferorTable.FetchPersonOfferorByPerson(person);

            offeror.Person = person;
            Currency currency = auction.Currency;
            Category category = auction.Product.Category;

            try
            {
                auction.PersonOfferor = offeror ?? throw new Exception("BAD OFFEROR");

                auction.ValidateObject();

                auction.Currency.ValidateObject();
                auction.Product.ValidateObject();

                if (auction.Currency.IdCurrency == 0)
                {
                    throw new Exception("Invalid currency.");
                }

                Product product = productTable.FetchProductByAllAttributes(auction.Product.Category.IdCategory, auction.Product);
                if (product != null)
                {
                    product.Category = category;

                    Auction fetched = auctionTable.FetchAuctionByIds(offeror.IdOfferor, product.IdProduct);

                    if (fetched.IdAuction != 0)
                    {
                        fetched.PersonOfferor = offeror;
                        fetched.Product       = product;
                        fetched.Currency      = currency;

                        return(fetched);
                        ////throw new Exception("Auction is already registered");
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            List <Auction> offerorAuctions  = auctionTable.FetchOfferorAuctions(offeror);
            List <Product> existingProducts = productTable.FetchAllProducts();

            bool canPost = CanAuctionBePostedCheck.DoCheck(offeror, auction, offerorAuctions, existingProducts);

            if (!canPost)
            {
                throw new Exception("CanAuctionBePostedCheck failed!");
            }

            productTable.InsertProduct(category.IdCategory, auction.Product);

            Product selectedProduct = productTable.FetchProductByAllAttributes(category.IdCategory, auction.Product);

            selectedProduct.Category = category;

            auctionTable.InsertAuction(offeror.IdOfferor, selectedProduct.IdProduct, currency.IdCurrency, auction);

            auction = auctionTable.FetchAuctionByIds(offeror.IdOfferor, selectedProduct.IdProduct);
            auction.PersonOfferor = offeror;
            auction.Product       = selectedProduct;
            auction.Currency      = currency;

            this.auctions.Add(auction);

            AuctionService auctionService = new AuctionService(auction);

            auctionService.StartTimers();

            return(auction);
        }