コード例 #1
0
        public async Task <ActionResult> VerifyBidder(string key, AuctionAppModel model)
        {
            var auction = await _auctionContext.GetByKeyAsync(key);

            if (null == auction)
            {
                return(this.NotFound($"{key} not found!"));
            }
            if (!this.IsBidder(model.BidderEmail, model.BidderCode, auction.Bidders))
            {
                return(this.Forbidden($"{model.BidderEmail} not verified!"));
            }

            var bidderNickname = this.GetBidder(model.BidderEmail, model.BidderCode, auction.Bidders).Nickname;

            dynamic jObject = new JObject();

            jObject.Key      = key;
            jObject.Auth     = true;
            jObject.Nickname = bidderNickname;
            return(this.Ok((string)JsonConvert.SerializeObject(jObject).ToString()));
        }
コード例 #2
0
        public async Task <ActionResult> PerformBid(string key, AuctionAppModel model)
        {
            var auction = await _auctionContext.GetByKeyAsync(key);

            if (null == auction)
            {
                return(this.NotFound($"{key} not found!"));
            }
            if (!this.IsBidder(model.BidderEmail, model.BidderCode, auction.Bidders))
            {
                return(this.Forbidden($"{model.BidderEmail} not verified!"));
            }
            if (model.BidderEmail == auction.Bidder.Email && model.BidderCode == auction.Bidder.Code)
            {
                return(this.BadRequest($"Invalid bid: {auction.Bidder.Email} is higest bidder!"));
            }
            if (auction.Status != "Started")
            {
                return(this.BadRequest($"Invalid status: {auction.Status}!"));
            }
            if (auction.Call > 3)
            {
                return(this.BadRequest($"Invalid call: {auction.Call}!"));
            }
            if (model.BidAmount <= auction.Amount)
            {
                return(this.BadRequest($"Invalid amount: {auction.Amount}!"));
            }

            this.BidTheAuction(model, auction);
            this.CallTheAuction(auction);

            var result = await _auctionContext.PutAsync(auction, key);

            return(null != result
                ? this.Ok(JsonConvert.SerializeObject(new FirebaseObject <Auction>(key, auction)))
                : this.InternalServerError(string.Empty));
        }