using AGSS.Models; using AGSS.Models.Entities; using Microsoft.AspNetCore.Identity; namespace AGSS.Services; public class UserService { private readonly UserManager _userManager; public UserService(UserManager userManager) { _userManager = userManager; } public async Task GetUserProfileAsync(string userId) { var user = await _userManager.FindByIdAsync(userId); if (user == null) { throw new ArgumentException("User not found"); } return new UserProfile { Id = user.Id, UserName = user.UserName, Email = user.Email, Sex = user.Sex, Description = user.Description, Config = user.Config, JobCode = user.JobCode, JobName = user.JobName, Birthday = user.Birthday, MenuCode = user.MenuCode, MenuName = user.MenuName }; } public async Task> GetUsersProfileInRoleAsync(string roleName) { var usersInRole = await _userManager.GetUsersInRoleAsync(roleName); if (usersInRole == null || !usersInRole.Any()) { throw new ArgumentException("No users found in the specified role"); } var userProfiles = new List(); foreach (var user in usersInRole) { userProfiles.Add(new UserProfile { Id = user.Id, UserName = user.UserName, Email = user.Email, Sex = user.Sex, Description = user.Description, Config = user.Config, JobCode = user.JobCode, JobName = user.JobName, Birthday = user.Birthday, MenuCode = user.MenuCode, MenuName = user.MenuName }); } // Assuming you want to return a single UserProfile, you might need to adjust this logic // For now, returning the first user's profile return userProfiles; } }