diff --git a/Project/adminBlazor/adminBlazor/Models/User.cs b/Project/adminBlazor/adminBlazor/Models/User.cs index 2e51cc3..623623d 100644 --- a/Project/adminBlazor/adminBlazor/Models/User.cs +++ b/Project/adminBlazor/adminBlazor/Models/User.cs @@ -1,17 +1,33 @@ -namespace adminBlazor.Models +using System.ComponentModel.DataAnnotations; + +namespace adminBlazor.Models { public class User { - public int id { get; set; } - public string password { get; set; } - public string email { get; set; } - public string name { get; set; } - public string surname { get; set; } - public string nickname { get; set; } - public string image { get; set; } - public bool extraTime { get; set; } - public int group { get; set; } - public string[] roles { get; set; } + [Required] + public int Id { get; set; } + + [StringLength(50, ErrorMessage = "Name length can't be more than 50.")] + public string Password { get; set; } + + [EmailAddress] + public string Email { get; set; } + + [StringLength(50, ErrorMessage = "Name length can't be more than 50.")] + public string Name { get; set; } + + [StringLength(50, ErrorMessage = "Name length can't be more than 50.")] + public string Surname { get; set; } + + [StringLength(50, ErrorMessage = "Name length can't be more than 50.")] + public string Nickname { get; set; } + + [StringLength(50, ErrorMessage = "Name length can't be more than 50.")] + public string Image { get; set; } + + public bool ExtraTime { get; set; } + public int Group { get; set; } + public string[] Roles { get; set; } } } diff --git a/Project/adminBlazor/adminBlazor/Pages/Add.razor b/Project/adminBlazor/adminBlazor/Pages/Add.razor new file mode 100644 index 0000000..8ecc02a --- /dev/null +++ b/Project/adminBlazor/adminBlazor/Pages/Add.razor @@ -0,0 +1,52 @@ +@page "/add" + +

Add

+ + + + + +

+ +

+

+ +

+

+ +

+

+ Roles categories: +

+ @foreach (var item in roles) + { + + } +
+

+

+ +

+

+ +

+ + +
diff --git a/Project/adminBlazor/adminBlazor/Pages/Add.razor.cs b/Project/adminBlazor/adminBlazor/Pages/Add.razor.cs new file mode 100644 index 0000000..e111326 --- /dev/null +++ b/Project/adminBlazor/adminBlazor/Pages/Add.razor.cs @@ -0,0 +1,98 @@ +using Blazored.LocalStorage; +using Microsoft.AspNetCore.Components.Forms; +using Microsoft.AspNetCore.Components; +using adminBlazor.Models; + +namespace adminBlazor.Pages +{ + public partial class Add + { + [Inject] + public ILocalStorageService LocalStorage { get; set; } + + [Inject] + public IWebHostEnvironment WebHostEnvironment { get; set; } + + + /// + /// The default enchant categories. + /// + private List roles = new List() { "admin","teacher","student" }; + + + /// + /// The current item model + /// + private User user = new User() + { + Roles = new string[] { "admin", "teacher", "student" } + }; + + private async void HandleValidSubmit() + { + // Get the current data + var currentData = await LocalStorage.GetItemAsync>("data"); + + // Simulate the Id + user.Id = currentData.Max(s => s.Id) + 1; + + // Add the item to the current data + currentData.Add(new User + { + Id = user.Id, + Name = user.Name, + Surname = user.Surname, + Nickname = user.Nickname, + ExtraTime = user.ExtraTime, + Image = user.Image, + Group = user.Group, + Password = user.Password, + Email = user.Email, + Roles = user.Roles + }); + + // Save the image + var imagePathInfo = new DirectoryInfo($"{WebHostEnvironment.WebRootPath}/images"); + + // Check if the folder "images" exist + if (!imagePathInfo.Exists) + { + imagePathInfo.Create(); + } + + // Determine the image name + var fileName = new FileInfo($"{imagePathInfo}/{user.Name}.png"); + + // Write the file content + //await File.WriteAllBytesAsync(fileName.FullName, users.Image); + + // Save the data + await LocalStorage.SetItemAsync("data", currentData); + } + /* + private async Task LoadImage(InputFileChangeEventArgs e) + { + // Set the content of the image to the model + using (var memoryStream = new MemoryStream()) + { + await e.File.OpenReadStream().CopyToAsync(memoryStream); + user.Image = memoryStream.ToArray(); + } + } + */ + /* + private void OnEnchantCategoriesChange(string item, object checkedValue) + { + if ((bool)checkedValue) + { + if (!user.Roles.Contains(item)) + { + user.Roles.Add(item); + } + + return; + } + } + */ + } +} \ No newline at end of file diff --git a/Project/adminBlazor/adminBlazor/Pages/List.razor b/Project/adminBlazor/adminBlazor/Pages/List.razor index b7a2e4a..d04a016 100644 --- a/Project/adminBlazor/adminBlazor/Pages/List.razor +++ b/Project/adminBlazor/adminBlazor/Pages/List.razor @@ -22,18 +22,18 @@ PageSize="10" ShowPager Responsive> - - - - - - - - - - + + + + + + + + + + - @(string.Join(", ", ((User)context).roles)) + @(string.Join(", ", ((User)context).Roles))