/// <summary> /// Loads the auctions. /// </summary> private void LoadAuctions() { IAuctionTable auctionTable = this.tablesProvider.GetAuctionTable(); List <Auction> auctions = auctionTable.FetchAllAuctions(); if (auctions != null) { this.auctions = auctions; } Log.Info("auctions loaded!"); }
/// <summary> /// Prevents a default instance of the <see cref="DomainDataStorage"/> class from being created. /// </summary> private DomainDataStorage() { string connectionString = ConfigurationManager.ConnectionStrings["MySQL"].ConnectionString; this.databaseConneection = new MySqlConnection(connectionString); this.auctionTable = this.databaseConneection.As <IAuctionTable>(); this.bidTable = this.databaseConneection.As <IBidTable>(); this.categoryTable = this.databaseConneection.As <ICategoryTable>(); this.currencyTable = this.databaseConneection.As <ICurrencyTable>(); this.personBidderTable = this.databaseConneection.As <IPersonBidderTable>(); this.personMarkTable = this.databaseConneection.As <IPersonMarkTable>(); this.personOfferorTable = this.databaseConneection.As <IPersonOfferorTable>(); this.personTable = this.databaseConneection.As <IPersonTable>(); this.productTable = this.databaseConneection.As <IProductTable>(); }
/// <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; } }
/// <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); }