Beispiel #1
0
        public async Task <User> GetUserByUsername(string username)
        {
            if (ValidateQuery(await _userTable.SelectByUsername(username), out User user)) // Get user with specified username, check if user exists
            {
                user.Roles = new List <Role>();

                List <UserRoleModel> userRoles = await _userRoleTable.SelectByUser(user.Id); // Get user role relations for the user

                foreach (UserRoleModel userRole in userRoles)
                {
                    if (ValidateQuery(await _roleTable.SelectById(userRole.RoleId), out Role role)) // Get role associated with role id
                    {
                        user.Roles.Add(role);                                                       // Add role to user's list of roles
                    }
                }

                return(user);
            }

            throw new ArgumentException("Provided username could not be found.");
        }