private ProdLinesPerformProd UpdateRepository(ProdLinesPerformProdDto dto) { ProdLinesPerformProd entity = null; try { if (dto.ID == 0) { entity = new ProdLinesPerformProd(); Mapper.Map(dto, entity); _repository.Repository <ProdLinesPerformProd>().Insert(entity); } else { entity = GetById(dto.ID); Mapper.Map(dto, entity); _repository.Repository <ProdLinesPerformProd>().Update(entity); } } catch (Exception ex) { LogException(ex); throw; } return(entity); }
public int AddToUnitOfWork(ProdLinesPerformProdDto dto) { int key = -1; ProdLinesPerformProd entity = UpdateRepository(dto); if (entity != null) { key = entity.ID; } return(key); }
public int Add(ProdLinesPerformDto dto) { var entity = Mapper.Map <ProdLinesPerformDto, ProdLinesPerform>(dto); try { var prodLine = _repository.Repository <ProdLine>().GetById(dto.ProdLineID); var typeCode = prodLine.ProdLineType.ProdLineTypeCode; if (typeCode == "TPO" || typeCode == "RW" || typeCode == "WI" || typeCode == "CO") { //Create ProdLinesPerform records for REPEL and GEOREPEL TPOProducts var products = _repository.Repository <TPOProduct>().GetAllBy(p => p.ProductCode == "REPEL" || p.ProductCode == "GEOREPEL").ToList(); for (int i = 0; i < products.Count; i++) { ProdLinesPerformProd perform = new ProdLinesPerformProd(); perform.ProdLineID = prodLine.ID; perform.ProductID = products[i].ID; perform.Throughput = entity.Throughput; perform.LocID = entity.LocID; perform.DateChange = DateTime.Now; _repository.Repository <ProdLinesPerformProd>().Insert(perform); } } _repository.Repository <ProdLinesPerform>().Insert(entity); _repository.Save(); } catch (System.Data.Entity.Validation.DbEntityValidationException valEx) { HandleValidationException(valEx); } catch (Exception ex) { LogException(ex); throw; } return(entity.ID); }
private ProdLinesPerformProdDto MapEntity(ProdLinesPerformProd entity) { return(Mapper.Map <ProdLinesPerformProd, ProdLinesPerformProdDto>(entity)); }