private ProdLineRollConfig Save(ProdLineRollConfigDto dto) { ProdLineRollConfig entity = null; try { if (dto.ID == 0) { entity = new ProdLineRollConfig(); Mapper.Map(dto, entity); _repository.Repository <ProdLineRollConfig>().Insert(entity); } else { entity = GetById(dto.ID); Mapper.Map(dto, entity); _repository.Repository <ProdLineRollConfig>().Update(entity); } } catch (Exception ex) { LogException(ex); throw; } return(entity); }
public int Add(ProdLineRollConfigDto dto) { ProdLineRollConfig entity = Save(dto); CommitUnitOfWork(); if (entity != null) { return(entity.ID); } else { return(-1); } }
private ProdLineRollConfigDto MapEntity(ProdLineRollConfig entity) { return(Mapper.Map <ProdLineRollConfig, ProdLineRollConfigDto>(entity)); }
public int Add(ProductionLinesDto dto) { var entity = Mapper.Map <ProductionLinesDto, ProdLine>(dto); //TODO: Set fields on ProdLinesPerform based on values in ProdLine //ProdLinesPerform plp = new ProdLinesPerform(); //plp.LocID = entity.LocID; //TODO: Handle setting current work order to Line based on its type (see usp_WO_UpdateRCRWWorkOrders in old DB for reference) #region Line Type Checks //Get the type of production line ProdLineType type = _repository.Repository <ProdLineType>().GetById(entity.LineTypeID); if (type != null) { //If type is not reclaim or rework, make sure a WOLineUse record is present if (type.ProdLineTypeCode != "RW" && type.ProdLineTypeCode != "RC") { //TODO: Once WOLineUse table has been created, create a new instance of that Entity here and assign to newly created ProdLine } if (type.ProdLineTypeCode == "TPO" || type.ProdLineTypeCode == "RW" || type.ProdLineTypeCode == "WI" || type.ProdLineTypeCode == "CO") { //Create TPOCurrentScrim record if (type.ProdLineTypeCode == "TPO" || type.ProdLineTypeCode == "CO") { TPOCurrentScrim currScrim = new TPOCurrentScrim(); entity.TPOCurrentScrims.Add(currScrim); currScrim.PlantID = entity.PlantID; currScrim.DateEntered = entity.DateEntered; currScrim.EnteredBy = entity.EnteredBy; currScrim.LastModified = entity.LastModified; currScrim.ModifiedBy = entity.ModifiedBy; currScrim.ScrimPos = "NA"; if (type.ProdLineTypeCode == "TPO") { //TODO: Create TPOFormLineProd for this line for all products for the //current plant in TPOProducts where IsRepel is false //See usp_SA_LineProdFormCheck in old database } //TODO: Once TPOCurrentBatch table has been created, create a new instance of that Entity here } } } #endregion //Create ProductionShiftUse records for each available shift var prodShifts = _repository.Repository <ProductionShiftDto>().GetAllBy(s => s.PlantID == entity.PlantID).ToList(); for (int i = 0; i < prodShifts.Count; i++) { var minutes = 0; if (prodShifts[i].StartTime > prodShifts[i].EndTime) { minutes = prodShifts[i].StartTime.Subtract(prodShifts[i].EndTime).Minutes + 1440; } else { minutes = minutes = prodShifts[i].StartTime.Subtract(prodShifts[i].EndTime).Minutes; } ProductionShiftUse use = new ProductionShiftUse() { ShiftID = prodShifts[i].ID, PlantID = entity.PlantID, Day1Minutes = minutes, Day2Minutes = minutes, Day3Minutes = minutes, Day4Minutes = minutes, Day5Minutes = minutes, Day6Minutes = minutes, Day7Minutes = minutes, DateEntered = entity.DateEntered, EnteredBy = entity.EnteredBy, LastModified = entity.LastModified, ModifiedBy = entity.ModifiedBy }; entity.ProductionShiftUses.Add(use); //Need to create config line now since FK is non-nullable ProdLineRollConfig config = new ProdLineRollConfig() { RollName = type.ProdLineTypeCode, TypeID = type.ID, Order = 0 }; entity.ProdLineRollConfig = config; } //TODO: Create new ProdDteChng record ProdDateChange change = new ProdDateChange() { DateChange = DateTime.Now, RotationStart = DateTime.Now, PlantID = entity.PlantID, DateEntered = entity.DateEntered, EnteredBy = entity.EnteredBy, LastModified = entity.LastModified, ModifiedBy = entity.ModifiedBy }; entity.ProdDateChanges.Add(change); try { _repository.Repository <ProdLine>().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); }