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
|
{
|
/// <summary>
|
/// 角色服务实践
|
/// </summary>
|
public class RolesServer : IRolesServer
|
{
|
/// <summary>
|
/// 依赖注入
|
/// </summary>
|
public IRolesRepository _roles { get; set; }
|
private readonly IMapper _mapper;
|
/// <summary>
|
/// 构造函数
|
/// </summary>
|
/// <param name="roles">角色</param>
|
/// <param name="mapper">automapper</param>
|
public RolesServer(IRolesRepository roles,IMapper mapper)
|
{
|
_roles = roles; //角色
|
_mapper = mapper; //automapper
|
}
|
|
/// <summary>
|
/// 获取角色数据列表
|
/// </summary>
|
/// <param name="RoleNo">角色号</param>
|
/// <param name="RoleName">角色名称</param>
|
/// <returns></returns>
|
public List<RoleDto> GetRoleList(string RoleNo, string RoleName,string UserId)
|
{
|
//获取角色信息
|
List<RoleDto> rolelist = _roles.GetRoleList(RoleNo, RoleName, UserId);
|
//返回数据
|
return rolelist;
|
}
|
|
/// <summary>
|
/// 根据编号获取角色信息列表
|
/// </summary>
|
/// <param name="RoleNo">角色编号</param>
|
/// <returns></returns>
|
public int GetRoleByNo(string RoleNo)
|
{
|
List<SysRoles> role = _roles.GetRoleByNo(RoleNo);
|
return role.Count;
|
}
|
|
/// <summary>
|
/// 新增角色数据信息
|
/// </summary>
|
/// <param name="roledto">角色dto</param>
|
/// <returns></returns>
|
/// <exception cref="Exception">捕获异常</exception>
|
public async Task<int> InsertRoleInfo(RoleDto roledto)
|
{
|
//捕获异常
|
try
|
{
|
//模型映射
|
SysRoles roles = _mapper.Map<SysRoles>(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);
|
}
|
}
|
|
|
/// <summary>
|
/// 删除角色信息(逻辑删除)
|
/// </summary>
|
/// <param name="roles">角色实体模型</param>
|
/// <returns></returns>
|
public async Task<int> DeleteRoleInfo(SysRoles roles)
|
{
|
int i = await _roles.DeleteRoleInfo(roles);
|
return i;
|
|
}
|
|
/// <summary>
|
/// 编辑角色信息
|
/// </summary>
|
/// <param name="role">角色实体模型</param>
|
/// <returns></returns>
|
public async Task<int> UpdateRoleInfo(SysRoles role)
|
{
|
//修改
|
int i = await _roles.UpdateRoleInfo(role);
|
return i;
|
|
}
|
|
/// <summary>
|
/// 根据id获取角色信息
|
/// </summary>
|
/// <param name="roleids">角色id</param>
|
/// <returns></returns>
|
public SysRoles GetRoleInfoById(int roleids)
|
{
|
SysRoles role= _roles.GetRoleInfoById(roleids);
|
return role;
|
}
|
|
}
|
}
|