public ActionResult CreateItem(int id)
 {
     // id = bulkorderid ..create a new line item to an existing bulkorderid
     BulkOrderItem obj = new BulkOrderItem();
     obj = ReplenishmentsService.fnCreateItem(id);
     return PartialView("~/Views/Replenishments/_BulkOrderItemModal.cshtml", obj);
 }
 public ActionResult SaveItem(BulkOrderItem obj)
 {
     // Catch form if no master code is selected
     if (obj.productmasterid == 0)
     {
         return Content("Please Select Master Code");
     }
     else
     {
         int pk = ReplenishmentsService.fnSaveItem(obj);
         return Content("Item Saved at " + DateTime.Now.ToString());
     }
 }
 public ActionResult EditItem(int id)
 {
     BulkOrderItem obj = new BulkOrderItem();
     obj = ReplenishmentsService.fnFillItemFromDB(id);
     return PartialView("~/Views/Replenishments/_BulkOrderItemModal.cshtml", obj);
 }
        public static int fnSaveItem(BulkOrderItem obj)
        {
            System.Threading.Thread.Sleep(1500);
            using (var db = new MvcPhoenix.EF.CMCSQL03Entities())
            {
                if (obj.bulkorderitemid == -1)
                {
                    obj.bulkorderitemid = fnNewBulkOrderItemID();
                }

                var dbrow = (from t in db.tblBulkOrderItem
                             where t.BulkOrderItemID == obj.bulkorderitemid
                             select t).FirstOrDefault();

                dbrow.BulkOrderID = obj.bulkorderid;
                dbrow.ProductMasterID = obj.productmasterid;
                dbrow.Weight = obj.weight;
                dbrow.Status = obj.itemstatus;
                dbrow.ETA = obj.eta;
                dbrow.DateReceived = obj.datereceived;
                dbrow.ItemNotes = obj.itemnotes;
                db.SaveChanges();

                return obj.bulkorderitemid;
            }
        }
        public static BulkOrderItem fnFillItemFromDB(int id)
        {
            // build object and return
            using (var db = new MvcPhoenix.EF.CMCSQL03Entities())
            {
                BulkOrderItem obj = new BulkOrderItem();
                obj = (from t in db.tblBulkOrderItem
                       where t.BulkOrderItemID == id
                       select new BulkOrderItem
                       {
                           bulkorderitemid = t.BulkOrderItemID,
                           bulkorderid = t.BulkOrderID,
                           productmasterid = t.ProductMasterID,
                           weight = t.Weight,
                           itemstatus = t.Status,
                           eta = t.ETA,
                           datereceived = t.DateReceived,
                           itemnotes = t.ItemNotes,
                       }).FirstOrDefault();

                var dbBulkOrder = db.tblBulkOrder.Find(obj.bulkorderid);
                obj.ListOfProductMasters = fnProductMasterIDs(Convert.ToInt32(dbBulkOrder.ClientID));
                obj.ListOfItemStatusIDs = fnOrderItemStatusIDs();

                return obj;
            }
        }
        public static BulkOrderItem fnCreateItem(int id)
        {
            using (var db = new MvcPhoenix.EF.CMCSQL03Entities())
            {
                BulkOrderItem obj = new BulkOrderItem();
                var dbBulkOrder = db.tblBulkOrder.Find(id);
                obj.bulkorderitemid = -1;
                obj.bulkorderid = id;
                obj.productmasterid = null;
                obj.weight = null;
                obj.itemstatus = "OP";
                obj.eta = null;
                obj.datereceived = null;
                obj.itemnotes = null;
                obj.ListOfProductMasters = fnProductMasterIDs(Convert.ToInt32(dbBulkOrder.ClientID));
                obj.ListOfItemStatusIDs = fnOrderItemStatusIDs();

                return obj;
            }
        }