Ejemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("ID,InventoryItemId,DailySalesId,PaymentMethodId,Quantity")] DailySalesEntry dailySalesEntry)
        {
            if (ModelState.IsValid)
            {
                var itemDetails = _context.InventoryItem
                                  .Where(x => x.ID == dailySalesEntry.InventoryItemId)
                                  .First();

                var currentStockQty = itemDetails.StockQty;

                if (dailySalesEntry.Quantity > currentStockQty)
                {
                    //Add error message and add to span element
                    return(RedirectToAction("Index", new { id = dailySalesEntry.DailySalesId }));
                }

                itemDetails.StockQty -= dailySalesEntry.Quantity;

                dailySalesEntry.ItemPriceCOP = itemDetails.PriceCOP;
                dailySalesEntry.AmountCOP    = dailySalesEntry.Quantity * itemDetails.PriceCOP;

                dailySalesEntry.ItemPriceUSD = itemDetails.PriceUSD;
                dailySalesEntry.AmountUSD    = dailySalesEntry.Quantity * itemDetails.PriceUSD;

                _context.Add(dailySalesEntry);
                await _context.SaveChangesAsync();
            }

            return(RedirectToAction("Index", new { id = dailySalesEntry.DailySalesId }));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("ID,Name,Ref,VendorName,VendorAddress,VendorPhone,Cost,PriceCOP,PriceUSD,ReorderQty,StockQty")] InventoryItem inventoryItem)
        {
            if (ModelState.IsValid)
            {
                _context.Add(inventoryItem);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(inventoryItem));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("ID,SalesRep,Date")] DailySalesModel dailySalesModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(dailySalesModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(dailySalesModel));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> Create(IFormCollection formCollection)
        {
            if (ModelState.IsValid)
            {
                //Save new AddInventoryModel
                AddInventoryModel addInventoryModel = new AddInventoryModel();
                addInventoryModel.UserName = User.Identity.Name;
                addInventoryModel.Date     = DateTime.Now;
                _context.Add(addInventoryModel);
                await _context.SaveChangesAsync();

                //Save new AddedItems to AddInventoryModel and update DB with new quantities
                var inventory = _context.InventoryItem;

                foreach (var _key in formCollection.Keys)
                {
                    if (_key != "__RequestVerificationToken")
                    {
                        var item   = inventory.Find(Convert.ToInt32(_key));
                        int addQty = Convert.ToInt32(formCollection[_key]);

                        //Add addedItem to _context and populate AddedItems
                        AddedItem addedItem = new AddedItem();
                        addedItem.AddInventoryModelId = addInventoryModel.ID;
                        addedItem.InventoryItemId     = item.ID;
                        addedItem.Quantity            = addQty;
                        _context.Add(addedItem);

                        //Update InventoryItem new StockQty
                        item.StockQty += addQty;
                    }
                }

                await _context.SaveChangesAsync();

                return(Redirect("../InventoryItems"));
            }

            return(RedirectToAction("AddInventory/Create"));
        }
Ejemplo n.º 5
0
 public async Task Save()
 {
     await cntx.SaveChangesAsync();
 }