public ActionResult Index(int id)
 {
     // build the landing page for shelf masters belonging to a productdetailid
     ShelfMasterViewModel obj = new ShelfMasterViewModel();
     var mylist = ShelfMasterService.fnListOfShelfMasters(id);
     FillIndexViewBag(id);
     return View("~/Views/ShelfMaster/Index.cshtml", mylist);
 }
        public static ShelfMasterViewModel fnFillShelfMasterFromDB(int id)
        {
            using (var db = new EF.CMCSQL03Entities())
            {
                ShelfMasterViewModel SM = new ShelfMasterViewModel();
                var dbSM = db.tblShelfMaster.Find(id);

                // get a pointer to the ProductDetail and ProductMaster parent records
                var PD = db.tblProductDetail.Find(dbSM.ProductDetailID);
                var PM = db.tblProductMaster.Find(PD.ProductMasterID);

                SM.shelfid = dbSM.ShelfID;
                SM.productdetailid = dbSM.ProductDetailID;
                SM.warehouse = dbSM.Warehouse;
                SM.size = dbSM.Size;
                SM.unitweight = dbSM.UnitWeight;
                SM.reordermin = dbSM.ReorderMin;
                SM.reordermax = dbSM.ReorderMax;
                SM.reorderqty = dbSM.ReorderQty;
                SM.bin = dbSM.Bin;   //??????
                SM.hazardsurcharge = dbSM.HazardSurcharge;
                SM.flammablesurcharge = dbSM.FlammableSurcharge;
                SM.heatsurcharge = dbSM.HeatSurcharge;
                SM.refrigsurcharge = dbSM.RefrigSurcharge;
                SM.freezersurcharge = dbSM.FreezerSurcharge;
                SM.cleansurcharge = dbSM.CleanSurcharge;
                SM.blendsurcharge = dbSM.BlendSurcharge;
                SM.nalgenesurcharge = dbSM.NalgeneSurcharge;
                SM.nitrogensurcharge = dbSM.NitrogenSurcharge;
                SM.biocidesurcharge = dbSM.BiocideSurcharge;
                SM.koshersurcharge = dbSM.KosherSurcharge;
                SM.labelsurcharge = dbSM.LabelSurcharge;
                SM.othersurcharge = dbSM.OtherSurcharge;
                SM.othersurchargeamt = dbSM.OtherSurchargeAmt;
                SM.othersurchargedescription = dbSM.OtherSurchargeDescription;
                SM.newitem = dbSM.NewItem;
                SM.inactivesize = dbSM.InactiveSize;
                SM.weboeinclude = dbSM.WebOEInclude;
                SM.sortorder = dbSM.SortOrder;
                SM.packageid = dbSM.PackageID;
                SM.notes = dbSM.Notes;
                SM.discontinued = dbSM.Discontinued;
                SM.alert = dbSM.Alert;
                SM.custcode = dbSM.CustCode;

                SM.ListOfTierSizes = fnListOfTierSizes(PM.ClientID);
                SM.ListOfPackages = fnListOfPackageIDs(dbSM.Size);
                SM.ListOfWareHouses = fnWarehouseIDs();
                return SM;
            }
        }
 public static ShelfMasterViewModel fnCreateNewShelfMaster(int id)
 {
     ShelfMasterViewModel SM = new ShelfMasterViewModel();
     SM.shelfid = -1;
     SM.productdetailid = id;
     using (var db = new EF.CMCSQL03Entities())
     {
         // get a pointer to the ProductDetail and ProductMaster parent records
         var PD = db.tblProductDetail.Find(id);
         var PM = db.tblProductMaster.Find(PD.ProductMasterID);
         SM.ListOfTierSizes = fnListOfTierSizes(PM.ClientID);
         SM.ListOfPackages = fnListOfPackageIDs(null);
         SM.ListOfWareHouses = fnWarehouseIDs();
         return SM;
     }
 }
        public ActionResult Save(ShelfMasterViewModel obj)
        {
            // do the work based on the button clicked in the Save action of the form

            string UserChoice = Request.Form["submitbutton"];

            if (UserChoice == "Cancel")
            {
                // just fall thru
            }
            if (UserChoice == "Save")
            {
                ShelfMasterService.fnSaveShelfMaster(obj);
            }
            if (UserChoice == "Delete")
            {
                // Need server side validation for Delete - no tblStock records
                ShelfMasterService.fnDeleteShelfMaster(obj.shelfid);
            }
            return RedirectToAction("Index", new { id = obj.productdetailid });
        }
        public static void fnSaveShelfMaster(ShelfMasterViewModel obj)
        {
            using (var db = new EF.CMCSQL03Entities())
            {
                if (obj.shelfid == -1)
                { obj.shelfid = fnNewShelfID(); }

                var dbSM = db.tblShelfMaster.Find(obj.shelfid);
                //SM.shelfid = dbSM.ShelfID;
                dbSM.ProductDetailID = obj.productdetailid;
                dbSM.Warehouse = obj.warehouse;
                dbSM.Size = obj.size;
                dbSM.UnitWeight = obj.unitweight;
                dbSM.ReorderMin = obj.reordermin;
                dbSM.ReorderMax = obj.reordermax;
                dbSM.ReorderQty = obj.reorderqty;
                dbSM.Bin = obj.bin;   //??????
                dbSM.HazardSurcharge = obj.hazardsurcharge;
                dbSM.FlammableSurcharge = obj.flammablesurcharge;
                dbSM.HeatSurcharge = obj.heatsurcharge;
                dbSM.RefrigSurcharge = obj.refrigsurcharge;
                dbSM.FreezerSurcharge = obj.freezersurcharge;
                dbSM.CleanSurcharge = obj.cleansurcharge;
                dbSM.BlendSurcharge = obj.blendsurcharge;
                dbSM.NalgeneSurcharge = obj.nalgenesurcharge;
                dbSM.NitrogenSurcharge = obj.nitrogensurcharge;
                dbSM.BiocideSurcharge = obj.biocidesurcharge;
                dbSM.KosherSurcharge = obj.koshersurcharge;
                dbSM.LabelSurcharge = obj.labelsurcharge;
                dbSM.OtherSurcharge = obj.othersurcharge;
                dbSM.OtherSurchargeAmt = obj.othersurchargeamt;
                dbSM.OtherSurchargeDescription = obj.othersurchargedescription;
                dbSM.NewItem = obj.newitem;
                dbSM.InactiveSize = obj.inactivesize;
                dbSM.WebOEInclude = obj.weboeinclude;
                dbSM.SortOrder = obj.sortorder;
                dbSM.PackageID = obj.packageid;
                dbSM.Notes = obj.notes;
                dbSM.Discontinued = obj.discontinued;
                dbSM.Alert = obj.alert;
                dbSM.CustCode = obj.custcode;
                db.SaveChanges();
            }
        }
 public ActionResult Edit(int id)
 {
     ShelfMasterViewModel obj = new ShelfMasterViewModel();
     obj = ShelfMasterService.fnFillShelfMasterFromDB(id);
     return PartialView("~/Views/ShelfMaster/_Edit.cshtml", obj);
 }
 public ActionResult Create(int id)
 {
     ShelfMasterViewModel obj = new ShelfMasterViewModel();
     obj = ShelfMasterService.fnCreateNewShelfMaster(id);
     return PartialView("~/Views/ShelfMaster/_Edit.cshtml", obj);
 }