using Microsoft.AspNetCore.Mvc;
using QM.AuthServer.IRepository;
using QM.AuthServer.Models.Roles;
using QM.AuthServer.Models.Users;
using QM.OrmSqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WS;
using WS.AutoMapper;
using WS.Orm;
using WS.Security;
using WS.Web.Auth;
using WS.WebCore.Api;
namespace QM.Gateway.Controllers
{
///
/// 部门
///
public class DepartmentController : BaseApiController
{
private readonly ISysDepartmentRepository _ISysDepartmentRepository;
public DepartmentController(
ISysDepartmentRepository ISysDepartmentRepository
)
{
_ISysDepartmentRepository = ISysDepartmentRepository;
}
#region 查询
///
/// 分页查询
///
/// 查询条件
///
[HttpGet]
public async Task GetPage([FromQuery] DepartmentPageDto input)
{
var query = _ISysDepartmentRepository.Query();
if (!string.IsNullOrWhiteSpace(input.name))
query.Where(t => t.name.Contains(input.name));
var page = await query.OrderBy(t => t.name).ToPageAsync(input.page, input.limit);
page.Data = (page.Data as List).MapTo();
return page;
}
///
/// 按编码获取
///
/// 编码
///
[HttpGet]
public async Task GetById(string id)
{
var model = _ISysDepartmentRepository.CheckId(id).MapTo();
model.posts = (await _ISysDepartmentRepository.DbClient()
.Queryable().Where(t => t.gid == id).ToListAsync())
.MapTo();
return model;
}
#endregion
#region 添加或修改
///
/// 添加
///
///
[HttpPost]
public async Task Create(DepartmentInputDto input)
{
return await _ISysDepartmentRepository.Create(input, AuthUser.Uid);
}
///
/// 修改
///
///
[HttpPost]
public async Task Update(DepartmentUpdateDto input)
{
return await _ISysDepartmentRepository.Update(input, AuthUser.Uid);
}
#endregion
#region 删除
///
/// 删除
///
///
///
[HttpPost]
public async Task Delete(string id)
{
return await _ISysDepartmentRepository.Delete(id);
}
#endregion
}
}