public async Task Update(FacturacionCompraDTO facturacionCompra) { try { Compra compra = await _compraRepository.FindAsync(facturacionCompra.IdCompra); if (compra != null) { compra.IdCliente = facturacionCompra.Cliente.IdCliente; List <CompraProducto> compraProductos = new List <CompraProducto>(); foreach (var producto in facturacionCompra.Productos) { compraProductos.Add(new CompraProducto { IdCompra = compra.IdCompra, Cantidad = producto.Cantidad, IdProducto = producto.IdProducto }); } compra.CompraProductos = compraProductos; _compraRepository.Update(compra); _compraRepository.Save(); } else { throw new Exception("No existe la compra"); } } catch (Exception e) { throw e; } }
public async void ShouldInsertWithSucess() { var revendedor = new Revendedor() { NomeCompleto = "Nome", CPF = "111.222.333-00", Email = "*****@*****.**", Senha = "1234", }; await _revendedorService.InsertAsync(revendedor); var compra = new Compra(1, 1200); var command = await _service.InsertAsync(compra, revendedor.CPF); Assert.NotNull(command); var compraBd = await _repository.FindAsync(command.Id); Assert.NotNull(compraBd); }