|
|
@ -12,45 +12,18 @@ Ouvrez le fichier `Pages/Add.razor.cs` et ajouter les lignes en surbrillances :
|
|
|
|
```csharp title="Pages/Add.razor.cs"
|
|
|
|
```csharp title="Pages/Add.razor.cs"
|
|
|
|
public partial class Add
|
|
|
|
public partial class Add
|
|
|
|
{
|
|
|
|
{
|
|
|
|
[Inject]
|
|
|
|
...
|
|
|
|
public ILocalStorageService LocalStorage { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// highlight-start
|
|
|
|
// highlight-start
|
|
|
|
[Inject]
|
|
|
|
[Inject]
|
|
|
|
public NavigationManager NavigationManager { get; set; }
|
|
|
|
public NavigationManager NavigationManager { get; set; }
|
|
|
|
// highlight-end
|
|
|
|
// highlight-end
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
...
|
|
|
|
/// The default roles.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
private List<string> roles = new List<string>() { "admin", "writter", "reader", "member" };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// The current data model
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
private DataModel dataModel = new()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
DateOfBirth = DateTime.Now,
|
|
|
|
|
|
|
|
Roles = new List<string>()
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async void HandleValidSubmit()
|
|
|
|
private async void HandleValidSubmit()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Get the current data
|
|
|
|
...
|
|
|
|
var currentData = await LocalStorage.GetItemAsync<List<Data>>("data");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Simulate the Id
|
|
|
|
|
|
|
|
dataModel.Id = currentData.Max(s => s.Id) + 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add the item to the current data
|
|
|
|
|
|
|
|
currentData.Add(new Data
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
LastName = dataModel.LastName,
|
|
|
|
|
|
|
|
DateOfBirth = dataModel.DateOfBirth,
|
|
|
|
|
|
|
|
FirstName = dataModel.FirstName,
|
|
|
|
|
|
|
|
Id = dataModel.Id,
|
|
|
|
|
|
|
|
Roles = dataModel.Roles
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Save the data
|
|
|
|
// Save the data
|
|
|
|
await LocalStorage.SetItemAsync("data", currentData);
|
|
|
|
await LocalStorage.SetItemAsync("data", currentData);
|
|
|
@ -58,24 +31,6 @@ public partial class Add
|
|
|
|
// highlight-next-line
|
|
|
|
// highlight-next-line
|
|
|
|
NavigationManager.NavigateTo("list");
|
|
|
|
NavigationManager.NavigateTo("list");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnRoleChange(string item, object checkedValue)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if ((bool)checkedValue)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!dataModel.Roles.Contains(item))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
dataModel.Roles.Add(item);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (dataModel.Roles.Contains(item))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
dataModel.Roles.Remove(item);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|