Exemple #1
0
        public async Task <IActionResult> FrontHouseInventory(int id, bool?loadFromContext)
        {
            //get inventory area log
            var areaLog = (from al in _summary.InventoryAreaLogs
                           where al.InventoryAreaid == id
                           select al).SingleOrDefault();

            if (areaLog == null)
            {
                return(NotFound());
            }

            //Create View Model
            FrontHouseInventoryViewModel fhivm = new FrontHouseInventoryViewModel();

            fhivm.Log = areaLog;

            //Load ViewModel with item counts
            foreach (var ic in areaLog.Inventory)
            {
                ItemCount temp = new ItemCount();
                temp.ItemCountId = ic.ItemCountId;
                temp.Item        = ic.Item;

                //Set count value based on value of loadFromContext
                if (loadFromContext == null || loadFromContext == true)
                {
                    temp.Count = ic.Count;  //get value from context
                }
                else
                {
                    temp.Count = 0;  //set count value to 0
                }

                //Add to itemCount to view model
                fhivm.Inventory.Add(temp);
            }

            return(View(fhivm));
        }
Exemple #2
0
 public IActionResult FrontHouseInventoryReset(FrontHouseInventoryViewModel fhivm)
 {
     //Redirect to FrontHouseInventory, setting loadFromContext to false
     return(RedirectToAction("FrontHouseInventory", new { id = fhivm.Log.InventoryAreaid, loadFromContext = false }));
 }
Exemple #3
0
        public async Task <IActionResult> FrontHouseInventorySubmit(FrontHouseInventoryViewModel fhivm)
        {
            if (fhivm == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    //Save ItemCounts
                    foreach (var ic in fhivm.Inventory)
                    {
                        //get corresponding itemcount from context
                        var temp = await(from i in _context.ItemCounts
                                         where i.ItemCountId == ic.ItemCountId
                                         select i).SingleOrDefaultAsync();

                        temp.Count = ic.Count;

                        //update context
                        _context.ItemCounts.Update(temp);
                    }

                    //Update Save Time

                    //get area log from context
                    var areaLog = await(from a in _context.InventoryAreaLogs
                                        where a.InventoryAreaInventoryLogId == fhivm.Log.InventoryAreaid
                                        select a).SingleOrDefaultAsync();

                    areaLog.Date = DateTime.Now;

                    //update arealog
                    _context.InventoryAreaLogs.Update(areaLog);

                    //Update Inventory Summary last edited user
                    var inventorySummary = await(from log in _context.InventoryLog
                                                 where log.InventorySummaryId == areaLog.InventorySummaryId
                                                 select log).SingleOrDefaultAsync();

                    var user = await _userManager.GetUserAsync(User);

                    inventorySummary.LastEdited = user.FullName;
                    _context.InventoryLog.Update(inventorySummary);

                    //save context
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }

                //Redirect to Submit page
                return(RedirectToAction("Submit", "InventorySummary", new { id = fhivm.Log.InventorySummaryId }));
            }

            return(RedirectToAction("FrontHouseInventory", new { id = fhivm.Log.InventoryAreaid, loadFromContext = true }));
        }