Merge branch 'develop' of Tiamo/UserPointManagement into master
commit
6b885a0c3e
|
|
@ -11,6 +11,8 @@ public interface IUserPointService
|
|||
Task<PageResultDto<UserPointDto>> GetUserPoints(GetUserPointDto req);
|
||||
|
||||
Task CreateUserPoint(CreateUserPointDto input);
|
||||
|
||||
Task DeletePoint(long userPointId);
|
||||
}
|
||||
|
||||
public class UserPointService : IUserPointService
|
||||
|
|
@ -36,8 +38,10 @@ 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.Paging(req).ToListAsync().ConfigureAwait(false);
|
||||
var data = await queryable.OrderByDescending(x => x.CreateTime).Paging(req).ToListAsync().ConfigureAwait(false);
|
||||
|
||||
return new PageResultDto<UserPointDto>()
|
||||
{
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -35,8 +35,11 @@ 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.Paging(req).ToListAsync().ConfigureAwait(false);
|
||||
var data = await queryable.OrderByDescending(x => x.Id).Paging(req).ToListAsync().ConfigureAwait(false);
|
||||
|
||||
return new PageResultDto<User>()
|
||||
{
|
||||
|
|
@ -60,6 +63,15 @@ public class UserService : IUserService
|
|||
public async Task CreateUser(User input)
|
||||
{
|
||||
await using var _userPointManagementDbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||
if (_userPointManagementDbContext.Users.Any(x => x.Mobile == input.Mobile))
|
||||
{
|
||||
throw new ArgumentException("手机号不可重复!");
|
||||
}
|
||||
|
||||
if (_userPointManagementDbContext.Users.Any(x => x.Name == input.Name))
|
||||
{
|
||||
throw new ArgumentException("名称不可重复!");
|
||||
}
|
||||
_userPointManagementDbContext.Users.Add(input);
|
||||
await _userPointManagementDbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
Path = "/user-point",
|
||||
Name = "用户积分",
|
||||
Key = "user-point",
|
||||
Icon = "smile",
|
||||
Icon = "unordered-list",
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
@using global::UserPointManagement.Model.Entities
|
||||
@inject IJSRuntime JS
|
||||
@inject IUserService UserService;
|
||||
@inject MessageService Message
|
||||
|
||||
<PageContainer Title="用户管理">
|
||||
<GridRow Style="margin: 10px 0">
|
||||
|
|
@ -84,13 +85,14 @@
|
|||
<Form Loading="loading" Model="@model"
|
||||
LabelColSpan="8"
|
||||
WrapperColSpan="16"
|
||||
ValidateMode=@FormValidateMode.Rules
|
||||
OnFinish="OnFinish"
|
||||
OnFinishFailed="OnFinishFailed"
|
||||
@ref="@_form">
|
||||
<FormItem Label="姓名">
|
||||
<FormItem Label="姓名" Rules=@(new FormValidationRule[] { new FormValidationRule { Required = true, Message = "名称不可为空!" }, new FormValidationRule() { Len = 50, Message = "名称上限50字" } })>
|
||||
<Input @bind-Value="@context.Name"/>
|
||||
</FormItem>
|
||||
<FormItem Label="手机号">
|
||||
<FormItem Label="手机号" Rules="@(new FormValidationRule[] { new FormValidationRule { Type = FormFieldType.Regexp, Pattern = @"^1\d{10}$", Message = "请输入正确手机号", Required = true } })">
|
||||
<Input @bind-Value="@context.Mobile"/>
|
||||
</FormItem>
|
||||
</Form>
|
||||
|
|
@ -102,7 +104,6 @@
|
|||
|
||||
public class Model
|
||||
{
|
||||
[Required]
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Mobile { get; set; }
|
||||
|
|
@ -148,10 +149,9 @@
|
|||
/// <summary>
|
||||
/// when form is submited, close the modal
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
/// <param name="editContext"></param>
|
||||
private void OnFinish(EditContext editContext)
|
||||
{
|
||||
Console.WriteLine("e");
|
||||
_visible = false;
|
||||
}
|
||||
|
||||
|
|
@ -161,13 +161,26 @@
|
|||
/// <param name="e"></param>
|
||||
private async Task HandleOk(MouseEventArgs e)
|
||||
{
|
||||
_form.Submit();
|
||||
await UserService.CreateUser(new User()
|
||||
if (_form.Validate())
|
||||
{
|
||||
Name = model.Name,
|
||||
Mobile = model.Mobile
|
||||
}).ConfigureAwait(false);
|
||||
await RefreshTable().ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
await UserService.CreateUser(new User()
|
||||
{
|
||||
Name = model.Name,
|
||||
Mobile = model.Mobile
|
||||
}).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
await Message.Error(exception.Message);
|
||||
}
|
||||
_visible = false;
|
||||
model.Mobile = string.Empty;
|
||||
model.Name = string.Empty;
|
||||
await RefreshTable().ConfigureAwait(false);
|
||||
await Message.Success("保存成功!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -11,7 +11,8 @@ namespace UserPointManagement.Web.Pages.UserManagement;
|
|||
|
||||
public class UserManagementBase : ComponentBase
|
||||
{
|
||||
[Inject] private IUserService _userService { get; set; }
|
||||
[Inject] private IUserService UserService { get; set; }
|
||||
[Inject] private MessageService MessageService { get; set; }
|
||||
|
||||
protected IDictionary<int, (bool edit, User data)> editCache =
|
||||
new Dictionary<int, (bool edit, User data)>();
|
||||
|
|
@ -38,7 +39,7 @@ public class UserManagementBase : ComponentBase
|
|||
protected async Task RefreshTable()
|
||||
{
|
||||
_loading = true;
|
||||
var res = await _userService.GetUsers(new GetUserDto()
|
||||
var res = await UserService.GetUsers(new GetUserDto()
|
||||
{
|
||||
Keyword = _searchValue,
|
||||
PageIndex = _pageIndex,
|
||||
|
|
@ -72,7 +73,8 @@ public class UserManagementBase : ComponentBase
|
|||
|
||||
protected async Task Delete(int userId)
|
||||
{
|
||||
await _userService.DeleteUser(userId).ConfigureAwait(false);
|
||||
await UserService.DeleteUser(userId).ConfigureAwait(false);
|
||||
await MessageService.Success("删除成功!");
|
||||
await RefreshTable();
|
||||
}
|
||||
|
||||
|
|
@ -92,7 +94,7 @@ public class UserManagementBase : ComponentBase
|
|||
{
|
||||
var index = _users.FindIndex(item => item.Id == id);
|
||||
_users[index] = editCache[id].data; // apply the copy to data source
|
||||
await _userService.ModifyUser(editCache[id].data.Id, new ModifyUserDto()
|
||||
await UserService.ModifyUser(editCache[id].data.Id, new ModifyUserDto()
|
||||
{
|
||||
Mobile = editCache[id].data.Mobile,
|
||||
Name = editCache[id].data.Name,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
<PageContainer Title="用户积分管理">
|
||||
<PageContainer Title="用户积分明细">
|
||||
<GridRow Style="margin: 10px 0">
|
||||
<GridCol Span="12">
|
||||
<Space Direction="@DirectionVHType.Horizontal">
|
||||
|
|
@ -45,7 +45,14 @@
|
|||
OnPageSizeChange="OnPageSizeChange">
|
||||
<PropertyColumn Property="c => c.Name" title="用户姓名"/>
|
||||
<PropertyColumn Property="c => c.Point" title="积分"/>
|
||||
<PropertyColumn Property="c => c.CreateTime" title="新增时间" Format="yyyy-MM-dd hh:mm"/>
|
||||
<PropertyColumn Property="c => c.CreateTime" title="新增时间" Format="yyyy-MM-dd HH:mm"/>
|
||||
<ActionColumn Title="操作" Width="220">
|
||||
<Space Size=@("middle")>
|
||||
<SpaceItem>
|
||||
<Button Danger OnClick="()=>Delete(context.UserPointId)">删除</Button>
|
||||
</SpaceItem>
|
||||
</Space>
|
||||
</ActionColumn>
|
||||
</Table>
|
||||
</PageContainer>
|
||||
|
||||
|
|
@ -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<UserPointDto> _userPoints;
|
||||
protected List<UserDto> _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();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue