Exemplo n.º 1
0
        public IActionResult BuyAuctionArticle(int aid)
        {
            var userName = User.Identity.Name;

            if (userName == null)
            {
                return(RedirectToAction("Login", "User"));
            }
            var userId = context.Users.Single(u => u.UserName == userName).Id;

            var auction = context.Auctions.Include(a => a.Article).Include(a => a.LastBid)
                          .Include(a => a.User)
                          .Single(a => a.ArticleId == aid);

            if (auction.User.UserName == userName)
            {
                return(RedirectToAction("Index", "Auction")); //Si nadie pujó en la subasta
            }

            var buyViewModel = new BuyAuctionArticleViewModel
            {
                Auction    = auction,
                CustomerId = userId
            };

            return(View(buyViewModel));
        }
Exemplo n.º 2
0
        public IActionResult EffectAuctionBuy(BuyAuctionArticleViewModel bvm)
        {
            var auction = context.Auctions.Include(a => a.Article).Include(a => a.LastBid)
                          .Include(a => a.User)
                          .Single(a => a.UserId == bvm.Auction.UserId && a.ArticleId == bvm.Auction.ArticleId);

            if (!ModelState.IsValid)
            {
                BuyAuctionArticleViewModel newBvw = new BuyAuctionArticleViewModel
                {
                    Auction    = auction,
                    CustomerId = bvm.CustomerId,
                    Address    = bvm.Address
                };
                return(View("BuyAuctionArticle", newBvw));
            }

            var newOrder = new AuctionOrder
            {
                CustomerId     = bvm.CustomerId,
                ArticleId      = bvm.Auction.ArticleId,
                Date           = DateTime.Now,
                Address        = bvm.Address,
                ShippingCharge = bvm.ShippingCharge
            };

            context.AuctionOrders.Add(newOrder);
            context.SaveChanges();

            var totalCharge = auction.CurrentPrice + newOrder.ShippingCharge;

            return(RedirectToAction("GetPaymentMethod", "PaymentGateway",
                                    new
            {
                userId = newOrder.CustomerId,
                articleId = newOrder.ArticleId,
                orderDateTicks = newOrder.Date.Ticks,
                charge = totalCharge,
                orderType = 2
            }));
        }