public IActionResult Edited(int Id, string Name, string Lot, int LocationSelectedId, int ManufacturerSelectedId, double Quantity, string Units)
        {
            InventoryItem inventoryItem = new InventoryItem();

            if (Id != 0)
            {
                inventoryItem = _context.InventoryItems.Where(i => i.Id == Id).SingleOrDefault();
            }
            inventoryItem.Name         = Name.ToUpper();
            inventoryItem.Lot          = Lot.ToUpper();
            inventoryItem.Quantity     = Quantity;
            inventoryItem.Units        = Units.ToUpper();
            inventoryItem.Location     = _context.Locations.Where(c => c.Id == LocationSelectedId).SingleOrDefault();
            inventoryItem.Manufacturer = _context.Manufacturers.Where(c => c.Id == ManufacturerSelectedId).SingleOrDefault();

            if (ModelState.IsValid && Id == 0)
            {
                _context.Add(inventoryItem);
                _context.SaveChanges();
            }
            else if (ModelState.IsValid && Id != 0)
            {
                _context.Update(inventoryItem);
                _context.SaveChanges();
            }
            else
            {
                return(View(new NotFoundResult()));
            }



            return(RedirectToAction("Index"));
        }
예제 #2
0
        public IActionResult Create(Product product)
        {
            _context.Add(product);
            _context.SaveChanges();

            ViewBag.Categories = _context.Categories.ToList();
            return(RedirectToAction("GetAll"));
        }
        public async Task <int> CreateProduct(Product product)
        {
            // Add Product
            product.CreatedOn = DateTime.Now;
            _context.Add(product);

            // Add 0 stock
            var stock = new Stock {
                Quantity = 0, Product = product
            };

            _context.Add(stock);

            await _context.SaveChangesAsync();

            return(product.Id);
        }
 public IActionResult Create(Category category)
 {
     if (ModelState.IsValid)
     {
         _context.Add(category);
         _context.SaveChanges();
     }
     return(RedirectToAction("GetAll"));
 }
예제 #5
0
        public async Task <IActionResult> Create([Bind("ProductId,Description,QtyOnHand,ReorderPoint,Status,Cost,Price")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
예제 #6
0
        public async Task <IActionResult> Create([Bind("VendorId,Name,Status,Phone,Email")] Vendor vendor)
        {
            if (ModelState.IsValid)
            {
                _context.Add(vendor);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(vendor));
        }
예제 #7
0
        public async Task <IActionResult> Create([Bind("Id,Name")] RoastModel roastModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(roastModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(roastModel));
        }
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Username,Password,ConfirmPassword,Role,BranchId")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BranchId"] = new SelectList(_context.Branches, "BranchId", "BranchId", user.BranchId);
            return(View(user));
        }
        public async Task <IActionResult> Create([Bind("ID, ProductID, StaffID, RequestedQuantity, ApprovalStatus")] StockRequest stockRequest)
        {
            if (ModelState.IsValid)
            {
                stockRequest.ProductID = 1;
                stockRequest.StaffID   = 1;
                _context.Add(stockRequest);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(stockRequest));
        }
예제 #10
0
        public async Task <ActionResult> Create(VendorModel newVendor)
        {
            try
            {
                _context.Add(newVendor);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
 public async Task <IActionResult> Edited(Manufacturer manufacturer)
 {
     if (manufacturer.Id == 0)
     {
         _context.Add(manufacturer);
         await _context.SaveChangesAsync();
     }
     else
     {
         _context.Update(manufacturer);
         await _context.SaveChangesAsync();
     }
     return(RedirectToAction("Index"));
 }
        public Task CreateStock(Stock stock)
        {
            // Update the product Current quantity
            var product = _context.Product.Single(p => p.Id == stock.ProductId);

            product.CurrentQuantity = stock.Quantity;
            product.LastUpdatedOn   = DateTime.Now;
            _context.Update(product);

            // Add Stock
            stock.CreatedOn = DateTime.Now;
            _context.Add(stock);
            return(_context.SaveChangesAsync());
        }
        public async Task <IActionResult> Create([Bind("Item")] CoffeeViewModel cvm)
        {
            if (ModelState.IsValid)
            {
                CountryModel newCountry = _context.Countries.FirstOrDefault(c => c.Name == cvm.Item.Country.Name) ?? new CountryModel(null, cvm.Item.Country.Name);
                if (newCountry.Id == null)
                {
                    _context.Add(newCountry);
                }
                VarietyModel newVariety = _context.Varieties.FirstOrDefault(v => v.Name == cvm.Item.Variety.Name) ?? new VarietyModel(null, cvm.Item.Variety.Name);
                if (newVariety.Id == null)
                {
                    _context.Add(newVariety);
                }
                cvm.Item.Country = newCountry;
                cvm.Item.Variety = newVariety;
                _context.Add(cvm.Item);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(cvm));
        }
        public async Task <IActionResult> Edited(Location location)
        {
            location.LocationName = location.LocationName.ToUpper();
            if (location.Id != 0)
            {
                _context.Update(location);
            }
            else
            {
                _context.Add(location);
            }
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public ApiResponse <IEnumerable <InventoryItem> > AddUpdate([FromBody] InventoryItem item)
        {
            item.LastUpdated = DateTime.Now;
            var existing = _context.Find <InventoryItem>(new object[] { item.ProductId });

            if (existing == null)
            {
                _context.Add(item);
            }
            else
            {
                existing.Quantity = item.Quantity;
            }
            _context.SaveChanges();
            return(GetAll());
        }
예제 #16
0
        public async Task <IActionResult> Create(InventoryViewModel ivm)
        {
            if (ModelState.IsValid)
            {
                InventoryModel newItem = new InventoryModel
                {
                    Coffee      = _context.Coffees.Find(ivm.CoffeeId),
                    Vendor      = _context.Vendors.Find(ivm.VendorId),
                    Roast       = _context.Roasts.Find(ivm.RoastId),
                    PricePerLbs = ivm.PricePerLbs,
                    LbsOnHand   = ivm.LbsOnHand
                };

                _context.Add(newItem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(ivm));
        }
예제 #17
0
 public void Add(Basket basket) => _context.Add(basket);
        public void Create(T entity)
        {
            _context.Add(entity);

            Save();;
        }