Exemplo n.º 1
0
        /// <summary>
        /// Create a new debt related to a customer.
        /// </summary>
        /// <param name="debt">The debt to be created. The <see cref="Debt.Number"/>, <see cref="Debt.CustomerId"/>, <see cref="Debt.Type"/>, <see cref="Debt.Date"/> and <see cref="Debt.DueDate"/> fields are mandatory. If it has items (<see cref="Debt.Items"/>) they must have the <see cref="Item.Name"/> field </param>
        /// <returns>The up-to-date created debt.</returns>
        /// <exception cref="IcException">On bad json (sent or received) and when the server rejects the request (conflict, bad request, invalid parameters, etc)</exception>
        /// <exception cref="WebException">On connection or protocol related errors (except for the protocol errors sent by the Invisible Collector)</exception>
        /// <exception cref="IcModelConflictException">When a debt with the same number already exists.</exception>
        public async Task <Debt> SetNewDebtAsync(Debt debt)
        {
            debt.AssertHasMandatoryFields(Debt.NumberName, Debt.CustomerIdName, Debt.TypeName, Debt.DateName,
                                          Debt.DueDateName);
            debt.AssertItemsHaveMandatoryFields(Item.NameName);
            _logger.LogDebug("Making a request to create a new debt with information: {Model}", debt);
            var ret = await MakeRequestAsync <Debt, object>("POST", debt.SendableDictionary, DebtsEndpoint);

            _logger.LogDebug("Created a new debt with the information: {Model}", ret);
            return(ret);
        }