Ajout vocabulaire
continuous-integration/drone/push Build is passing Details

possiblité d'ajouter du vocabulaire et fix de 2/3 bugitos
blazor
Antoine JOURDAIN 1 year ago
parent f414f8c385
commit 50da11c8c1

@ -8,6 +8,8 @@ namespace adminBlazor.Models
[Required]
public int Id { get; set; }
[Required]
[StringLength(50, ErrorMessage = "Name length can't be more than 50.")]
public string Name { get; set; }
public byte[] Image { get; set; }

@ -1,4 +1,4 @@
@page "/add"
@page "/addUser"
@attribute [Authorize(Roles = "admin")]
@using adminBlazor.Models
<h3>Add</h3>

@ -7,7 +7,7 @@ using adminBlazor.Services;
namespace adminBlazor.Pages
{
public partial class Add
public partial class AddUser
{
[Inject]
public NavigationManager NavigationManager { get; set; }

@ -0,0 +1,44 @@
@page "/addVoc"
@attribute [Authorize(Roles = "teacher")]
@using adminBlazor.Models
@using Blazorise.Extensions
<h3>Add Vocabulary List</h3>
<EditForm Model="@voc" OnValidSubmit="@HandleValidSubmit">
<DataAnnotationsValidator />
<ValidationSummary />
<p>
<label for="name">
Name:
<InputText id="name" @bind-Value="voc.Name" />
<ValidationMessage For="@(() => voc.Name)"/>
</label>
</p>
<h4>Words:</h4>
@if (voc.Translations.IsNullOrEmpty() == false)
{
foreach (var word in voc.Translations)
{
{
<div class="word-container">
<label>
First Word:
<InputText @bind-Value="word.FirstWord"/>
</label>
<label>
Second Word:
<InputText @bind-Value="word.SecondWord"/>
</label>
</div>
<button type="button" @onclick="() => RemoveWord(word)">Remove Word</button>
}
}
}
else
{
<p>No words</p>
}
<button type="button" @onclick="AddWord">Add Word</button>
<button type="submit">Submit</button>
</EditForm>

@ -0,0 +1,40 @@
using Blazored.LocalStorage;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components;
using adminBlazor.Models;
using Microsoft.AspNetCore.Mvc.RazorPages;
using adminBlazor.Services;
namespace adminBlazor.Pages
{
public partial class AddVoc
{
[Inject] public NavigationManager NavigationManager { get; set; }
[Inject] public IVocListService VocService { get; set; }
private VocabularyListModel voc = new VocabularyListModel();
private async void HandleValidSubmit()
{
voc.Translations ??= new List<TranslationModel>();
await VocService.Add(voc);
NavigationManager.NavigateTo("voc");
}
private void AddWord()
{
if (voc.Translations == null)
{
voc.Translations = new List<TranslationModel>();
}
voc.Translations.Add(new TranslationModel());
}
private void RemoveWord(TranslationModel word)
{
voc.Translations.Remove(word);
}
}
}

@ -11,7 +11,7 @@
<h3>List</h3>
<div>
<a href="Add" class="btn btn-primary" > <i class="fa fa-plus"></i> Ajouter </a>
<a href="addUser" class="btn btn-primary" > <i class="fa fa-plus"></i> Ajouter </a>
</div>
<DataGrid TItem="User"

@ -10,6 +10,10 @@
<link href="_content/Blazorise.Bootstrap/blazorise.bootstrap.css" rel="stylesheet" />
<h3>Vocabulary Lists</h3>
<div>
<a href="addVoc" class="btn btn-primary" > <i class="fa fa-plus"></i> Ajouter </a>
</div>
<DataGrid TItem="VocabularyList"
Data="@_vocList"
ReadData="@OnReadData"

Loading…
Cancel
Save