/// <summary> /// Gets paged list of invoices. /// </summary> /// <param name="page">The page number.</param> /// <param name="type">The invoice type.</param> /// <param name="status">The invoice status.</param> /// <param name="subjectId">The customer subject id.</param> /// <param name="since">The date since when the invoice was created.</param> /// <param name="number">The invoice display number.</param> /// <returns> /// List of <see cref="JsonInvoice" /> instances. /// </returns> /// <exception cref="System.ArgumentOutOfRangeException"> /// page;Value must be greater than zero. /// or /// subjectId;Value must be greater than zero. /// </exception> public IEnumerable <JsonInvoice> Select(int page, InvoiceTypeCondition type = InvoiceTypeCondition.Any, InvoiceStatusCondition status = InvoiceStatusCondition.Any, int?subjectId = null, DateTime?since = null, string number = null) { try { return(this.SelectAsync(page, type, status, subjectId, since, number).Result); } catch (AggregateException aex) { throw aex.InnerException; } }
/// <summary> /// Gets asynchronously paged list of invoices. /// </summary> /// <param name="page">The page number.</param> /// <param name="type">The invoice type.</param> /// <param name="status">The invoice status.</param> /// <param name="subjectId">The customer subject id.</param> /// <param name="since">The date since when the invoice was created.</param> /// <param name="number">The invoice display number.</param> /// <returns> /// List of <see cref="JsonInvoice" /> instances. /// </returns> /// <exception cref="System.ArgumentOutOfRangeException"> /// page;Value must be greater than zero. /// or /// subjectId;Value must be greater than zero. /// </exception> public async Task <IEnumerable <JsonInvoice> > SelectAsync(int page, InvoiceTypeCondition type = InvoiceTypeCondition.Any, InvoiceStatusCondition status = InvoiceStatusCondition.Any, int?subjectId = null, DateTime?since = null, string number = null) { if (page < 1) { throw new ArgumentOutOfRangeException(nameof(page), "Value must be greater than zero."); } if (subjectId.HasValue && subjectId.Value < 1) { throw new ArgumentOutOfRangeException(nameof(subjectId), "Value must be greater than zero."); } // Get URI based on invoice type string uri; switch (type) { case InvoiceTypeCondition.Proforma: uri = "invoices/proforma.json"; break; case InvoiceTypeCondition.Regular: uri = "invoices/regular.json"; break; default: uri = "invoices.json"; break; } // Get status string based string statusString = null; switch (status) { case InvoiceStatusCondition.Open: statusString = "open"; break; case InvoiceStatusCondition.Sent: statusString = "sent"; break; case InvoiceStatusCondition.Overdue: statusString = "overdue"; break; case InvoiceStatusCondition.Paid: statusString = "paid"; break; case InvoiceStatusCondition.Cancelled: statusString = "cancelled"; break; } // Prepare query parameters var queryParams = new { status = statusString, subject_id = subjectId.HasValue ? subjectId.Value.ToString() : null, since, number }; // Get entities return(await base.GetPagedEntitiesAsync <JsonInvoice>(uri, page)); }
/// <summary> /// Gets list of invoiced, paged by 10. /// </summary> /// <param name="page">The page number.</param> /// <param name="type">The invoice type.</param> /// <param name="status">The invoice status.</param> /// <param name="subjectId">The customer subject id.</param> /// <param name="since">The date since when the invoice was created.</param> /// <param name="number">The invoice display number.</param> /// <returns> /// List of <see cref="JsonInvoice" /> instances. /// </returns> /// <exception cref="System.ArgumentOutOfRangeException"> /// page;Value must be greater than zero. /// or /// subjectId;Value must be greater than zero. /// </exception> public IEnumerable<JsonInvoice> Select(int page, InvoiceTypeCondition type = InvoiceTypeCondition.Any, InvoiceStatusCondition status = InvoiceStatusCondition.Any, int? subjectId = null, DateTime? since = null, string number = null) { if (page < 1) throw new ArgumentOutOfRangeException("page", "Value must be greater than zero."); if (subjectId.HasValue && subjectId.Value < 1) throw new ArgumentOutOfRangeException("subjectId", "Value must be greater than zero."); // Get URI based on invoice type string uri; switch (type) { case InvoiceTypeCondition.Proforma: uri = "invoices/proforma.json"; break; case InvoiceTypeCondition.Regular: uri = "invoices/regular.json"; break; default: uri = "invoices.json"; break; } // Get status string based string statusString = null; switch (status) { case InvoiceStatusCondition.Open: statusString = "open"; break; case InvoiceStatusCondition.Sent: statusString = "sent"; break; case InvoiceStatusCondition.Overdue: statusString = "overdue"; break; case InvoiceStatusCondition.Paid: statusString = "paid"; break; case InvoiceStatusCondition.Cancelled: statusString = "cancelled"; break; } // Prepare query parameters var queryParams = new { status = statusString, subject_id = subjectId.HasValue ? subjectId.Value.ToString() : null, since = since, number = number }; // Get entities return base.GetPagedEntities<JsonInvoice>(uri, page); }