public JsonResult RawMaterialAjaxDelete(string id) { ResponseMessage responseMessage; try { TPOCurrentRawMaterial tpoCurrentRawMaterial = JsonConvert.DeserializeObject <TPOCurrentRawMaterial>(id); if (tpoCurrentRawMaterial != null) { TPOCurrentRawMaterialDto dto = new TPOCurrentRawMaterialDto(); using (TPOCurrentRawMaterialService service = new TPOCurrentRawMaterialService()) { Mapper.Map(tpoCurrentRawMaterial, dto); if (tpoCurrentRawMaterial.ID > 0) { service.Delete(dto.ID); } } } responseMessage = SetResponseMesssage(ActionTypeMessage.SuccessfulDelete); } catch (Exception exc) { responseMessage = SetResponseMesssage(ActionTypeMessage.FailedSave, exc.Message); } return(Json(responseMessage, JsonRequestBehavior.AllowGet)); }
public int AddTPOCurrentRawMaterial(TPOCurrentRawMaterialDto tpoCurrentRawMaterialDto) { var tpoCurrentRawMaterialEntity = new TPOCurrentRawMaterial(); try { tpoCurrentRawMaterialDto.ModifiedBy = CurrentUserName; tpoCurrentRawMaterialDto.EnteredBy = CurrentUserName; tpoCurrentRawMaterialDto.LastModified = DateTime.Now; tpoCurrentRawMaterialDto.DateEntered = DateTime.Now; Mapper.Map(tpoCurrentRawMaterialDto, tpoCurrentRawMaterialEntity); _repository.Repository <TPOCurrentRawMaterial>().Insert(tpoCurrentRawMaterialEntity); _repository.Save(); } catch (DbEntityValidationException valEx) { var sb = new StringBuilder(); foreach (var failure in valEx.EntityValidationErrors) { sb.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); sb.AppendLine(); } } throw new DbEntityValidationException( "Entity Validation Failed - errors follow:\n" + sb.ToString(), valEx ); // Add the original exception as the innerException } catch (Exception ex) { LogException(ex); throw; } return(tpoCurrentRawMaterialEntity.ID); }
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)); }