public bool Delete(Invoice invoice)
 {
     IDictionary<string, object> vars = new Dictionary<string, object>(2);
     vars.Add("companyId", this.companyId);
     vars.Add("invoiceID", invoice.Id.Value);
     Invoice response = this.restTemplate.PostForObjectAsync<Invoice>("/resource/invoice/v2/{companyId}/{invoiceID}?methodx=delete", buildDelete(invoice), vars).Result;
     return (response.Id == null);
 }
 public Task<Invoice> Save(Invoice invoice)
 {
     if (invoice.Id != null && invoice.Id.Value != null)
     {
         return Update(invoice);
     }
     else
     {
         return Create(invoice);
     }
 }
        public InvoiceBuilder()
        {
            _invoice = new Invoice();

            InvoiceHeader invoiceHeader = new InvoiceHeader();

            invoiceHeader.DocNumber = "000101";
            invoiceHeader.Msg = "No Black Ink Pens";
            invoiceHeader.Note = "Blue Ink pens only";
            IdType customerId = new IdType();
            customerId.Value = "5";
            invoiceHeader.CustomerId = customerId;
            invoiceHeader.SubTotalAmt = decimal.Parse("200.00");
            invoiceHeader.SubTotalAmtSpecified = true;
            invoiceHeader.TotalAmt = decimal.Parse("298.75");
            invoiceHeader.TotalAmtSpecified = true;
            invoiceHeader.BillEmail = "*****@*****.**";
            invoiceHeader.ItemElementName = ItemChoiceType2.DiscountAmt;
            invoiceHeader.Item = decimal.Parse("-1.25");
            invoiceHeader.TxnDate = DateTime.Parse("2010-08-07");
            invoiceHeader.TxnDateSpecified = true;
            invoiceHeader.DueDate = DateTime.Parse("2010-08-16");
            invoiceHeader.DueDateSpecified = true;
            _invoice.Header = invoiceHeader;

            InvoiceLine invoiceLine = new InvoiceLine();
            invoiceLine.Desc = "Pens";
            invoiceLine.Amount = decimal.Parse("200.00");
            invoiceLine.AmountSpecified = true;
            invoiceLine.Taxable = true;
            invoiceLine.TaxableSpecified = true;
            IdType itemId = new IdType();
            itemId.Value = "4";
            object[] items = new object[3];
            ItemsChoiceType2[] elementNames = new ItemsChoiceType2[3];
            elementNames[0] = ItemsChoiceType2.ItemId;
            items[0] = itemId;
            elementNames[1] = ItemsChoiceType2.UnitPrice;
            items[1] = decimal.Parse("100"); ;
            elementNames[2] = ItemsChoiceType2.Qty;
            items[2] = decimal.Parse("4");

            invoiceLine.ItemsElementName = elementNames;
            invoiceLine.Items = items;

            List<InvoiceLine> lines = new List<InvoiceLine>();
            lines.Add(invoiceLine);

            _invoice.Line = lines.ToArray();
        }
 private Invoice buildDelete(Invoice invoice)
 {
     Invoice delete = new Invoice();
     delete.SyncToken = invoice.SyncToken;
     delete.Id = invoice.Id;
     return delete;
 }
 public Task<Invoice> Update(Invoice invoice)
 {
     IDictionary<string, object> vars = new Dictionary<string, object>(2);
     vars.Add("companyId", this.companyId);
     vars.Add("invoiceID", invoice.Id.Value);
     return this.restTemplate.PostForObjectAsync<Invoice>("/resource/invoice/v2/{companyId}/{invoiceID}", invoice, vars);
 }
 public Task<Invoice> Create(Invoice invoice)
 {
     IDictionary<string, object> vars = new Dictionary<string, object>(1);
     vars.Add("companyId", this.companyId);
     return this.restTemplate.PostForObjectAsync<Invoice>("/resource/invoice/v2/{companyId}", invoice, vars);
 }