public async Task <object> GetRoleByUser(string user) { var roleUser = _roleUserRepository.FindAll(x => x.user_account.Trim() == user.Trim()); var role = _rolesRepository.FindAll(x => x.role_unique.Trim() != null); var data = await(from a in role select new { role_sequence = a.role_sequence, user_account = user, Role_unique = a.role_unique, Role_name = a.role_name, Status = roleUser == null?false:roleUser.Where(x => x.role_unique == a.role_unique).Count() != 0 ? true : false }).OrderBy(x => x.role_sequence).ToListAsync(); return(data); }
public async Task <UserForLogged_Dto> GetUser(string username, string password) { var user = _repoUser.FindSingle(x => x.User_ID.Trim() == username.Trim()); //Kiem tra user co ton tai khong if (user == null) { return(null); } if (user.Password != password) { return(null); } var roleUser = _repoRoleUser.FindAll(x => x.user_account == user.User_ID); var role = _repoRole.FindAll(); var roleName = await roleUser.Join(role, x => x.role_unique, y => y.role_unique, (x, y) => new Role_Dto { Name = y.role_unique, Position = y.role_sequence }).ToListAsync(); var result = new UserForLogged_Dto { Id = user.User_ID, Email = user.Email, Username = user.User_Name, Name = user.User_Name, Role = roleName.OrderBy(x => x.Position).Select(x => x.Name).ToList() }; return(result); }