using AutoMapper;
using Model.ModelDto.SysDto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WMS.Entity.SysEntity;
using WMS.IBLL.ISysServer;
using WMS.IDAL.ISysInterface;
namespace WMS.BLL.SysServer
{
///
/// 角色服务实践
///
public class RolesServer : IRolesServer
{
///
/// 依赖注入
///
public IRolesRepository _roles { get; set; }
private readonly IMapper _mapper;
///
/// 构造函数
///
/// 角色
/// automapper
public RolesServer(IRolesRepository roles,IMapper mapper)
{
_roles = roles; //角色
_mapper = mapper; //automapper
}
///
/// 获取角色数据列表
///
/// 角色号
/// 角色名称
///
public List GetRoleList(string RoleNo, string RoleName,string UserId)
{
//获取角色信息
List rolelist = _roles.GetRoleList(RoleNo, RoleName, UserId);
//返回数据
return rolelist;
}
///
/// 根据编号获取角色信息列表
///
/// 角色编号
///
public int GetRoleByNo(string RoleNo)
{
List role = _roles.GetRoleByNo(RoleNo);
return role.Count;
}
///
/// 新增角色数据信息
///
/// 角色dto
///
/// 捕获异常
public async Task InsertRoleInfo(RoleDto roledto)
{
//捕获异常
try
{
//模型映射
SysRoles roles = _mapper.Map(roledto);
//判断角色号是否唯一
int count = GetRoleByNo(roledto.RoleNo);
int i = 0;
if (count > 0)
{
i = 3;
}
else if (count == 0)
{
//新增角色信息
i = await _roles.InsertRoleInfo(roles);
}
return i;
}
catch (Exception ex)
{
//抛出异常
throw new Exception("角色信息新增异常", ex);
}
}
///
/// 删除角色信息(逻辑删除)
///
/// 角色实体模型
///
public async Task DeleteRoleInfo(SysRoles roles)
{
int i = await _roles.DeleteRoleInfo(roles);
return i;
}
///
/// 编辑角色信息
///
/// 角色实体模型
///
public async Task UpdateRoleInfo(SysRoles role)
{
//修改
int i = await _roles.UpdateRoleInfo(role);
return i;
}
///
/// 根据id获取角色信息
///
/// 角色id
///
public SysRoles GetRoleInfoById(int roleids)
{
SysRoles role= _roles.GetRoleInfoById(roleids);
return role;
}
}
}