コード例 #1
0
ファイル: AuctionController.cs プロジェクト: Gu4ty/ISProject
        public async Task <IActionResult> Select(IList <ProductsAuctionViewModel> prodAuctionList)
        {
            if (ModelState.IsValid)
            {
                var newProdList = new List <ProductsAuctionViewModel>();
                foreach (var item in prodAuctionList)
                {
                    if (item.Quantity > 0)
                    {
                        if (item.Quantity > item.ProductSale.Units)
                        {
                            item.Quantity = item.ProductSale.Units;
                        }
                        var product = await _db.ProductSale.Include(p => p.Product).Include(p => p.Seller)
                                      .Where(p => p.Id == item.ProductSale.Id)
                                      .FirstOrDefaultAsync();

                        var prod = new ProductsAuctionViewModel()
                        {
                            ProductSale = product,
                            Quantity    = item.Quantity
                        };
                        newProdList.Add(prod);
                    }
                }

                TempData["selectedProducts"] = JsonConvert.SerializeObject(newProdList);
                return(RedirectToAction(nameof(Create)));
            }

            foreach (var modelState in ViewData.ModelState.Values)
            {
                foreach (ModelError error in modelState.Errors)
                {
                    Console.WriteLine(error.ErrorMessage);
                }
            }

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

            var products = await _db.ProductSale.Include(p => p.Product).Include(p => p.Seller)
                           .Where(p => p.SellerId == claim.Value && p.Units > 0)
                           .ToListAsync();

            List <ProductsAuctionViewModel> newprodAuctionList = new List <ProductsAuctionViewModel>();

            foreach (var prod in products)
            {
                var prodAuction = new ProductsAuctionViewModel()
                {
                    ProductSale = prod,
                    Quantity    = 0
                };
                newprodAuctionList.Add(prodAuction);
            }

            return(View(newprodAuctionList));
        }
コード例 #2
0
ファイル: AuctionController.cs プロジェクト: Gu4ty/ISProject
        public async Task <IActionResult> Select()
        {
            var claimsIdentity = (ClaimsIdentity)this.User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            var products = await _db.ProductSale.Include(p => p.Product).Include(p => p.Seller)
                           .Where(p => p.SellerId == claim.Value && p.Units > 0)
                           .ToListAsync();

            List <ProductsAuctionViewModel> prodAuctionList = new List <ProductsAuctionViewModel>();

            foreach (var prod in products)
            {
                var prodAuction = new ProductsAuctionViewModel()
                {
                    ProductSale = prod,
                    Quantity    = 0
                };
                prodAuctionList.Add(prodAuction);
            }

            return(View(prodAuctionList));
        }