namespace HStation.CAL.LocalClient
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public class TransferFileUser : ITransferFileUser
|
{
|
private readonly HStation.Service.TransferFileUser _service = new();
|
|
#region Query
|
|
/// <summary>
|
/// 获取所有
|
/// </summary>
|
public async Task<List<TransferFileUserDto>> GetAll()
|
{
|
return await Task.Factory.StartNew(() =>
|
{
|
var list = _service.GetAll();
|
var vmList = list?.Select(x => new TransferFileUserDto(x)).ToList();
|
return vmList;
|
});
|
}
|
|
/// <summary>
|
/// 通过 ID 获取
|
/// </summary>
|
public async Task<TransferFileUserDto> GetByID(long input)
|
{
|
return await Task.Factory.StartNew(() =>
|
{
|
var model = _service.GetByID(input);
|
return model == null ? null : new TransferFileUserDto(model);
|
});
|
}
|
|
/// <summary>
|
/// 通过 Ids 获取
|
/// </summary>
|
public async Task<List<TransferFileUserDto>> GetByIds(List<long> Ids)
|
{
|
return await Task.Factory.StartNew(() =>
|
{
|
var list = _service.GetByIds(Ids);
|
var vmList = list?.Select(x => new TransferFileUserDto(x)).ToList();
|
return vmList;
|
});
|
}
|
|
/// <summary>
|
/// 通过 Name 获取
|
/// </summary>
|
public async Task<TransferFileUserDto> GetByName(string Name)
|
{
|
return await Task.Factory.StartNew(() =>
|
{
|
var model = _service.GetByName(Name);
|
return model == null ? null : new TransferFileUserDto(model);
|
});
|
}
|
|
#endregion
|
|
#region Insert
|
|
/// <summary>
|
/// 插入一条
|
/// </summary>
|
public async Task<long> Insert(AddTransferFileUserInput input)
|
{
|
return await Task.Factory.StartNew(() =>
|
{
|
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;
|
});
|
}
|
|
public Task<bool> Inserts(List<AddTransferFileUserInput> list)
|
{
|
throw new NotImplementedException();
|
}
|
|
public Task<bool> BulkInserts(List<AddTransferFileUserInput> list)
|
{
|
throw new NotImplementedException();
|
}
|
|
#endregion
|
|
#region Update
|
|
/// <summary>
|
/// 更新一条
|
/// </summary>
|
public async Task<bool> Update(UpdateTransferFileUserInput input)
|
{
|
return await Task.Factory.StartNew(() =>
|
{
|
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;
|
});
|
}
|
|
public Task<bool> Updates(List<UpdateTransferFileUserInput> list)
|
{
|
throw new NotImplementedException();
|
}
|
|
public Task<bool> BulkUpdates(List<UpdateTransferFileUserInput> list)
|
{
|
throw new NotImplementedException();
|
}
|
|
/// <summary>
|
/// 更新排序码
|
/// </summary>
|
public async Task<bool> UpdateSortCode(long ID, int SortCode)
|
{
|
return await Task.Factory.StartNew(() =>
|
{
|
var bol = _service.UpdateSortCode(ID, SortCode);
|
return bol;
|
});
|
}
|
|
/// <summary>
|
/// 更新排序
|
/// </summary>
|
public async Task<bool> UpdateSorter(List<UpdateSortCodeInput> inputList)
|
{
|
return await Task.Factory.StartNew(() =>
|
{
|
var list = inputList.Select(x => x.Adapt<UpdateSortCodeInput, Yw.Model.Sorter>()).ToList();
|
var bol = _service.UpdateSorter(list);
|
return bol;
|
});
|
}
|
|
/// <summary>
|
/// 激活
|
/// </summary>
|
public async Task<bool> Active(ActiveTransferFileUserInput input)
|
{
|
return await Task.Factory.StartNew(() =>
|
{
|
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>
|
public async Task<bool> Invalid(InvalidTransferFileUserInput input)
|
{
|
return await Task.Factory.StartNew(() =>
|
{
|
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>
|
public async Task<bool> IsExistName(string input)
|
{
|
return await Task.Factory.StartNew(() =>
|
{
|
var bol = _service.IsExistName(input);
|
return bol;
|
});
|
}
|
|
/// <summary>
|
/// 判断 Name 是否存在 ExceptID
|
/// </summary>
|
public async Task<bool> IsExistNameExceptID(NameExceptInput input)
|
{
|
return await Task.Factory.StartNew(() =>
|
{
|
var bol = _service.IsExistNameExceptID(input.Name, input.ExceptID);
|
return bol;
|
});
|
}
|
|
#endregion
|
|
#region Delete
|
|
/// <summary>
|
/// 通过 ID 删除
|
/// </summary>
|
public async Task<bool> DeleteByID(long input)
|
{
|
return await Task.Factory.StartNew(() =>
|
{
|
var bol = _service.DeleteByID(input, out string msg);
|
if (!bol)
|
{
|
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D999, msg, default(bool));
|
}
|
return bol;
|
});
|
}
|
|
public Task<bool> DeleteByIds(List<long> Ids)
|
{
|
throw new NotImplementedException();
|
}
|
|
public Task<bool> DeleteAll()
|
{
|
throw new NotImplementedException();
|
}
|
|
|
#endregion
|
}
|
}
|