/// <summary> /// Creates an invoice tag. /// </summary> /// <param name="value">The invoice tag.</param> /// <param name="token">The cancellation token.</param> /// <returns> /// A task that represents the asynchronous operation. /// The task result returns the newly created invoice tag with the ID. /// </returns> /// <exception cref="ArgumentException">Thrown when the parameter check fails.</exception> /// <exception cref="NotAuthorizedException">Thrown when not authorized to access this resource.</exception> /// <exception cref="NotFoundException">Thrown when the resource url could not be found.</exception> public async Task <InvoiceTag> CreateTagAsync(InvoiceTag value, CancellationToken token = default) { if (value == null) { throw new ArgumentNullException(nameof(value)); } if (value.InvoiceId == 0 || string.IsNullOrEmpty(value.Name) || value.Id != 0) { throw new ArgumentException("invalid property values for invoice payment", nameof(value)); } var wrappedModel = new InvoiceTagWrapper { InvoiceTag = value.ToApi() }; try { var result = await PostAsync("/api/invoice-tags", wrappedModel, token); return(result.ToDomain()); } catch (WebException wex) when(wex.Status == WebExceptionStatus.ProtocolError && (wex.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.BadRequest) { throw new ArgumentException("wrong input parameter", nameof(value), wex); } }
public InvoiceTag ApiToDomain(InvoiceTagWrapper value) { return(ApiToDomain(value?.InvoiceTag)); }
internal static InvoiceTag ToDomain(this InvoiceTagWrapper value) { return(s_invoiceTagMapper.ApiToDomain(value)); }