예제 #1
0
        /// <summary>
        /// Creates an invoice comment.
        /// </summary>
        /// <param name="value">The invoice comment.</param>
        /// <param name="token">The cancellation token.</param>
        /// <returns>
        /// A task that represents the asynchronous operation.
        /// The task result returns the newly created invoice comment 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 <InvoiceComment> CreateCommentAsync(InvoiceComment value, CancellationToken token = default)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }
            if (value.InvoiceId == 0 || string.IsNullOrEmpty(value.Comment) || value.Id != 0)
            {
                throw new ArgumentException("invalid property values for invoice comment", nameof(value));
            }
            var wrappedModel = new InvoiceCommentWrapper
            {
                InvoiceComment = value.ToApi()
            };

            try
            {
                var result = await PostAsync("/api/invoice-comments", 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);
                }
        }
 internal static InvoiceComment ToDomain(this InvoiceCommentWrapper value)
 {
     return(s_invoiceCommentMapper.ApiToDomain(value));
 }
예제 #3
0
 public InvoiceComment ApiToDomain(InvoiceCommentWrapper value)
 {
     return(ApiToDomain(value?.InvoiceComment));
 }