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"));
        }
Esempio n. 2
0
        public async Task <IActionResult> Edit(int id, [Bind("ProductId,Description,QtyOnHand,ReorderPoint,Status,Cost,Price")] Product product)
        {
            if (id != product.ProductId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(product);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductExists(product.ProductId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
Esempio n. 3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] RoastModel roastModel)
        {
            if (id != roastModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(roastModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RoastModelExists(roastModel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(roastModel));
        }
        public async Task <IActionResult> Edit(int id, [Bind("RequestedQuantity, ApprovalStatus, ID, ProductID, StaffID")] StockRequest stockRequest)
        {
            if (id != stockRequest.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(stockRequest);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StockRequestExists(stockRequest.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(stockRequest));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,FirstName,LastName,Username,Password,ConfirmPassword,Role,BranchId")] User user)
        {
            if (id != user.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(user);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(user.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BranchId"] = new SelectList(_context.Branches, "BranchId", "BranchId", user.BranchId);
            return(View(user));
        }
Esempio n. 6
0
        public async Task <IActionResult> Edit(int id, [Bind("VendorId,Name,Status,Phone,Email")] Vendor vendor)
        {
            if (id != vendor.VendorId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(vendor);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VendorExists(vendor.VendorId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(vendor));
        }
 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> 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"));
        }
Esempio n. 10
0
        public DTOs.Order UpdateOrder(DTOs.Order order)
        {
            var entityOrder = InventoryDbContext.Orders.SingleOrDefault(existingOrder => existingOrder.Id == order.Id);

            if (entityOrder == null)
            {
                return(null);
            }

            entityOrder.Name             = order.Name;
            entityOrder.DateLastModified = DateTime.Now;

            var updatedOrder = InventoryDbContext.Update(entityOrder).Entity;

            InventoryDbContext.SaveChanges();

            return(Mapper.Map <DTOs.Order>(updatedOrder));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Item")] CoffeeViewModel cvm)
        {
            if (id != cvm.Item.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    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.Update(cvm.Item);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CoffeeModelExists(cvm.Item.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(cvm));
        }
Esempio n. 12
0
        public async Task <IActionResult> Edit(int id, [Bind("ItemId,CoffeeId,VendorId,RoastId,PricePerLbs,LbsOnHand")] InventoryViewModel ivm)
        {
            if (id != ivm.ItemId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var updated = new InventoryModel
                    {
                        Id          = ivm.ItemId,
                        Coffee      = _context.Coffees.Find(ivm.CoffeeId),
                        Vendor      = _context.Vendors.Find(ivm.VendorId),
                        Roast       = _context.Roasts.Find(ivm.RoastId),
                        LbsOnHand   = ivm.LbsOnHand,
                        PricePerLbs = ivm.PricePerLbs
                    };
                    _context.Update(updated);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!InventoryModelExists(id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(ivm));
        }
Esempio n. 13
0
 public void Update(Basket basket) => _context.Update(basket);
 public Task UpdateProduct(Product product)
 {
     product.LastUpdatedOn = DateTime.Now;
     _context.Update(product);
     return(_context.SaveChangesAsync());
 }