Exemple #1
0
        public async Task <IActionResult> Create([Bind("Id,Hostname,IpAddress,Vendor,Location,Description")] Node node)
        {
            if (ModelState.IsValid)
            {
                _context.Add(node);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(node));
        }
        public async Task <IActionResult> Create([Bind("Id,Name")] ProductCategory productCategory)
        {
            if (ModelState.IsValid)
            {
                productCategory.Name = productCategory.Name.Trim();
                _context.Add(productCategory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(productCategory));
        }
Exemple #3
0
        public async Task <IActionResult> Create(StockLocation stockLocation)
        {
            if (ModelState.IsValid)
            {
                ICollection <Stock> newStocks = new List <Stock>();
                var Products = _context.Products.ToList();
                foreach (var Product in Products)
                {
                    newStocks.Add(new Stock
                    {
                        ProductId = Product.Id,
                        Quantity  = 0
                    });
                }
                stockLocation.Stock = newStocks;
                _context.Add(stockLocation);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(stockLocation));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Description,ProductCategoryId")] Product product)
        {
            if (ModelState.IsValid)
            {
                ICollection <Stock> newStocks = new List <Stock>();
                var StockLocations            = await _context.StockLocation.ToListAsync();

                foreach (var StockLocation in StockLocations)
                {
                    newStocks.Add(new Stock
                    {
                        Quantity        = 0,
                        StockLocationId = StockLocation.Id,
                    });
                }
                product.Stock = newStocks;
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Categories"] = new SelectList(_context.Set <ProductCategory>(), "Id", "Name");
            return(View(product));
        }