71 lines
2.1 KiB
C#
71 lines
2.1 KiB
C#
using Mapster;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using SqlSugar;
|
|
using WGShare.API.Controllers.Basic;
|
|
using WGShare.Domain.DTOs.Tenant;
|
|
using WGShare.Domain.DTOs.User;
|
|
using WGShare.Domain.Entities;
|
|
using WGShare.Domain.FriendlyException;
|
|
using WGShare.Domain.GeneralModel;
|
|
using Yitter.IdGenerator;
|
|
|
|
namespace WGShare.API.Controllers.Backend
|
|
{
|
|
[ApiExplorerSettings(GroupName = "backend")]
|
|
[Route("be/tenant")]
|
|
public class TenantController : BasicController
|
|
{
|
|
private readonly ISqlSugarClient _sqlSugar;
|
|
|
|
public TenantController(ISqlSugarClient sqlSugar)
|
|
{
|
|
_sqlSugar = sqlSugar;
|
|
}
|
|
|
|
|
|
[HttpGet("{id}")]
|
|
public async Task<Tenant> GetSingle([FromRoute] string id)
|
|
{
|
|
return await _sqlSugar.Queryable<Tenant>().FirstAsync(x => x.Id == id);
|
|
}
|
|
|
|
[HttpGet("list")]
|
|
public async Task<List<Tenant>> GetList()
|
|
{
|
|
return await _sqlSugar.Queryable<Tenant>().ToListAsync();
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<bool> Add([FromBody] TenantInputDTO inputDTO)
|
|
{
|
|
var entity = inputDTO.Adapt<Tenant>();
|
|
entity.Id = YitIdHelper.NextId().ToString();
|
|
return await _sqlSugar.Insertable(entity).ExecuteCommandAsync() > 0;
|
|
}
|
|
|
|
[HttpPut]
|
|
public async Task<bool> Modify([FromBody] TenantInputDTO inputDTO)
|
|
{
|
|
var entity = inputDTO.Adapt<Tenant>();
|
|
|
|
|
|
return await _sqlSugar.Updateable(entity)
|
|
.UpdateColumns(x => new { x.TenantName }).ExecuteCommandAsync() > 0;
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<bool> Delete([FromQuery] string id, [FromQuery] bool enable)
|
|
{
|
|
return await _sqlSugar.Updateable<Tenant>()
|
|
.SetColumns(x => x.IsDelete == enable)
|
|
.Where(x => x.Id == id).ExecuteCommandHasChangeAsync();
|
|
}
|
|
|
|
[HttpGet("dp-list")]
|
|
public async Task<List<Tenant>> GetDropDownList()
|
|
{
|
|
return await _sqlSugar.Queryable<Tenant>().Where(x => x.IsDelete == false).ToListAsync();
|
|
}
|
|
}
|
|
}
|