public void Update(ScrimRollDto scrimRollDto, ScrimActionDto scrimActionDto) { try { var scrimRoll = new ScrimRoll(); Mapper.Map(scrimRollDto, scrimRoll); _repository.Repository <ScrimRoll>().Update(scrimRoll); //CommitUnitOfWork(); var scrimAction = new ScrimAction(); Mapper.Map(scrimActionDto, scrimAction); if (scrimAction.ID > 0) { _repository.Repository <ScrimAction>().Update(scrimAction); } else { _repository.Repository <ScrimAction>().Insert(scrimAction); } CommitUnitOfWork(); } 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; } }
private void UpdateScrimUsageEntryForContractorRoll(TPOCProductRollDto tpoCProductRollDto, double divisor) { DateTime now = DateTime.Now; TPOBatch batch = _repository.Repository <TPOBatch>().GetAllBy(b => b.BatchNumber == tpoCProductRollDto.BatchNumber && b.IsScrim == true).FirstOrDefault(); ScrimRoll roll = _repository.Repository <ScrimRoll>().GetById(batch.ScrimRollID); ScrimActionType type = _repository.Repository <ScrimActionType>().GetAllBy(t => t.Code == "PR" && t.PlantID == tpoCProductRollDto.PlantID).FirstOrDefault(); double actionLength = (double)ConvertUoM(tpoCProductRollDto.Length, tpoCProductRollDto.LengthUoMID, roll.LengthUoMID) / divisor; double actionWeight = (double)ConvertUoM(tpoCProductRollDto.Weight, tpoCProductRollDto.WeightUoMID, roll.WeightUoMID) / divisor; ScrimAction action = new ScrimAction() { ActionDate = now, ActionLength = actionLength, ActionReasonText = "Production Entry", ActionWeight = actionWeight, DateEntered = now, EndLength = roll.Length - actionLength, EndWeight = roll.Weight - actionWeight, EnteredBy = tpoCProductRollDto.ModifiedBy, FleeceProd = false, LastModified = now, LineID = tpoCProductRollDto.LineID, ModifiedBy = tpoCProductRollDto.ModifiedBy, PlantID = tpoCProductRollDto.PlantID, ReasonID = null, RollID = null, ScrimRollID = roll.ID, ShiftID = tpoCProductRollDto.ShiftID, StartLength = roll.Length, StartWeight = roll.Weight, TypeID = type.ID }; _repository.Repository <ScrimAction>().Insert(action); }
public int Add(ScrimRollDto dto) { var entity = new ScrimRoll(); try { Mapper.Map(dto, entity); _repository.Repository <ScrimRoll>().Insert(entity); _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(entity.ID); }