public async Task <ActionResult <IEnumerable <ResponseInvoice> > > Put(InvoiceFullDto invoiceFullDto) { var result = new ResponseInvoice(); try { using (var tran = _facturaContexto.Database.BeginTransaction()) { try { var rs_invoice = await _facturaContexto.Invoices.Where(x => x.Id == invoiceFullDto.Id).FirstOrDefaultAsync(); if (rs_invoice == null) { return(BadRequest()); } rs_invoice.ClientId = invoiceFullDto.ClientId; rs_invoice.NameShopkeeper = invoiceFullDto.NameShopkeeper; rs_invoice.Date = rs_invoice.Date; _facturaContexto.Entry(rs_invoice).State = EntityState.Modified; _facturaContexto.SaveChanges(); foreach (var item in invoiceFullDto.DetailInvoiceDto) { var detailp = _facturaContexto.DetailInvoices.Find(item.ProductId); var listProduct = new DetailInvoiceDto(); if (detailp == null) { return(BadRequest()); } listProduct.ProductId = item.ProductId; listProduct.Precio_Pro = detailp.Precio_Pro; listProduct.Cantidad = item.Cantidad; listProduct.Total = detailp.Precio_Pro * item.Cantidad; _facturaContexto.Entry(listProduct).State = EntityState.Modified; _facturaContexto.SaveChanges(); } await tran.CommitAsync(); } catch (Exception) { await tran.RollbackAsync(); throw; } } } catch (Exception) { throw; } return(Ok(result)); }
public async Task <ActionResult> PutClient(int id, ClientDto item) { if (id != item.Id) { return(BadRequest()); } _facturaContexto.Entry(item).State = EntityState.Modified; await _facturaContexto.SaveChangesAsync(); return(NoContent()); }