// POST api/invoiceLines
 public virtual HttpResponseMessage Post(InvoiceLine invoiceLine)
 {
     if (invoiceLine == null)
     {
         return Request.CreateResponse(HttpStatusCode.BadRequest);
     }
     else
     {
         if (invoiceLine.Product == null)
         {
             return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "No se puede crear una línea sin producto");
         }
         if (invoiceLine.Invoice == null)
         {
             return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "No se puede crear una línea de factura sin información de su cabecera");
         }
         using (AriUMContext ctx = new AriUMContext("AriUMDBConnection"))
         {
             InvoiceLine i = CntWebApiVerbs.PostInvoiceLine(invoiceLine, ctx);
             InvoiceLine idt = ctx.CreateDetachedCopy<InvoiceLine>(i);
             var response = Request.CreateResponse<InvoiceLine>(HttpStatusCode.Created, idt);
             response.Headers.Location = GetInvoiceLineLocation(idt.InvoiceLineId);
             return response;
         }
     }
 }
 // PUT api/invoiceLines/5
 public virtual HttpResponseMessage Put(int id, InvoiceLine invoiceLine)
 {
     if (invoiceLine == null || id != invoiceLine.InvoiceLineId)
     {
         return Request.CreateResponse(HttpStatusCode.BadRequest);
     }
     else
     {
         using (AriUMContext ctx = new AriUMContext("AriUMDBConnection"))
         {
             // Does it exist?
             InvoiceLine i = CntWebApiVerbs.GetInvoiceLine(id, ctx);
             if (i == null)
             {
                 return Request.CreateResponse(HttpStatusCode.NotFound);
             }
             else
             {
                 CntWebApiVerbs.PutInvoiceLine(invoiceLine, ctx);
                 return Request.CreateResponse(HttpStatusCode.NoContent);
             }
         }
     }
 }
Exemplo n.º 3
0
 public static InvoiceLine PutInvoiceLine(InvoiceLine invoiceLine, AriUMContext ctx)
 {
     int invoiceLineId = invoiceLine.InvoiceLineId;
     int productId = 0;
     int invoiceId = 0;
     if (invoiceLine.Product != null)
     {
         productId = invoiceLine.Product.ProductId;
         invoiceLine.Product = null;
     }
     if (invoiceLine.Invoice != null)
     {
         invoiceId = invoiceLine.Invoice.InvoiceId;
         invoiceLine.Invoice = null;
     }
     ctx.AttachCopy<InvoiceLine>(invoiceLine);
     invoiceLine = (from il in ctx.InvoiceLines
                    where il.InvoiceLineId == invoiceLineId
                    select il).FirstOrDefault<InvoiceLine>();
     invoiceLine.Product = (from p in ctx.Products
                            where p.ProductId == productId
                            select p).FirstOrDefault<Product>();
     invoiceLine.Invoice = (from i in ctx.Invoices
                            where i.InvoiceId == invoiceId
                            select i).FirstOrDefault<Invoice>();
     ctx.SaveChanges();
     return invoiceLine;
 }
Exemplo n.º 4
0
 public static bool DeleteInvoiceLine(InvoiceLine invoiceLine, AriUMContext ctx)
 {
     ctx.Delete(invoiceLine);
     ctx.SaveChanges();
     return true;
 }
Exemplo n.º 5
0
 public static InvoiceLine PostInvoiceLine(InvoiceLine invoiceLine, AriUMContext ctx)
 {
     if (invoiceLine.Invoice != null)
     {
         Invoice invoice = (from i in ctx.Invoices
                            where i.InvoiceId == invoiceLine.Invoice.InvoiceId
                            select i).FirstOrDefault<Invoice>();
         invoiceLine.Invoice = invoice;
     }
     if (invoiceLine.Product != null)
     {
         Product product = (from p in ctx.Products
                            where p.ProductId == invoiceLine.Product.ProductId
                            select p).FirstOrDefault<Product>();
         invoiceLine.Product = product;
     }
     ctx.Add(invoiceLine);
     ctx.SaveChanges();
     return invoiceLine;
 }