Ejemplo n.º 1
0
 public ActionResult Edit([Bind(Include = "SID,Name")] Seller seller)
 {
     if (ModelState.IsValid)
     {
         db.Entry(seller).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(seller));
 }
Ejemplo n.º 2
0
 public ActionResult Edit([Bind(Include = "IID,Name,Description,Seller")] Item item)
 {
     if (ModelState.IsValid)
     {
         db.Entry(item).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Seller = new SelectList(db.Seller, "SID", "Name", item.Seller);
     return(View(item));
 }
Ejemplo n.º 3
0
        public async Task <JsonResult> Bid(int?id, byte[] rowVersion)
        {
            if (id == null)
            {
                return(Json(false));
            }


            var auctionToUpdate = await _context.auctions.Include(a => a.winner).Include(a => a.owner).FirstOrDefaultAsync(a => a.Id == id);

            if (auctionToUpdate == null)
            {
                return(Json(false));
            }

            _context.Entry(auctionToUpdate).Property("RowVersion").OriginalValue = rowVersion;

            if (await TryUpdateModelAsync <Auction>(auctionToUpdate, "", a => a.currentPrice))
            {
                try{
                    User loggedUser = await this._userManager.GetUserAsync(base.User);

                    if (loggedUser.tokens <= 0)
                    {
                        return(Json("ERROR"));
                    }

                    auctionToUpdate.currentPrice += incCurrentPrice;
                    auctionToUpdate.winner        = loggedUser;
                    auctionToUpdate.winnerId      = loggedUser.Id;

                    Bid bid = new Bid()
                    {
                        price     = auctionToUpdate.currentPrice,
                        bidDate   = DateTime.Now,
                        user      = loggedUser,
                        userId    = loggedUser.Id,
                        auctionId = auctionToUpdate.Id
                    };

                    _context.Add(bid);

                    loggedUser.tokens -= 1;

                    await _context.SaveChangesAsync();

                    auctionToUpdate = await _context.auctions.Include(a => a.winner).Include(a => a.bids).FirstOrDefaultAsync(a => a.Id == id);

                    UpdatedAuction resultAuction = new UpdatedAuction()
                    {
                        currentPrice   = auctionToUpdate.currentPrice,
                        RowVersion     = auctionToUpdate.RowVersion,
                        winnerUsername = auctionToUpdate.winner.UserName,
                        numberOfBids   = auctionToUpdate.bids.Count()
                    };

                    return(Json(resultAuction));
                }
                catch (DbUpdateConcurrencyException ex) {
                    return(Json(ex));
                }
            }


            return(Json(false));
        }