Exemplo n.º 1
0
        public async Task <IActionResult> Create(InventoryViewModel inventoryView)
        {
            if (ModelState.IsValid)
            {
                var EmployeeId  = _context.Employees.Where(e => e.Name == inventoryView.Employee).Select(e => e.EmployeeId).FirstOrDefault();
                var StockId     = _context.Stocks.Where(s => s.StockName == inventoryView.StockName).Select(s => s.Id).FirstOrDefault();
                var WarehouseId = _context.Warehouses.Where(w => w.Location == inventoryView.Location).Select(w => w.Id).FirstOrDefault();

                Inventory addinventory = new Inventory()
                {
                    DateRecieved = inventoryView.DateRecieved,
                    EmployeeId   = EmployeeId,
                    StockId      = StockId,
                    Units        = inventoryView.Unit,
                    WarehouseId  = WarehouseId
                };
                _context.Add(addinventory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            ViewData["Employee"]  = new SelectList(_context.Employees, "Name", "Name", inventoryView.Employee);
            ViewData["StockName"] = new SelectList(_context.Stocks, "StockName", "StockName", inventoryView.StockName);
            ViewData["Location"]  = new SelectList(_context.Warehouses, "Location", "Location", inventoryView.Location);

            return(View(inventoryView));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,StockName")] Stock stock)
        {
            if (ModelState.IsValid)
            {
                _context.Add(stock);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(stock));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("EmployeeId,Name")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                _context.Add(employee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(employee));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("Id,Location")] Warehouse warehouse)
        {
            if (ModelState.IsValid)
            {
                _context.Add(warehouse);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(warehouse));
        }