public ActionResult Create(int qcID = 0) { if (qcID == 0) { SetResponseMesssage(ActionTypeMessage.Error, General.ResponseMessageFailNoId); return(RedirectToAction("Index", "RawMaterialQC")); } using (RawMaterialQCRedHoldService rhSvc = new RawMaterialQCRedHoldService()) { var dto = rhSvc.GetByQC(qcID); if (dto != null) { return(RedirectToAction("Edit", new { id = dto.Id })); } } RawMaterialQCRedHoldViewModel model = new RawMaterialQCRedHoldViewModel(); model.RawMaterialQCId = qcID; using (RawMaterialsQcService svc = new RawMaterialsQcService()) { RawMaterialQcDto qcDto = svc.Get(qcID); model.RawMaterialReceivedId = qcDto.RawMaterialReceivedId; using (RawMaterialReceivedService receiveSvc = new RawMaterialReceivedService()) { RawMaterialReceivedDto receivedDto = receiveSvc.Get(qcDto.RawMaterialReceivedId); model.BoxCarTested = receivedDto.LotNumber; model.RawMaterialReceived = receivedDto.RawMaterialCode; ViewBag.RawMaterialReceivedID = new SelectList(receiveSvc.GetAll(), "ID", "RawMaterialID"); } } PrepareSelectLists(); return(View(model)); }
public ActionResult Edit(RawMaterialQCRedHoldViewModel viewModel) { try { using (RawMaterialQCRedHoldService svc = new RawMaterialQCRedHoldService()) { var dto = svc.Get(viewModel.Id); dto = AutoMapper.Mapper.Map <RawMaterialQCRedHoldViewModel, RawMaterialQcRedHoldDto>(viewModel, dto); dto.ModifiedBy = CurrentUser; dto.LastModified = DateTime.Now; svc.Update(dto); SetResponseMesssage(ActionTypeMessage.SuccessfulSave); } } catch (Exception ex) { SetResponseMesssage(ActionTypeMessage.FailedSave); } finally { using (RawMaterialReceivedService svc = new RawMaterialReceivedService()) { ViewBag.RawMaterialReceivedID = new SelectList(svc.GetAll(), "ID", "RawMaterialID"); } } PrepareSelectLists(); return(View(viewModel)); }
public ActionResult Edit(int id = 0) { if (id == 0) { SetResponseMesssage(ActionTypeMessage.Error, General.ResponseMessageFailNoId); return(RedirectToAction("Index", "RawMaterialQC")); } RawMaterialQCRedHoldViewModel model = null; using (RawMaterialQCRedHoldService svc = new RawMaterialQCRedHoldService()) { var dto = svc.Get(id); model = AutoMapper.Mapper.Map <RawMaterialQcRedHoldDto, RawMaterialQCRedHoldViewModel>(dto); } PrepareSelectLists(); return(View(model ?? new RawMaterialQCRedHoldViewModel())); }
public ActionResult Create(RawMaterialQCRedHoldViewModel viewModel) { if (ModelState.IsValid) { try { //separate view model data into dtos //var msrv = new MessageService(); using (var rhsrv = new RawMaterialQCRedHoldService()) { var dto = AutoMapper.Mapper.Map <RawMaterialQCRedHoldViewModel, RawMaterialQcRedHoldDto>(viewModel); dto.PlantId = CurrentPlantId; dto.EnteredBy = CurrentUser; dto.DateEntered = DateTime.Now; dto.ModifiedBy = CurrentUser; dto.LastModified = DateTime.Now; //save item, get item ID back int itemId = rhsrv.Add(dto); //if item ID is valid redirect to edit page. if (itemId > 0) { SetResponseMesssage(ActionTypeMessage.SuccessfulSave); return(RedirectToAction("Edit", "RawMaterialQCRedHold", new { ID = itemId })); } } } catch (Exception ex) { SetResponseMesssage(ActionTypeMessage.FailedSave); } finally { PrepareSelectLists(); RawMaterialReceivedService rmsrv = new RawMaterialReceivedService(); ViewBag.RawMaterialReceivedID = new SelectList(rmsrv.GetAll(), "ID", "RawMaterialID"); } } return(View(viewModel)); }