I'm not picking up on what you're saying...
I've found the problem but I don't have the solution.
As you know, I use the Radzen
library;
I use RadzenDataGrid
in the inline editing mode, I based my code according to https://blazor.radzen.com/datagrid-inline-edit
In this case I need to configure DataRadzenGrid
as follows
<RadzenDataGrid @ref="gridprojet" AEditMode="DataGridEditMode.Single"
Data="@projet" TItem="ProjetModel" RowUpdate="@OnUpdateRow" …>
….
</RadzenDataGridColumn>
<EditTemplate Context="projet">
<RadzenButton Icon="check" ButtonStyle="ButtonStyle.Success"
Variant="Variant.Flat" Size="ButtonSize.Medium" Click="@(args =>
SaveRow(projet))">
</EditTemplate>
</RadzenDataGridColumn>
I've defined OnUpdateRow
as below :
async Task OnUpdateRow(ProjetModel newRow)
{
// Reset();
var response = await client.PutAsJsonAsync("api/projetbe", newRow);
if (response.StatusCode == System.Net.HttpStatusCode.BadRequest)
{
ErrorResponseDictionary = new Dictionary<string, List<string>>();
ErrorResponseDictionary = await response.Content.ReadFromJsonAsync<Dictionary<string, List<string>>>();
projetBEToUpdate = null;
return;
}
else
{
projetBEToUpdate = null;
return;
await OnInitializedAsync();
}
}
I've defined a put method as below :
[HttpPut]
public async Task<IActionResult> Put(ProjetModel projetModel)
{
_context.Entry(projetModel).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException ex)
{
//throw;
var exceptionEntry = ex.Entries.Single();
var clientValues = (ProjetModel)exceptionEntry.Entity;
var databaseEntry = exceptionEntry.GetDatabaseValues();
var dbValues = (ProjetModel)databaseEntry.ToObject();
await SetDbErrorMessage(dbValues, clientValues);
projetModel.ConcurrencyToken = (byte[])dbValues.ConcurrencyToken;
ModelState.Remove($"{nameof(projetModel)}.{nameof(projetModel.ConcurrencyToken)}");
return BadRequest(ModelState);
}
return NoContent();
}
I've defined SaveRow
as below
async Task SaveRow(ProjetModel suivi)
{
await gridprojet.UpdateRow(suivi);
}
In this configuration I obtain
But in this case, it's NOK because if the user makes two changes to the same page, he gets an error message and that's not what I want.
I think the problem lies in the configuration of inLine Mode of the RadzenDataGRid
The UpdateRow
in SaveRow
is defined as below (from VS when reach the definition from RadzenDataGrid)
// Résumé :
// Updates the row.
//
// Paramètres :
// item:
// The item.
public async Task UpdateRow(TItem item)
{
if (!editedItems.Keys.Any((TItem i) => ItemEquals(i, item)))
{
return;
}
if (editContexts[item].Validate())
{
editedItems.Remove(item);
editContexts.Remove(item);
if (!object.Equals(itemToInsert, item))
{
await RowUpdate.InvokeAsync(item);
}
else
{
await RowCreate.InvokeAsync(item);
itemToInsert = default(TItem);
}
}
StateHasChanged();
}
You can see that the RowUpdate
is invoked. This function is implemented is RadzenDataGRid
If I want to implement Handling concurrency in RadzenDataGRid
I have to call the put method twice to avoid receiving the message handling concurrency errors when the one user makes two modification in the same page.
here's where I am!