You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.8 KiB
C#

using EntrustSettle.IRepository.Base;
using EntrustSettle.IServices;
using EntrustSettle.Model.Models;
using EntrustSettle.Services.Base;
using System.Linq;
using System.Threading.Tasks;
namespace EntrustSettle.FrameWork.Services
{
/// <summary>
/// sysUserInfoServices
/// </summary>
public class SysUserInfoServices : BaseServices<SysUserInfo>, ISysUserInfoServices
{
private readonly IBaseRepository<UserRole> _userRoleRepository;
private readonly IBaseRepository<Role> _roleRepository;
public SysUserInfoServices(IBaseRepository<UserRole> userRoleRepository, IBaseRepository<Role> roleRepository)
{
_userRoleRepository = userRoleRepository;
_roleRepository = roleRepository;
}
/// <summary>
///
/// </summary>
/// <param name="loginName"></param>
/// <param name="loginPwd"></param>
/// <returns></returns>
public async Task<string> GetUserRoleNameStr(string loginName, string loginPwd)
{
string roleName = "";
var user = (await base.Query(a => a.LoginName == loginName && a.LoginPWD == loginPwd)).FirstOrDefault();
var roleList = await _roleRepository.Query(a => a.IsDeleted == false);
if (user != null)
{
var userRoles = await _userRoleRepository.Query(ur => ur.UserId == user.Id);
if (userRoles.Count > 0)
{
var arr = userRoles.Select(ur => ur.RoleId.ObjToString()).ToList();
var roles = roleList.Where(d => arr.Contains(d.Id.ObjToString()));
roleName = string.Join(',', roles.Select(r => r.Name).ToArray());
}
}
return roleName;
}
}
}