diff --git a/src/UserPointManagement.Application/Services/UserPointService.cs b/src/UserPointManagement.Application/Services/UserPointService.cs index 096400b..21489c5 100644 --- a/src/UserPointManagement.Application/Services/UserPointService.cs +++ b/src/UserPointManagement.Application/Services/UserPointService.cs @@ -11,6 +11,8 @@ public interface IUserPointService Task> GetUserPoints(GetUserPointDto req); Task CreateUserPoint(CreateUserPointDto input); + + Task DeletePoint(long userPointId); } public class UserPointService : IUserPointService @@ -36,6 +38,8 @@ public class UserPointService : IUserPointService CreateTime = userPoint.CreateTime }; + queryable = queryable.Where(x => x.UserId == req.UserId, req.UserId.HasValue); + var count = queryable.Count(); var data = await queryable.OrderByDescending(x => x.CreateTime).Paging(req).ToListAsync().ConfigureAwait(false); @@ -52,4 +56,14 @@ public class UserPointService : IUserPointService _userPointManagementDbContext.UserPoints.Add(new UserPoint(input.UserId, input.Point)); await _userPointManagementDbContext.SaveChangesAsync().ConfigureAwait(false); } + + public async Task DeletePoint(long userPointId) + { + await using var _userPointManagementDbContext = await _dbContextFactory.CreateDbContextAsync(); + var userPoint = await _userPointManagementDbContext.UserPoints.FirstOrDefaultAsync(x => x.Id == userPointId) + .ConfigureAwait(false); + + _userPointManagementDbContext.Remove(userPoint); + await _userPointManagementDbContext.SaveChangesAsync().ConfigureAwait(false); + } } \ No newline at end of file diff --git a/src/UserPointManagement.Application/Services/UserService.cs b/src/UserPointManagement.Application/Services/UserService.cs index cf21fd5..b7978ba 100644 --- a/src/UserPointManagement.Application/Services/UserService.cs +++ b/src/UserPointManagement.Application/Services/UserService.cs @@ -35,6 +35,9 @@ public class UserService : IUserService var queryable = from user in _userPointManagementDbContext.Users select user; + queryable = queryable.Where(x => x.Mobile.Contains(req.Keyword) || x.Name.Contains(req.Keyword), + !string.IsNullOrEmpty(req.Keyword)); + var count = queryable.Count(); var data = await queryable.OrderByDescending(x => x.Id).Paging(req).ToListAsync().ConfigureAwait(false); diff --git a/src/UserPointManagement.Web/Layouts/BasicLayout.razor b/src/UserPointManagement.Web/Layouts/BasicLayout.razor index bde0434..12c8fae 100644 --- a/src/UserPointManagement.Web/Layouts/BasicLayout.razor +++ b/src/UserPointManagement.Web/Layouts/BasicLayout.razor @@ -32,7 +32,7 @@ Path = "/user-point", Name = "用户积分", Key = "user-point", - Icon = "smile", + Icon = "unordered-list", } }; diff --git a/src/UserPointManagement.Web/Pages/UserPointPage/UserPointManage.razor b/src/UserPointManagement.Web/Pages/UserPointDetail/UserPointDetail.razor similarity index 91% rename from src/UserPointManagement.Web/Pages/UserPointPage/UserPointManage.razor rename to src/UserPointManagement.Web/Pages/UserPointDetail/UserPointDetail.razor index 6f6adaa..4c5c626 100644 --- a/src/UserPointManagement.Web/Pages/UserPointPage/UserPointManage.razor +++ b/src/UserPointManagement.Web/Pages/UserPointDetail/UserPointDetail.razor @@ -1,4 +1,4 @@ -@inherits UserPointManageBase +@inherits UserPointManagement.Web.Pages.UserPointPage.UserPointDetailBase @page "/user-point" @using System.ComponentModel.DataAnnotations @using System.Text.Json @@ -7,7 +7,7 @@ @using UserPointManagement.Application.Services @inject IUserPointService UserPointService; - + @@ -45,7 +45,14 @@ OnPageSizeChange="OnPageSizeChange"> - + + + + + + + + diff --git a/src/UserPointManagement.Web/Pages/UserPointPage/UserPointManage.razor.cs b/src/UserPointManagement.Web/Pages/UserPointDetail/UserPointDetail.razor.cs similarity index 70% rename from src/UserPointManagement.Web/Pages/UserPointPage/UserPointManage.razor.cs rename to src/UserPointManagement.Web/Pages/UserPointDetail/UserPointDetail.razor.cs index a166375..5d5cc79 100644 --- a/src/UserPointManagement.Web/Pages/UserPointPage/UserPointManage.razor.cs +++ b/src/UserPointManagement.Web/Pages/UserPointDetail/UserPointDetail.razor.cs @@ -9,10 +9,11 @@ using UserPointManagement.Model.Dtos.UserPoint; namespace UserPointManagement.Web.Pages.UserPointPage; -public class UserPointManageBase : ComponentBase +public class UserPointDetailBase : ComponentBase { - [Inject] private IUserPointService _UserPointService { get; set; } - [Inject] private IUserService _UserService { get; set; } + [Inject] private IUserPointService UserPointService { get; set; } + [Inject] private IUserService UserService { get; set; } + [Inject] private MessageService MessageService { get; set; } protected List _userPoints; protected List _users; @@ -24,7 +25,7 @@ public class UserPointManageBase : ComponentBase protected override async Task OnInitializedAsync() { - _users = await _UserService.GetAllUsers().ConfigureAwait(false); + _users = await UserService.GetAllUsers().ConfigureAwait(false); await RefreshTable(); } @@ -38,7 +39,7 @@ public class UserPointManageBase : ComponentBase protected async Task RefreshTable() { _loading = true; - var res = await _UserPointService.GetUserPoints(new GetUserPointDto() + var res = await UserPointService.GetUserPoints(new GetUserPointDto() { UserId = _selectedUserId, PageIndex = _pageIndex, @@ -64,4 +65,11 @@ public class UserPointManageBase : ComponentBase _pageSize = args.PageSize; await RefreshTable(); } + + protected async Task Delete(long userPointId) + { + await UserPointService.DeletePoint(userPointId).ConfigureAwait(false); + await MessageService.Success("删除成功!"); + await RefreshTable(); + } } \ No newline at end of file