public static void fnSaveInventory(Inventory vm)
        {
            using (var db = new EF.CMCSQL03Entities())
            {
                var pd = db.tblProductDetail.Find(vm.PP.productdetailid);
                var pm = db.tblProductMaster.Find(pd.ProductMasterID);

                pm.AlertNotesPackout = vm.PP.alertnotespackout;
                pm.AlertNotesReceiving = vm.PP.alertnotesreceiving;
                pd.AlertNotesOrderEntry = vm.PP.alertnotesorderentry;
                pd.AlertNotesShipping = vm.PP.alertnotesshipping;

                db.SaveChanges();
            }
        }
        public static Inventory fnFillInventoryVM(int id)
        {
            using (var db = new CMCSQL03Entities())
            {
                Inventory vm = new Inventory();
                ProductProfile PP = new ProductProfile();

                PP.productdetailid = id;
                vm.PP = ProductsService.FillFromPD(PP);
                PP = ProductsService.FillFromPM(PP);
                PP = ProductsService.fnFillOtherPMProps(PP);

                //vm.vmMasterNotesAlert = PP.masternotesalert;    // cannot get View to properly handle this when buried in PP
                vm.ClientCode = (from t in db.tblClient
                                 where t.ClientID == PP.clientid
                                 select t.ClientCode).FirstOrDefault();

                vm.ClientUM = (from t in db.tblClient
                               where t.ClientID == id
                               select t.ClientUM).FirstOrDefault();

                vm.Division = (from t in db.tblDivision
                               where t.DivisionID == PP.divisionid
                               select t.Division).FirstOrDefault();

                var q = (from t in db.tblBulkOrderItem
                         where t.ProductMasterID == id && t.Status == "OP"
                         select t).FirstOrDefault();

                vm.BackOrderPending = q == null ? false : true;

                var q1 = (from t in db.tblBulkOrderItem
                          where t.ProductMasterID == id && t.Status == "OP"
                          select new { tot = t.Qty * t.Weight }).ToList();

                var q2 = (from x in q1 select x.tot).Sum();

                vm.BulkWeightCurrentlyOnOrder = Convert.ToDecimal(q2);

                vm.ShelfLevelTotal = StatusLevelShelf(id, "TOTAL");
                vm.ShelfLevelAvail = StatusLevelShelf(id, "AVAIL");
                vm.ShelfLevelTest = StatusLevelShelf(id, "TEST");
                vm.ShelfLevelHold = StatusLevelShelf(id, "HOLD");
                vm.ShelfLevelQC = StatusLevelShelf(id, "QC");
                vm.ShelfLevelReturn = StatusLevelShelf(id, "RETURN");
                vm.ShelfLevelRecd = StatusLevelShelf(id, "RECD");
                vm.ShelfLevelOther = StatusLevelShelf(id, "OTHER");
                vm.BulkLevelTotal = StatusLevelBulk(id, "TOTAL");
                vm.BulkLevelAvail = StatusLevelBulk(id, "AVAIL");
                vm.BulkLevelTest = StatusLevelBulk(id, "TEST");
                vm.BulkLevelHold = StatusLevelBulk(id, "HOLD");
                vm.BulkLevelQC = StatusLevelBulk(id, "QC");
                vm.BulkLevelReturn = StatusLevelBulk(id, "RETURN");
                vm.BulkLevelRecd = StatusLevelBulk(id, "RECD");
                vm.BulkLevelOther = StatusLevelBulk(id, "OTHER");
                vm.TotalLevelTotal = StatusLevelTotal(id, "TOTAL");
                vm.TotalLevelAvail = StatusLevelTotal(id, "AVAIL");
                vm.TotalLevelTest = StatusLevelTotal(id, "TEST");
                vm.TotalLevelHold = StatusLevelTotal(id, "HOLD");
                vm.TotalLevelQC = StatusLevelTotal(id, "QC");
                vm.TotalLevelReturn = StatusLevelTotal(id, "RETURN");
                vm.TotalLevelReturn = StatusLevelTotal(id, "RECD");
                vm.TotalLevelOther = StatusLevelTotal(id, "OTHER");

                return vm;
            }
        }
 public ActionResult Save(Inventory vm)
 {
     MvcPhoenix.Services.InventoryService.fnSaveInventory(vm);
     return RedirectToAction("Edit", new { id = vm.PP.productdetailid });
 }