public void UpdateInvoice_NullableProperties(int invoiceId) { // Entity's properties which can be null are of NullableProperty<T> type in order to distinguish // between non-changing the property value and explicit setting to null. var secondRow = new IssuedInvoiceItemPatchModel { Id = GetSecondRowId(invoiceId) }; // At this point, properties DiscountPercentage, PriceListItemId and VatCodeId wouldn't be changed in iDoklad - their IsSet // property contains false. // Explicit set VatCodeId of last row to null - no explicit conversion to NullableProperty<int> needed. secondRow.VatCodeId = null; // Set DiscountPercentage to 10% - no explicit conversion to NullableProperty<decimal> needed. secondRow.DiscountPercentage = 10m; // In some cases, explicit conversion is required to determine the type of expression result. // Set specific value or null - DiscountPercentage in iDoklad will be changed secondRow.DiscountPercentage = DateTime.Today.DayOfWeek == DayOfWeek.Friday ? (NullableProperty <decimal>) 5 : null; secondRow.DiscountPercentage = DateTime.Today.DayOfWeek == DayOfWeek.Sunday ? new NullableProperty <decimal>(10) : null; // Preserve original value in iDoklad - DiscountPercentage in iDoklad won't be changed secondRow.DiscountPercentage = default; // Property value can be accessed by its Value property or we can use implicit conversion. var discountPercentage1 = secondRow.DiscountPercentage.Value; decimal?discountPercentage2 = secondRow.DiscountPercentage; // Create update model for first row. If we didn't include it in invoice update model, it would be removed. var firstRow = new IssuedInvoiceItemPatchModel { Id = GetFirstRowId(invoiceId) }; // Create invoice update model. var invoiceUpdateModel = new IssuedInvoicePatchModel { Id = invoiceId, Items = new List <IssuedInvoiceItemPatchModel> { firstRow, secondRow } }; // Update the invoice var updatedInvoice = _api.IssuedInvoiceClient.Update(invoiceUpdateModel).Data; }
private IssuedInvoiceItemPatchModel AddPriceListItem(int priceListItemId, int amount) { // Get price list item var priceListItem = GetPriceListItem(priceListItemId); // Create new issued invoice item model. Model is of IssuedInvoiceItemPatchModel because we are updating the invoice. var issuedInvoiceItem = new IssuedInvoiceItemPatchModel { Name = priceListItem.Name, Amount = amount, Code = priceListItem.Code, PriceType = priceListItem.PriceType, UnitPrice = priceListItem.Price, Unit = priceListItem.Unit, VatRateType = priceListItem.VatRateType, PriceListItemId = priceListItem.Id }; return(issuedInvoiceItem); }