114 lines
3.3 KiB
C#
114 lines
3.3 KiB
C#
using LY.App.Model;
|
|
using LY.App.Service;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace LY.App.Controllers
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class UserController : ControllerBase
|
|
{
|
|
private readonly UserService _userService;
|
|
public UserController(UserService userService)
|
|
{
|
|
_userService = userService;
|
|
}
|
|
#region 增删改查
|
|
[HttpPost("add")]
|
|
public async Task<IActionResult> Add(AddUser input)
|
|
{
|
|
var result = await _userService.Add(input);
|
|
return Ok(result);
|
|
}
|
|
/// <summary>
|
|
/// 列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet("list")]
|
|
public async Task<IActionResult> GetList(int pageSize = 10, int pageNum = 1, string key = "")
|
|
{
|
|
var result = await _userService.GetPage(pageSize, pageNum, key);
|
|
return Ok(new ApiResult() { data = result });
|
|
}
|
|
/// <summary>
|
|
/// 删除
|
|
/// </summary>
|
|
/// <param name="ids"></param>
|
|
/// <returns></returns>
|
|
[HttpDelete("remove")]
|
|
public async Task<IActionResult> Delete(IEnumerable<long> ids)
|
|
{
|
|
var result = await _userService.SoftDelete(ids);
|
|
return Ok(new ApiResult()
|
|
{
|
|
code = string.IsNullOrEmpty(result) ? 0 : 1,
|
|
msg = result
|
|
});
|
|
}
|
|
/// <summary>
|
|
/// 更新用户对象
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("update")]
|
|
public async Task<IActionResult> Update(UpdateUser input)
|
|
{
|
|
var result = await _userService.Update(input);
|
|
return Ok(new ApiResult()
|
|
{
|
|
code = string.IsNullOrEmpty(result) ? 0 : 1,
|
|
msg = result,
|
|
});
|
|
}
|
|
/// <summary>
|
|
/// 更新密码
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("updatepwd")]
|
|
public async Task<IActionResult> updatepwd(UpdatePwdDto input)
|
|
{
|
|
var result = await _userService.UpdatePwd(input);
|
|
return Ok(new ApiResult()
|
|
{
|
|
code = string.IsNullOrEmpty(result) ? 0 : 1,
|
|
msg = result
|
|
});
|
|
}
|
|
[HttpGet("detail")]
|
|
public async Task<IActionResult> Detail(long id)
|
|
{
|
|
var result = await _userService.GetUserById(id);
|
|
if (result == null)
|
|
{
|
|
return Ok(new ApiResult()
|
|
{
|
|
code = 0,
|
|
data = { },
|
|
msg = ""
|
|
});
|
|
}
|
|
else
|
|
{
|
|
return Ok(new ApiResult()
|
|
{
|
|
code = 0,
|
|
data = result,
|
|
msg = ""
|
|
});
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
#region 登陆
|
|
[HttpPost("login")]
|
|
public async Task<IActionResult> Login(LoginModel input)
|
|
{
|
|
var result = await _userService.Login(input);
|
|
return Ok(result);
|
|
}
|
|
#endregion
|
|
}
|
|
}
|