I have an app that has an entity entitled, "Invoice". Within the Invoice entity, I have a reference to a collection for another entity entitled, "InvoiceLine".
I am using SyncFusion's DataGrid along with DataManager to perform CRUD operations. When I click on an invoice in the datagrid, it displays a component containing the relevant information. The invoice contains an invoice line component. When I make a change to an invoice line, the UI reflects the changes. I have also verified that the invoice line within the invoice line collection within the invoice reflects the changes.
The issues is when I click save, the changes are not carried through to the controller on the server-side.
// relevant line within the invoice entity class
// Navigation property
public List<InvoiceLine>? InvoiceLines
{
get => GetPropertyValue<List<InvoiceLine>?>();
set => SetPropertyValue(value);
}
// invoice data manager class
namespace AccountsReceivable.Client.DataAdaptor
{
public class InvoicesDataManager : SfDataManager
{
private IServerApiService _serverApiService = default!;
[Inject]
private IServerApiService ServerApiService
{
get => _serverApiService;
set
{
if (_serverApiService != value)
{
_serverApiService = value;
OnServerApiServiceChanged();
}
}
}
public InvoicesDataManager()
{
Adaptor = Syncfusion.Blazor.Adaptors.ODataV4Adaptor;
this.EnableCaching = true;
}
// Set data manager url values
private void OnServerApiServiceChanged()
{
// main url
const string apiUrl = "api/Invoices";
// Instantiate http instance
HttpClientInstance = ServerApiService.HttpClientInstance;
// Set base url
Url = ServerApiService.GetApiUrl(apiUrl);
// Set saving url
UpdateUrl = ServerApiService.GetApiUrl($"{apiUrl}/save");
// Set deletion url
RemoveUrl = ServerApiService.GetApiUrl($"{apiUrl}/delete");
}
protected override void OnInitialized()
{
OnServerApiServiceChanged();
base.OnInitialized();
}
}
}
// Controller code...the values argument contains the changes that have been made.
// PATCH: api/invoices/save
[HttpPatch("save({invoiceId})")]
[AuthorizeScope(AuthorizationScope.UpdateInvoice)]
public async Task<ActionResult> Patch([FromRoute] int invoiceId, [FromBody] IDictionary<string, JsonDocument>? values, CancellationToken ct)
{
try
{
Invoice? invoice = await _invoiceDataProvider.GetItemAsync(invoiceId);
if (invoice != null)
{
values?.Patch(invoice);
await _invoiceDataProvider.SaveAsync(invoice);
}
return Ok(ApiResponse.OkResponse(invoice));
}
catch (Exception ex)
{
_logger.LogError(ex, "Invoice Error");
return BadRequest(new ApiResponse(ApiStatusCodes.UnhandledError, ex.Message));
}
}