public TransactionResult update(PipaVo pipa_vo) { IList <Tanque> tanquesLast = pipa_repository.getAllTanquesByIdPipa(pipa_vo.id); pipa_repository.deleteTanquesByIdPipa(pipa_vo.id); foreach (TanqueVo dvo in pipa_vo.tanques) { dvo.pipa_id = pipa_vo.id; foreach (Tanque t in tanquesLast) { if (dvo.combustible_id == t.combustible.id) { dvo.litros = t.litros; break; } } var tr2 = TransactionResult.CREATED; tr2 = pipa_repository.createTanque(TanqueAdapter.voToObject(dvo)); if (tr2 != TransactionResult.CREATED) { return(tr2); } } return(pipa_repository.update(PipaAdapter.voToObject(pipa_vo))); }
//Create Pipa con sus tanques public TransactionResult create(PipaVo pipa_vo) { //Pipa pipa = PipaAdapter.voToObject(pipa_vo); //return pipa_repository.create(pipa); Pipa pipa = PipaAdapter.voToObject(pipa_vo); int id = pipa_repository.create(pipa); if (id > 0) { foreach (TanqueVo dvo in pipa_vo.tanques) { dvo.pipa_id = id; var tr2 = TransactionResult.CREATED; tr2 = pipa_repository.createTanque(TanqueAdapter.voToObject(dvo)); if (tr2 != TransactionResult.CREATED) { return(tr2); } } return(TransactionResult.CREATED); } return(TransactionResult.ERROR); }