public IActionResult OnPost([FromBody] LivroAutorAggregateModel livroAggregateModel) { if (ModelState.IsValid) { _unitOfWork.BeginTransaction(); var livroCriado = _livroService.Create(livroAggregateModel); _unitOfWork.Commit(); return(Ok(livroCriado)); } return(BadRequest("Existe algum valor inválido passado.")); }
public LivroModel Create(LivroAutorAggregateModel livroAutorAggregateModel) { if (livroAutorAggregateModel.Livro.AutorId > 0) { return(_livroRepository.Create(livroAutorAggregateModel.Livro)); } //Exemplo com transaction sem UnitOfWork e SaveChanges nos Repositories //using var transactionScope = new TransactionScope(); //TransactionScopeAsyncFlowOption.Enabled); var autor = _autorRepository.Create(livroAutorAggregateModel.Autor); livroAutorAggregateModel.Livro.Autor = autor; //Com Transaction, usar AutorId var livro = _livroRepository.Create(livroAutorAggregateModel.Livro); //Exemplo com transaction sem UnitOfWork e SaveChanges nos Repositories //transactionScope.Complete(); return(livro); }