public JsonResult SaveCurrentScrimResult(TPOCurrentScrimModel model) { ResponseMessage responseMessage; try { var dto = Mapper.Map <TPOCurrentScrimModel, TPOCurrentScrimDto>(model); dto.PlantID = CurrentPlantId; dto.ModifiedBy = CurrentUser; dto.LastModified = DateTime.Now; using (TPOCurrentScrimService svc = new TPOCurrentScrimService()) { if (dto.ID > 0) { svc.Update(dto); } else { dto.DateEntered = dto.LastModified; dto.EnteredBy = CurrentUser; dto.PlantID = CurrentPlantId; dto.ID = svc.Add(dto); } } model = Mapper.Map <TPOCurrentScrimDto, TPOCurrentScrimModel>(dto); //Have to set these manually //AutoMapper is setting them to null every time model.DateEntered = dto.DateEntered; model.EnteredBy = dto.EnteredBy; model.LastModified = dto.LastModified; model.ModifiedBy = dto.ModifiedBy; responseMessage = SetResponseMesssage(ActionTypeMessage.SuccessfulSave); } catch (Exception exc) { responseMessage = SetResponseMesssage(ActionTypeMessage.FailedSave, exc.Message); } return(Json(responseMessage, JsonRequestBehavior.AllowGet)); }
public JsonResult CurrentScrimByLineResult(int lineID = 0) { TPOCurrentScrimModel model = new TPOCurrentScrimModel(); using (TPOCurrentScrimService svc = new TPOCurrentScrimService()) { var dto = svc.GetByLineID(lineID).FirstOrDefault(); if (dto == null) { dto = new TPOCurrentScrimDto(); } Mapper.Map <TPOCurrentScrimDto, TPOCurrentScrimModel>(dto, model); //Have to set these manually //AutoMapper is setting them to null every time model.DateEntered = dto.DateEntered; model.EnteredBy = dto.EnteredBy; model.LastModified = dto.LastModified; model.ModifiedBy = dto.ModifiedBy; } return(Json(model, JsonRequestBehavior.AllowGet)); }
public JsonResult CurrentScrimAjaxCreate(string id, int lineId) { ResponseMessage responseMessage; try { CurrentScrimViewModel currentSrimViewModel = JsonConvert.DeserializeObject <CurrentScrimViewModel>(id); if (currentSrimViewModel != null) { TPOCurrentRawMaterialDto tpoCurrentRawMaterialdto = new TPOCurrentRawMaterialDto(); if (currentSrimViewModel.Id > 0) { using (TPOCurrentRawMaterialService service = new TPOCurrentRawMaterialService()) { tpoCurrentRawMaterialdto = service.Get(currentSrimViewModel.Id); } using (RawMaterialReceivedService service = new RawMaterialReceivedService()) { RawMaterialReceivedDto rawMaterialDto = new RawMaterialReceivedDto(); rawMaterialDto = service.GetAll() .Where(q => q.Id == Convert.ToInt32(currentSrimViewModel.LotNumber)) .ToList() .FirstOrDefault(); tpoCurrentRawMaterialdto.RawMaterialReceivedID = rawMaterialDto.Id; } } else { tpoCurrentRawMaterialdto.PlantID = CurrentPlantId; using (ProductionLineService service = new ProductionLineService()) { tpoCurrentRawMaterialdto.LineID = service.Get(lineId).ID; } using (RawMaterialReceivedService service = new RawMaterialReceivedService()) { RawMaterialReceivedDto rawMaterialDto = new RawMaterialReceivedDto(); rawMaterialDto = service.GetAll() .Where(q => q.Id == Convert.ToInt32(currentSrimViewModel.LotNumber)) .ToList() .FirstOrDefault(); tpoCurrentRawMaterialdto.RawMaterialReceivedID = rawMaterialDto.Id; } } using (TPOCurrentScrimService service = new TPOCurrentScrimService()) { if (currentSrimViewModel.Id > 0) { service.UpdateTPOCurrentRawMaterial(tpoCurrentRawMaterialdto); } else { service.AddTPOCurrentRawMaterial(tpoCurrentRawMaterialdto); } } } responseMessage = SetResponseMesssage(ActionTypeMessage.SuccessfulSave); } catch (Exception exc) { responseMessage = SetResponseMesssage(ActionTypeMessage.FailedSave, exc.Message); } return(Json(responseMessage, JsonRequestBehavior.AllowGet)); }