using Furion.DatabaseAccessor.Extensions;
using YBEE.EQM.Core;
namespace YBEE.EQM.Application
{
///
/// 角色组服务
///
public class SysRoleGroupService : ISysRoleGroupService, ITransient
{
private readonly IRepository _roleGroupRep;
public SysRoleGroupService(IRepository roleGroupRep)
{
_roleGroupRep = roleGroupRep;
}
///
/// 添加角色组
///
///
///
public async Task Add(AddSysRoleGroupInput input)
{
var isExist = await _roleGroupRep.DetachedEntities.AnyAsync(u => u.Name == input.Name);
if (isExist)
{
throw Oops.Oh(ErrorCode.E2004);
}
var roleGroup = input.Adapt();
await roleGroup.InsertNowAsync();
return roleGroup.Id;
}
///
/// 更新角色组
///
///
///
public async Task Update(UpdateSysRoleGroupInput input)
{
var rg = await _roleGroupRep.FindOrDefaultAsync(input.Id) ?? throw Oops.Oh(ErrorCode.E2001);
if (await _roleGroupRep.AnyAsync(t => t.Id != input.Id && t.Name.ToLower() == input.Name.ToLower()))
{
throw Oops.Oh(ErrorCode.E2004);
}
rg.Name = input.Name;
rg.Remark = input.Remark;
await _roleGroupRep.SaveNowAsync();
}
///
/// 删除角色组
///
///
///
public async Task Del(DeleteSysRoleGroupInput input)
{
var rg = await _roleGroupRep.FindOrDefaultAsync(input.Id) ?? throw Oops.Oh(ErrorCode.E2001);
await _roleGroupRep.DeleteAsync(rg);
}
///
/// 获取所有角色组列表
///
///
public async Task> GetAllList()
{
var items = await _roleGroupRep.DetachedEntities.Where(u => u.IsDeleted == false)
.ProjectToType()
.ToListAsync();
return items;
}
}
}