// GET: /RawMaterialQCRedHold/Edit/5 public ActionResult Edit(DateTime?holddate, DateTime?managerdate, DateTime?reddate, int?id) { RawMaterialQCRedHoldViewModel model = new Models.RawMaterialQCRedHoldViewModel(); try { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } //RawMaterialQCRedHold rawmaterialqcredhold = db.RawMaterialQCRedHolds.Find(id); //Sloppy error handling, have to fix the null ID variable. RawMaterialQCRedHoldDTO dto = RawMaterialQCRedHoldRepo.GetByID(id ?? -1); if (dto == null) { return(HttpNotFound()); } else { model = MapRawMaterialQCRedHoldDTOtoViewModel(dto); //TODO: Rewrite after QC object has been refactored. GetQcFormDetail(ref model); model.ManagerDate = managerdate; model.HoldDate = holddate; model.RedDate = reddate; PrepareSelectLists(); ViewBag.RawMaterialReceivedID = new SelectList(db.RawMaterialReceiveds, "ID", "RawMaterialID"); } } catch (Exception ex) { ViewBag.ExceptionMessage = ex.Message; TempData["ActionMessage"] = MessageRepository.GetStringValue(MessageKeys.ResponseMessageFailNoRecord); TempData["ActionMessageType"] = MessageRepository.GetStringValue(MessageKeys.ResponseTypeError); return(View(model)); } return(View(model)); }
public ActionResult Create( [Bind(Include = "Id,RawMaterialQCId,PlantId,RawMaterialReceivedId,FailPropertyId,HoldLotId,QCTechId,LeadOperatorId,SupervisorId,ManagerId,RedDate,Zone,RedComments,RedCorrectionAction,HoldDate,HoldComments,ManagerDate,ManagerComments,PrimeBoxCar,PrimeUOM,ReworkBoxCar,ReworkUOM,ScrapBoxCar,ScrapUOM,DateEntered,EnteredBy,LastModified,ModifiedBy")] RawMaterialQCRedHoldViewModel viewModel) { if (ModelState.IsValid) { try { //map objects for database TPO.Domain.DTO.RawMaterialQCRedHoldDTO dto = MapRawMaterialQCRedHoldViewModeltoDTO(viewModel); //update object records dto.ModifiedBy = CurrentUser; dto.EnteredBy = CurrentUser; dto.LastModified = DateTime.Now; dto.DateEntered = DateTime.Now; //save item, get item ID back int itemId = RawMaterialQCRedHoldRepo.Add(dto); //if item ID is valid redirect to edit page. if (itemId > 0) { TempData["ActionMessage"] = MessageRepository.GetStringValue(MessageKeys.ResponseMessageSuccessSave); TempData["ActionMessageType"] = MessageRepository.GetStringValue(MessageKeys.ResponseTypeSuccess); return(RedirectToAction("Edit", "RawMaterialQCRedHold", new { ID = itemId })); } } catch (Exception ex) { //ViewBag.ExceptionMessage = ex.Message; //return View(viewModel); TempData["ActionMessage"] = MessageRepository.GetStringValue(MessageKeys.ResponseMessageFailSave); TempData["ActionMessageType"] = MessageRepository.GetStringValue(MessageKeys.ResponseTypeError); } finally { PrepareSelectLists(); ViewBag.RawMaterialReceivedID = new SelectList(db.RawMaterialReceiveds, "ID", "RawMaterialID"); } } return(View(viewModel)); }
// GET: /RawMaterialQCRedHold/Create/QCID public ActionResult Create(DateTime?holddate, DateTime?managerdate, DateTime?reddate, int?id) { TPOWeb.Models.RawMaterialQCRedHoldViewModel model = new Models.RawMaterialQCRedHoldViewModel(); if (id == null) { TempData["ActionMessage"] = MessageRepository.GetStringValue(MessageKeys.ResponseMessageFailNoId); TempData["ActionMessageType"] = MessageRepository.GetStringValue(MessageKeys.ResponseTypeError); return(RedirectToAction("Index", "RawMaterialQC")); //return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } else { //Sloppy error handling, have to fix the null ID variable. RawMaterialQCRedHoldDTO lookupObjByQCId = RawMaterialQCRedHoldRepo.GetByQCID(id ?? -1); //test to see if record already exists, if it does, switch to edit view if (lookupObjByQCId != null && lookupObjByQCId.ID >= 0) { return(RedirectToAction("Edit", "RawMaterialQCRedHold", new { ID = lookupObjByQCId.ID })); } //TODO: Rewrite after QC object has been refactored. TPO.DL.Models.RawMaterialQC qcLookupObj = db.RawMaterialQCs.Find(id); model.RawMaterialQCId = qcLookupObj.ID; model.QCTechId = qcLookupObj.QCTechUserID; model.PlantId = qcLookupObj.PlantID; model.BoxCarTested = qcLookupObj.BoxCarTested; model.RawMaterialReceived = qcLookupObj.RawMaterialReceived.RawMaterial.Code; model.LotNumber = qcLookupObj.RawMaterialReceived.LotNumber; model.RawMaterialReceivedId = qcLookupObj.RawMaterialReceivedID; model.ManagerDate = managerdate; model.HoldDate = holddate; model.RedDate = reddate; PrepareSelectLists(); ViewBag.RawMaterialReceivedID = new SelectList(db.RawMaterialReceiveds, "ID", "RawMaterialID"); } return(View(model)); }
public ActionResult Edit( [Bind(Include = "Id,RawMaterialQCId,PlantId,RawMaterialReceivedId,FailPropertyId,HoldLotId,QCTechId,LeadOperatorId,SupervisorId,ManagerId,RedDate,Zone,RedComments,RedCorrectionAction,HoldDate,HoldComments,ManagerDate,ManagerComments,PrimeBoxCar,PrimeUOM,ReworkBoxCar,ReworkUOM,ScrapBoxCar,ScrapUOM,DateEntered,EnteredBy,LastModified,ModifiedBy")] RawMaterialQCRedHoldViewModel viewModel) { ViewBag.SuccessMessage = ""; if (ModelState.IsValid) { try { //map objects for database TPO.Domain.DTO.RawMaterialQCRedHoldDTO dto = MapRawMaterialQCRedHoldViewModeltoDTO(viewModel); //update object records dto.EnteredBy = dto.EnteredBy ?? CurrentUser; dto.DateEntered = dto.DateEntered ?? DateTime.Now; dto.ModifiedBy = CurrentUser; dto.LastModified = DateTime.Now; //save item, get item ID back RawMaterialQCRedHoldRepo.Update(dto); TempData["ActionMessage"] = MessageRepository.GetStringValue(MessageKeys.ResponseMessageSuccessSave); TempData["ActionMessageType"] = MessageRepository.GetStringValue(MessageKeys.ResponseTypeSuccess); //ViewBag.SuccessMessage = "Save completed successfully."; } catch (Exception ex) { ViewBag.ExceptionMessage = ex.Message; TempData["ActionMessage"] = MessageRepository.GetStringValue(MessageKeys.ResponseMessageFailSave); TempData["ActionMessageType"] = MessageRepository.GetStringValue(MessageKeys.ResponseTypeError); //return View(viewModel); } finally { ViewBag.RawMaterialReceivedID = new SelectList(db.RawMaterialReceiveds, "ID", "RawMaterialID"); } } else { ModelState.AddModelError(string.Empty, "Please enter required fields."); } PrepareSelectLists(); GetQcFormDetail(ref viewModel); return(View(viewModel)); }