Пример #1
0
        public async Task <IActionResult> Create([Bind("ID,userID,firstName,lastName,address1,address2,city,state,zip,email,productID,productName,datePurchased,shipDate,stowLocation")] PurchaseOrder purchaseOrder)
        {
            if (ModelState.IsValid)
            {
                _context.Add(purchaseOrder);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(purchaseOrder));
        }
        public async Task <IActionResult> AddOrEdit([Bind("Id,Name,Address,Email")] Supplier supplier)
        {
            if (ModelState.IsValid)
            {
                _ = supplier.Id == 0 ? _context.Add(supplier) : _context.Update(supplier);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(supplier));
        }
        public async Task <IActionResult> AddProducts([Bind("Name,Description,Price")] Product product)
        {
            product.Supplier_id = Int32.Parse(Request.Form["Supplier_identity"]);

            if (ModelState.IsValid)
            {
                _context.Add(product);
                string url = $"AddProducts/{product.Supplier_id}";
                await _context.SaveChangesAsync();

                return(Redirect(url));
            }
            return(View());
        }
        public async Task <IActionResult> PurchaseOrder(int id, ProductListModel model)
        {
            PurchaseOrdersNumbers purchaseOrdersNumbers = new PurchaseOrdersNumbers();
            PurchaseOrderNumber   OrderNumber           = new PurchaseOrderNumber();
            PurchaseOrderTax      purchaseOrderTax      = new PurchaseOrderTax();

            purchaseOrdersNumbers.OrderNumber = OrderNumber.GetPurchaseOrderNumber();
            purchaseOrdersNumbers.Supplier_id = id;
            purchaseOrderTax.OrderNumber      = purchaseOrdersNumbers.OrderNumber;
            var TaxPercentage = _context.Taxs.FirstOrDefault();

            purchaseOrderTax.Tax = TaxPercentage.TaxPercentage;
            List <Product> SelectedProducts = model.ProductList.Where(x => x.Quantity != 0).ToList <Product>();

            foreach (Product products in SelectedProducts)
            {
                _contextnew.Add(products);
                products.OrderNumber = purchaseOrdersNumbers.OrderNumber;
            }
            _context.Add(purchaseOrdersNumbers);
            _context.Add(purchaseOrderTax);
            if (SelectedProducts.Count() > 0)
            {
                await _contextnew.SaveChangesAsync();

                await _context.SaveChangesAsync();
            }
            else
            {
                TempData["ErrMsg"] = true;
                return(View(model));
            }
            string url = $"../ViewPurchaseOrder/{purchaseOrdersNumbers.OrderNumber}";

            return(Redirect(url));
        }