public Boolean StartAuction() { if (this.state.Equals(KeysUtils.AuctionReady())) { this.state = KeysUtils.AuctionOpened(); this.current_price = this.starting_price; this.opened = DateTime.Now; this.closed = DateTime.Now.AddMilliseconds(this.duration * 1000); return(true); } return(false); }
public void checkAuctionEnd() { if (this.state.Equals(KeysUtils.AuctionOpened())) { if (DateTime.Now > this.closed) { Bid b = Zeka.Models.Bid.LastBidForAuction(this); if (b != null) { b.winner = true; b.saveChanges(); } this.state = KeysUtils.AuctionCompleted(); this.saveChanges(); } } }
public ActionResult StartAuction(Guid key) { User u = (User)Session[KeysUtils.SessionAdmin()]; if (u == null) { return(RedirectToAction("Index", "Home")); } else { Auction auction = Auction.getByKey(key); if (auction != null) { auction.state = KeysUtils.AuctionOpened(); auction.current_price = auction.starting_price; DateTime t = DateTime.Now; auction.opened = t; auction.closed = t.AddSeconds(auction.duration); auction.saveChanges(); } return(RedirectToAction("Index", "Admin")); } }
public Boolean processBid() { object u = SynchronizationUtils.getLockOnUser(this.user_id); Boolean status; lock (u) { status = User.Pay(this.tokens, this.user_id); } if (!status) { return(false); } Bid lastBid = null; object a = SynchronizationUtils.getLockOnAuction(this.auction_id); lock (a) { Auction auction = Auction.getByKey(this.auction_id); if (auction == null || auction.state != KeysUtils.AuctionOpened() || auction.token_price > this.tokens) { status = false; } else { //TODO calculate more stuf? price in currency(cant think right now) auction.token_price = this.tokens; auction.current_price = auction.token_price * auction.tokenValue; auction.saveChanges(); lastBid = Bid.LastBidForAuction(auction); //TODO should remove last bid? this.save(); User thisUser = User.getById(this.user_id); AuctionHub.RefreshPrice(this.auction_id, thisUser.email, this.tokens, auction.currency, auction.current_price); AuctionHub.UpdateBidInsert(this.tokens, this.auction_id, thisUser.email, this.time, auction.current_price, auction.currency); status = true; } } if (status == false) { lock (u) { User.Pay(-this.tokens, this.user_id); } } else { if (lastBid != null) { object uOld = SynchronizationUtils.getLockOnUser(lastBid.user_id); lock (uOld) { User.Pay(-lastBid.tokens, lastBid.user_id); } SynchronizationUtils.returnLockOnUser(lastBid.user_id); } } SynchronizationUtils.returnLockOnUser(this.user_id); SynchronizationUtils.returnLockOnAuction(this.auction_id); return(status); }