//[HttpPost]
        //public ActionResult Create(TPO.Model.RawMaterials.RawMaterialQCModel model)
        //{
        //   TPO.BL.RawMaterials.RawMaterialQC qcBL = new TPO.BL.RawMaterials.RawMaterialQC();
        //  model = qcBL.InsertRawMaterialQCModel(model);
        //   return RedirectToAction("Edit", new { id = model.ID, unlocked = false });
        //}


        public ActionResult Edit(int id = 0, bool isNew = false, bool success = false)
        {
            TPO.BL.Security.User userBL = new TPO.BL.Security.User();
            ViewBag.QCTech = new SelectList(userBL.GetQCTechUsers(), "ID", "FullName");

            TPO.BL.RawMaterials.RawMaterialQC         qcBL  = new TPO.BL.RawMaterials.RawMaterialQC();
            TPO.Model.RawMaterials.RawMaterialQCModel model = qcBL.GetRawMaterialQCModelByRawMaterialQCID(id);
            //model.IsEditMode = !isNew;

            //hack
            if (success)
            {
                TempData["ActionMessage"]     = MessageRepository.GetStringValue(MessageKeys.ResponseMessageSuccessSave);
                TempData["ActionMessageType"] = MessageRepository.GetStringValue(MessageKeys.ResponseTypeSuccess);
            }
            if (model == null)
            {
                TempData["ActionMessage"] = MessageRepository.GetStringValue(MessageKeys.ResponseMessageFailNoRecord);
                //string.Format("Raw Material QC with ID {0} not found.", id);
                TempData["ActionMessageType"] = MessageRepository.GetStringValue(MessageKeys.ResponseTypeError);
                return(RedirectToAction("Index"));
                //return HttpNotFound(string.Format("Raw Material QC with ID {0} not found.", id));
            }
            return(View(model));
        }
        //
        // GET: /RawMaterialQC/
        public ActionResult Index(int?id, bool unlocked = false)
        {
            TPOMVCApplicationEntities db = new TPOMVCApplicationEntities();
            //
            var RawMat = db.RawMaterialQCs.Where(s => s.RawMaterialReceivedID != null).ToList();

            TPO.BL.RawMaterials.RawMaterial RawMatList = new TPO.BL.RawMaterials.RawMaterial();
            ViewBag.RawMaterialQCList = RawMatList.GetRawMaterials();

            //TODO: Refactor after RawMaterialModel is completed to use intID
            List <RawMaterialModel> rawMatListFromBL = RawMatList.GetRawMaterials();
            var QCList = db.Users.Where(s => s.ID != null).ToList();


            IEnumerable <SelectListItem> rawMaterialSelectList = from s in rawMatListFromBL
                                                                 select new SelectListItem
            {
                Value = s.RawMaterialCode,
                Text  = (s.RawMaterialCode + " | " + s.RawMaterialName)
            };
            //IEnumerable<SelectListItem> selectList = from s in RawMat
            //                                         select new SelectListItem
            //                                         {
            //                                             Value = s.RawMaterialID,
            //                                             Text = s.RawMaterialID + " | " + s.RawMaterialLotID.ToString()
            //                                         };

            IEnumerable <SelectListItem> lotSelectList = from s in RawMaterialReceivedRepo.GetAll()
                                                         select new SelectListItem
            {
                Value = s.LotNumber,
                Text  = s.LotNumber + " | " + s.LastModified.ToShortDateString()
            };


            //IEnumerable<SelectListItem> lotSelectList = from s in RawMat
            //                                            select new SelectListItem
            //                                            {
            //                                                Value = s.RawMaterialLotID,
            //                                                Text = (s.RawMaterialLotID.Length != 11 ? s.RawMaterialLotID : s.RawMaterialLotID) + " | " +
            //                                                s.DateEntered.ToShortDateString() +
            //                                                " | " + s.LastModified.ToShortDateString()
            //                                            };

            IEnumerable <SelectListItem> lotTestList = from s in RawMat
                                                       select new SelectListItem
            {
                Value = s.ID.ToString(),
                Text  = s.DateEntered.ToShortDateString() + " | " + s.BoxCarTested
            };


            //new SelectList()
            ViewBag.RawMaterialQC             = new SelectList(rawMaterialSelectList, "Value", "Text");
            ViewBag.RawMaterialLotQC          = new SelectList(lotSelectList, "Value", "Text");
            ViewBag.RawMaterialQCLotTest      = new SelectList(lotTestList, "Value", "Text");
            ViewBag.RawMaterialQCLastModified = new SelectList(RawMat, "ID", "LastModified");
            ViewBag.RawMaterialEnteredBy      = new SelectList(QCList, "ID", "FullName");

            TPO.BL.RawMaterials.RawMaterialQC qcBL = new TPO.BL.RawMaterials.RawMaterialQC();

            //if (id != null)
            //{
            //    RawMaterialQCModel model = qcBL.GetRawMaterialQCModelByRawMaterialQCID(id ?? Convert.ToInt32(id));
            //}
            //else
            //{
            //    RawMaterialQCModel model = new RawMaterialQCModel();
            //}

            RawMaterialQCModel model = qcBL.GetRawMaterialQCModelByRawMaterialQCID(id ?? Convert.ToInt32(id));

            if (model == null)
            {
                model = new RawMaterialQCModel();
            }

            var tests = (from t in db.RawMaterialQCs
                         where t.RawMaterialReceived.ID == t.RawMaterialReceivedID
                         select t).ToList();

            ViewBag.QCItems = tests;

            return(View(model));
        }