diff --git a/src/UserPointManagement.Application/Services/UserService.cs b/src/UserPointManagement.Application/Services/UserService.cs index fb99556..ab78467 100644 --- a/src/UserPointManagement.Application/Services/UserService.cs +++ b/src/UserPointManagement.Application/Services/UserService.cs @@ -9,6 +9,8 @@ namespace UserPointManagement.Application.Services; public interface IUserService { Task> GetUsers(GetUserDto req); + + Task CreateUser(User input); } public class UserService : IUserService @@ -34,4 +36,10 @@ public class UserService : IUserService TotalCount = count }; } + + public async Task CreateUser(User input) + { + _userPointManagementDbContext.Users.Add(input); + await _userPointManagementDbContext.SaveChangesAsync().ConfigureAwait(false); + } } \ No newline at end of file diff --git a/src/UserPointManagement.Web/Pages/UserManagement/UserManagement.razor b/src/UserPointManagement.Web/Pages/UserManagement/UserManagement.razor new file mode 100644 index 0000000..bddb869 --- /dev/null +++ b/src/UserPointManagement.Web/Pages/UserManagement/UserManagement.razor @@ -0,0 +1,137 @@ +@inherits MyAntDesignAppServer.Pages.UserManagement.UserManagementBase +@page "/" +@using UserPointManagement.Application.Services +@using UserPointManagement.Model.Dtos +@using UserPointManagement.Model.Entities +@using System.ComponentModel.DataAnnotations +@using System.Text.Json +@inject IJSRuntime JS +@inject IUserService UserService; + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + +
+ + + + + + +
+
+ +@code { + + #region original form coding + public class Model + { + [Required] + public string Name { get; set; } + public string Mobile { get; set; } + } + + private Model model = new Model(); + + private void OnFinishFailed(EditContext editContext) + { + Console.WriteLine($"Failed:{JsonSerializer.Serialize(model)}"); + } + + bool loading = false; + + void toggle(bool value) => loading = value; + + #endregion + + #region original modal coding + + bool _visible = false; + + private void ShowModal() + { + _visible = true; + } + + private void HandleCancel(MouseEventArgs e) + { + _visible = false; + } + + #endregion + + /* + * Careful! + * + * next bind submit event to modal OK button + */ + + private Form _form; + + /// + /// when form is submited, close the modal + /// + /// + private void OnFinish(EditContext editContext) + { + Console.WriteLine("e"); + _visible = false; + } + + /// + /// on modal OK button is click, submit form manually + /// + /// + private async Task HandleOk(MouseEventArgs e) + { + _form.Submit(); + await UserService.CreateUser(new User() + { + Name = model.Name, + Mobile = model.Mobile + }).ConfigureAwait(false); + await RefreshTable().ConfigureAwait(false); + } +} \ No newline at end of file diff --git a/src/UserPointManagement.Web/Pages/UserManagement/UserManagement.razor.cs b/src/UserPointManagement.Web/Pages/UserManagement/UserManagement.razor.cs new file mode 100644 index 0000000..91b4586 --- /dev/null +++ b/src/UserPointManagement.Web/Pages/UserManagement/UserManagement.razor.cs @@ -0,0 +1,62 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using AntDesign; +using Microsoft.AspNetCore.Components; +using UserPointManagement.Application.Services; +using UserPointManagement.Model.Dtos; +using UserPointManagement.Model.Entities; + +namespace MyAntDesignAppServer.Pages.UserManagement; + +public class UserManagementBase : ComponentBase +{ + [Inject] private IUserService _userService { get; set; } + + protected List _users; + protected int _pageIndex = 1; + protected int _pageSize = 20; + protected int _total = 0; + protected bool _loading; + private string _searchValue; + + protected override async Task OnInitializedAsync() + { + await RefreshTable(); + } + + protected async Task OnSearch(string arg) + { + _searchValue = arg; + _pageIndex = 1; + await RefreshTable(); + } + + protected async Task RefreshTable() + { + _loading = true; + var res = await _userService.GetUsers(new GetUserDto() + { + Keyword = _searchValue, + PageIndex = _pageIndex, + PageSize = _pageSize + }); + + _users = res.Items; + _total = res.TotalCount; + _loading = false; + } + + protected async Task OnPageIndexChanged(PaginationEventArgs args) + { + _pageIndex = args.Page; + _pageSize = args.PageSize; + await RefreshTable(); + } + + protected async Task OnPageSizeChange(PaginationEventArgs args) + { + _pageIndex = args.Page; + _pageSize = args.PageSize; + await RefreshTable(); + } +} \ No newline at end of file diff --git a/src/UserPointManagement.Web/Pages/Welcome.razor.css b/src/UserPointManagement.Web/Pages/UserManagement/UserManagement.razor.css similarity index 100% rename from src/UserPointManagement.Web/Pages/Welcome.razor.css rename to src/UserPointManagement.Web/Pages/UserManagement/UserManagement.razor.css diff --git a/src/UserPointManagement.Web/Pages/Welcome.razor b/src/UserPointManagement.Web/Pages/Welcome.razor deleted file mode 100644 index 88b2b2c..0000000 --- a/src/UserPointManagement.Web/Pages/Welcome.razor +++ /dev/null @@ -1,82 +0,0 @@ -@page "/" -@using UserPointManagement.Application.Services -@using UserPointManagement.Model.Dtos -@using UserPointManagement.Model.Entities -@inject IUserService _userService; -@inject IJSRuntime JS - - - - - - - - - - - - - - - - - -
-
- -@code { - private List _users; - int _pageIndex = 1; - int _pageSize = 20; - int _total = 0; - bool _loading; - string _searchValue; - - protected override async Task OnInitializedAsync() - { - await RefreshTable(); - } - - private async Task OnSearch(string arg) - { - _searchValue = arg; - _pageIndex = 1; - await RefreshTable(); - } - - private async Task RefreshTable() - { - _loading = true; - var res = await _userService.GetUsers(new GetUserDto() - { - Keyword = _searchValue, - PageIndex = _pageIndex, - PageSize = _pageSize - }); - - _users = res.Items; - _total = res.TotalCount; - _loading = false; - } - - private async Task OnPageIndexChanged(PaginationEventArgs args) - { - _pageIndex = args.Page; - _pageSize = args.PageSize; - await RefreshTable(); - } - - private async Task OnPageSizeChange(PaginationEventArgs args) - { - _pageIndex = args.Page; - _pageSize = args.PageSize; - await RefreshTable(); - } - -} \ No newline at end of file