Ejemplo n.º 1
0
        public async Task <IActionResult> CustomBid(CustomBidViewModel cb)
        {
            if (!ModelState.IsValid)
            {
                return(NotFound());
            }

            var claimsIdentity = (ClaimsIdentity)this.User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            var a_user = await _db.AuctionUser.FirstOrDefaultAsync(a => a.UserId == claim.Value && a.AuctionId == cb.AuctionId);

            var auction = await _db.AuctionHeader.FirstOrDefaultAsync(a => a.Id == cb.AuctionId);

            a_user.LastPriceOffered = cb.CustomBid;

            if (auction.CurrentPrice < a_user.LastPriceOffered)
            {
                var outbided_user = await _db.AuctionUser.FirstOrDefaultAsync(a => a.AuctionId == auction.Id && a.LastPriceOffered == auction.CurrentPrice);

                if (outbided_user.UserId != claim.Value)
                {
                    await NotiApi.SendNotiAuction(_db, "You got outbided, check the auction for more details", outbided_user.UserId, auction.Id);
                }

                await NotiApi.SendNotiAuction(_db, "You bid for $" + a_user.LastPriceOffered.ToString("F2") + " in an auction, check the auction for more details", a_user.UserId, auction.Id);

                auction.CurrentPrice = Math.Max(auction.CurrentPrice, a_user.LastPriceOffered);
            }


            _db.SaveChanges();

            return(RedirectToAction("Details", new { id = cb.AuctionId, status = SD.ActiveStatus, callBack = SD.BidedAuctions }));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> CustomBid(int id) //get
        {
            var auction = await _db.AuctionHeader.FirstOrDefaultAsync(a => a.Id == id);

            var vm = new CustomBidViewModel()
            {
                AuctionId    = auction.Id,
                PriceStep    = auction.PriceStep,
                CurrentPrice = auction.CurrentPrice,
                CustomBid    = auction.CurrentPrice + auction.PriceStep
            };

            return(PartialView(vm));
        }