using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System; using System.Threading.Tasks; using Znyc.Admin.AspNetCore.Controllers; using Znyc.Admin.AspNetCore.Entitys; using Znyc.Admin.AspNetCore.Mvc; using Znyc.Admin.Commons.Entitys; using Znyc.Admin.Commons.Pages; using Znyc.Admin.Security.Dtos; using Znyc.Admin.Security.Entitys; using Znyc.Admin.Security.IServices; namespace Znyc.Admin.WebApi.Controllers { /// /// 用户 /// [ApiController] [Route("api/Security/[controller]")] public class UserController : AreaApiController { private readonly IUserService _userServices; /// /// 构造函数 /// public UserController( IUserService userServices ) : base(userServices) { _userServices = userServices; } /// /// 新增前处理数据 /// /// protected override void OnBeforeInsert(User info) { info.Id = 0; info.CreatedTime = DateTime.Now; info.CreatedUserId = CurrentUser.UserId; info.IsDeleted = false; } /// /// 在更新数据前对数据的修改操作 /// /// /// protected override void OnBeforeUpdate(User info) { info.CreatedUserId = CurrentUser.UserId; info.ModifiedUserId = CurrentUser.UserId; info.ModifiedTime = DateTime.Now; } /// /// 在软删除数据前对数据的修改操作 /// /// /// protected override void OnBeforeSoftDelete(User info) { info.IsDeleted = true; } /// /// 异步分页查询 /// /// /// [HttpPost("FindWithPagerSearchAsync")] [FunctionAuthorize("List")] [AllowAnonymous] public async Task FindWithPagerSearchAsync(SearchUserModel search) { CommonResult> result = new CommonResult> { ResData = await _userServices.FindWithPagerSearchAsync(search), ErrCode = ErrCode.successCode }; return ToJsonContent(result); } /// /// 修改用户状态 /// /// /// /// [HttpPut("UpdateStatusAsync")] [FunctionAuthorize("")] public async Task UpdateStatusAsync(long id, int status) { CommonResult result = new CommonResult(); result = await _userServices.UpdateStatusAsync(id, status); if (result.Success) { result.ErrCode = ErrCode.successCode; result.ErrMsg = ErrCode.err0; } else { result.ErrMsg = ErrCode.err43002; result.ErrCode = "43002"; } return ToJsonContent(result); } } }