コード例 #1
0
        public Response <Invoice> Save(Invoice invoice)
        {
            try {
                Invoice newInvoice = new Invoice(invoice.IdInvoice, invoice.IdClient);
                foreach (InvoiceDetail detail in invoice.InvoiceDetails)
                {
                    newInvoice.AddInvoiceDetails(detail.Product, detail.QuantityProduct, detail.Discount, detail.UnitValue);
                }
                newInvoice.CalculateTotal();
                foreach (InvoiceDetail detail1 in newInvoice.InvoiceDetails)
                {
                    detail1.Product = null;
                }

                _context.Invoices.Add(newInvoice);
                _context.SaveChanges();
                return(new Response <Invoice>(newInvoice));
            } catch (Exception e) {
                return(new Response <Invoice>($"Error del aplicacion: {e.Message}"));
            }
        }
コード例 #2
0
 public Response <Invoice> Save(Invoice invoice)
 {
     try {
         Invoice newInvoice = new Invoice(invoice.Client);
         foreach (InvoiceDetail detail in invoice.InvoiceDetails)
         {
             if (detail.Product.QuantityStock - detail.QuantityProduct < 0)
             {
                 return(new Response <Invoice>("No hay suficiente stock"));
             }
             newInvoice.AddInvoiceDetails(detail.Product, detail.QuantityProduct, detail.Discount, detail.UnitValue);
             detail.Product.discountQuantityStock(detail.QuantityProduct);
             _context.Products.Update(detail.Product);
         }
         newInvoice.CalculateTotal();
         _context.Invoices.Add(newInvoice);
         _context.SaveChanges();
         return(new Response <Invoice>(newInvoice));
     } catch (Exception e) {
         return(new Response <Invoice>($"Error del aplicacion: {e.Message}"));
     }
 }