public ActionResult Create([Bind(Include = "ID,PlantID,LineID,RawMaterialReceivedID,DateEntered,EnteredBy,LastModified,ModifiedBy")] CurrentRawMaterialViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var dto = MapCurrentRawMaterialViewModelToDTO(viewModel);
                    dto.ModifiedBy   = dto.EnteredBy;
                    dto.LastModified = DateTime.Now;
                    dto.DateEntered  = DateTime.Now;
                    CurrentRawMaterialRepo.Add(dto);

                    TempData["ActionMessage"]     = MessageRepository.GetStringValue(MessageKeys.ResponseMessageSuccessSave);
                    TempData["ActionMessageType"] = MessageRepository.GetStringValue(MessageKeys.ResponseTypeSuccess);
                    return(RedirectToAction("Index", new { lineId = dto.LineId }));
                }
                catch (Exception ex)
                {
                    ViewBag.ExceptionMessage = ex.Message;

                    TempData["ActionMessage"]     = MessageRepository.GetStringValue(MessageKeys.ResponseMessageFailSave);
                    TempData["ActionMessageType"] = MessageRepository.GetStringValue(MessageKeys.ResponseTypeError);
                    return(View(viewModel));
                }
            }

            return(RedirectToAction("Create"));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            string lineIdHolder = CurrentRawMaterialRepo.GetById(id).LineId;

            CurrentRawMaterialRepo.Delete(id);
            TempData["ActionMessage"]     = MessageRepository.GetStringValue(MessageKeys.ResponseMessageSuccessDelete);
            TempData["ActionMessageType"] = MessageRepository.GetStringValue(MessageKeys.ResponseTypeSuccess);
            return(RedirectToAction("Index", new { lineId = lineIdHolder }));
        }
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                TempData["ActionMessage"]     = MessageRepository.GetStringValue(MessageKeys.ResponseMessageFailNoId);
                TempData["ActionMessageType"] = MessageRepository.GetStringValue(MessageKeys.ResponseTypeError);
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var dto       = CurrentRawMaterialRepo.GetById(id.Value);
            var viewModel = MapCurrentRawMaterialDTOToViewModel(dto);

            return(View(viewModel));
        }
        // GET: /RawMaterialCurrent/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id.HasValue)
            {
                var dto = CurrentRawMaterialRepo.GetById(id.Value);
                var vm  = MapCurrentRawMaterialDTOToViewModel(dto);
                return(ShowEditView(vm));
            }

            TempData["ActionMessage"]     = MessageRepository.GetStringValue(MessageKeys.ResponseMessageFailNoId);
            TempData["ActionMessageType"] = MessageRepository.GetStringValue(MessageKeys.ResponseTypeError);
            return(RedirectToAction("Index"));
        }
        //public void LoadLineDropdown(string lineId)
        //{
        //    var productionLines = ProductionLineRepo.GetProductionLines(CurrentPlantId).ToList();
        //    IEnumerable<SelectListItem> lineItems = from currentLine in productionLines
        //                                            select new SelectListItem {
        //                                                Text = currentLine.Code,
        //                                                //TODO: Replace with ID after refactor in sprint 2
        //                                                Value = currentLine.Code,
        //                                                Selected = currentLine.Code==lineId,
        //                                            };
        //    ViewBag.productionLineSelectList = new SelectList(lineItems,"","",selectedValue);
        //}

        public List <CurrentRawMaterialDTO> GetRawMaterailListing(string lineId)
        {
            List <CurrentRawMaterialDTO> currentRawMaterials;

            if (lineId != null)
            {
                currentRawMaterials = CurrentRawMaterialRepo.GetAll(CurrentPlantId, lineId);
            }
            else
            {
                currentRawMaterials = new List <CurrentRawMaterialDTO>();
            }

            return(currentRawMaterials);
        }
        public ActionResult Edit([Bind(Include = "ID,PlantID,LineID,RawMaterialReceivedID,DateEntered,EnteredBy,LastModified,ModifiedBy")] CurrentRawMaterialViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var dto = MapCurrentRawMaterialViewModelToDTO(viewModel);
                CurrentRawMaterialRepo.Update(dto);

                TempData["ActionMessage"]     = MessageRepository.GetStringValue(MessageKeys.ResponseMessageSuccessSave);
                TempData["ActionMessageType"] = MessageRepository.GetStringValue(MessageKeys.ResponseTypeSuccess);
                return(RedirectToAction("Index", new { lineId = dto.LineId }));
            }
            TempData["ActionMessage"]     = MessageRepository.GetStringValue(MessageKeys.ResponseMessageFailSave);
            TempData["ActionMessageType"] = MessageRepository.GetStringValue(MessageKeys.ResponseTypeError);
            return(ShowEditView(viewModel));
        }
        // GET: /RawMaterialCurrent/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                TempData["ActionMessage"]     = MessageRepository.GetStringValue(MessageKeys.ResponseMessageFailNoId);
                TempData["ActionMessageType"] = MessageRepository.GetStringValue(MessageKeys.ResponseTypeError);
                return(RedirectToAction("Index"));
                //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            var current = CurrentRawMaterialRepo.GetById(id.Value);

            if (current == null)
            {
                TempData["ActionMessage"]     = MessageRepository.GetStringValue(MessageKeys.ResponseMessageFailNoRecord);
                TempData["ActionMessageType"] = MessageRepository.GetStringValue(MessageKeys.ResponseTypeError);
                return(RedirectToAction("Index"));
                //return HttpNotFound();
            }
            return(View(MapCurrentRawMaterialDTOToViewModel(current)));
        }