namespace HStation.Application
|
{
|
/// <summary>
|
/// TransferFileUser
|
/// </summary>
|
[Route("Transfer/File/User")]
|
[AllowAnonymous]
|
[ApiDescriptionSettings("TransferFile", Name = "用户", Order = 10000)]
|
public class TransferFileUser_Controller : IDynamicApiController
|
{
|
private readonly Service.TransferFileUser _service = new();
|
|
#region Query
|
|
/// <summary>
|
/// 获取所有
|
/// </summary>
|
[Route("GetAll@V1.0")]
|
[HttpGet]
|
public List<TransferFileUserDto> GetAll()
|
{
|
var list = _service.GetAll();
|
var vmList = list?.Select(x => new TransferFileUserDto(x)).ToList();
|
return vmList;
|
}
|
|
/// <summary>
|
/// 通过 ID 获取
|
/// </summary>
|
[Route("GetByID@V1.0")]
|
[HttpGet]
|
public TransferFileUserDto GetByID([FromQuery][Required] IDInput input)
|
{
|
var model = _service.GetByID(input.ID);
|
return model == null ? null : new TransferFileUserDto(model);
|
}
|
|
/// <summary>
|
/// 通过 Ids 获取
|
/// </summary>
|
[Route("GetByIds@V1.0")]
|
[HttpGet]
|
public List<TransferFileUserDto> GetByIds([FromQuery][Required] IdsInput model)
|
{
|
var ids = LongListHelper.ToList(model.Ids);
|
var list = _service.GetByIds(ids);
|
var vmList = list?.Select(x => new TransferFileUserDto(x)).ToList();
|
return vmList;
|
}
|
|
/// <summary>
|
/// 通过 Name 获取
|
/// </summary>
|
[Route("GetByName@V1.0")]
|
[HttpGet]
|
public TransferFileUserDto GetByName([FromQuery][Required] NameInput input)
|
{
|
var model = _service.GetByName(input.Name);
|
return model == null ? null : new TransferFileUserDto(model);
|
}
|
|
#endregion
|
|
#region Insert
|
|
/// <summary>
|
/// 插入一条
|
/// </summary>
|
[Route("Insert@V1.0")]
|
[HttpPost]
|
public long Insert([Required] AddTransferFileUserInput input)
|
{
|
if (_service.IsExistName(input.Name))
|
{
|
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, $"Name:{input.Name}", "名称已存在");
|
}
|
var model = input.Adapt<AddTransferFileUserInput, Model.TransferFileUser>();
|
model.SortCode = _service.GetMaxSortCode() + 1;
|
var id = _service.Insert(model);
|
return id;
|
}
|
|
#endregion
|
|
#region Update
|
|
/// <summary>
|
/// 更新一条
|
/// </summary>
|
[Route("Update@V1.0")]
|
[HttpPut]
|
public bool Update([Required] UpdateTransferFileUserInput input)
|
{
|
var model = _service.GetByID(input.ID);
|
if (model == null)
|
{
|
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"ID:{input.ID} 数据不存在");
|
}
|
if (_service.IsExistNameExceptID(input.Name, input.ID))
|
{
|
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, $"Name:{input.Name}", "名称已存在");
|
}
|
var rhs = new Model.TransferFileUser(model);
|
input.Adapt(rhs);
|
var bol = _service.Update(rhs);
|
return bol;
|
}
|
|
/// <summary>
|
/// 更新排序码
|
/// </summary>
|
[Route("UpdateSortCode@V1.0")]
|
[HttpPut]
|
public bool UpdateSortCode([Required] UpdateSortCodeInput input)
|
{
|
var bol = _service.UpdateSortCode(input.ID, input.SortCode);
|
return bol;
|
}
|
|
/// <summary>
|
/// 更新排序
|
/// </summary>
|
[Route("UpdateSorter@V1.0")]
|
[HttpPut]
|
public bool UpdateSorter([Required] List<UpdateSortCodeInput> inputList)
|
{
|
var list = inputList.Select(x => x.Adapt<UpdateSortCodeInput, Yw.Model.Sorter>()).ToList();
|
var bol = _service.UpdateSorter(list);
|
return bol;
|
}
|
|
/// <summary>
|
/// 激活
|
/// </summary>
|
[Route("Active@V1.0")]
|
[HttpPost]
|
public bool Active([Required] ActiveTransferFileUserInput input)
|
{
|
var model = _service.GetByName(input.Name);
|
if (model == null)
|
{
|
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, $"Name:{input.Name} 不存在");
|
}
|
var bol = _service.Active(model.ID, out string Msg);
|
if (!bol)
|
{
|
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, Msg);
|
}
|
return bol;
|
}
|
|
/// <summary>
|
/// 失效
|
/// </summary>
|
[Route("Invalid@V1.0")]
|
[HttpPost]
|
public bool Invalid([Required] InvalidTransferFileUserInput input)
|
{
|
var model = _service.GetByName(input.Name);
|
if (model == null)
|
{
|
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, $"Name:{input.Name} 不存在");
|
}
|
var bol = _service.Invalid(model.ID, input.InvalidTime, out string Msg);
|
if (!bol)
|
{
|
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, Msg);
|
}
|
return bol;
|
}
|
|
#endregion
|
|
#region Exist
|
|
/// <summary>
|
/// 判断 Name 是否存在
|
/// </summary>
|
[Route("IsExistName@V1.0")]
|
[HttpGet]
|
public bool IsExistName([FromQuery][Required] NameInput input)
|
{
|
var bol = _service.IsExistName(input.Name);
|
return bol;
|
}
|
|
/// <summary>
|
/// 判断 Name 是否存在 ExceptID
|
/// </summary>
|
[Route("IsExistNameExceptID@V1.0")]
|
[HttpGet]
|
public bool IsExistNameExceptID([FromQuery][Required] NameExceptInput input)
|
{
|
var bol = _service.IsExistNameExceptID(input.Name, input.ExceptID);
|
return bol;
|
}
|
|
#endregion
|
|
#region Delete
|
|
/// <summary>
|
/// 通过 ID 删除
|
/// </summary>
|
[Route("DeleteByID@V1.0")]
|
[HttpDelete]
|
public bool DeleteByID([FromQuery][Required] IDInput input)
|
{
|
var bol = _service.DeleteByID(input.ID, out string msg);
|
if (!bol)
|
{
|
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D999, msg, default(bool));
|
}
|
return bol;
|
}
|
|
#endregion
|
|
|
|
}
|
}
|