예제 #1
0
        public async Task <IActionResult> GetUsers()
        {
            Users users = new Users();

            try
            {
                users.Resources = new List <Models.User>();

                // Initialize the GraphServiceClient.
                GraphServiceClient client = await MicrosoftGraphClient.GetGraphServiceClient();

                // Load users profiles.
                var userList = await client.Users.Request().GetAsync();

                // Copy Microsoft User to DTO User
                foreach (var user in userList)
                {
                    var objUser = CopyHandler.UserProperty(user);
                    users.Resources.Add(objUser);
                }

                return(Ok(users));
            }
            catch (ServiceException ex)
            {
                if (ex.StatusCode == HttpStatusCode.BadRequest)
                {
                    return(BadRequest());
                }
                else
                {
                    return(NotFound());
                }
            }
        }
예제 #2
0
        public async Task <IActionResult> GetUser(string id)
        {
            Models.User objUser = new Models.User();
            try
            {
                if (string.IsNullOrEmpty(id) || string.IsNullOrWhiteSpace(id))
                {
                    return(BadRequest());
                }


                // Initialize the GraphServiceClient.
                GraphServiceClient client = await MicrosoftGraphClient.GetGraphServiceClient();

                // Load user profile.
                var user = await client.Users[id].Request().GetAsync();

                // Copy Microsoft-Graph User to DTO User
                objUser = CopyHandler.UserProperty(user);

                return(Ok(objUser));
            }
            catch (ServiceException ex)
            {
                if (ex.StatusCode == HttpStatusCode.BadRequest)
                {
                    return(BadRequest());
                }
                else
                {
                    return(NotFound());
                }
            }
        }
        //private readonly MicrosoftGraphClient graphClient;
        //public AzureADHandler()
        //{
        //    this.graphClient = MicrosoftGraphClient.graphClient;
        //}

        public async Task <Models.User> GetUser(string id)
        {
            try
            {
                Models.User objUser = new Models.User();

                // Initialize the GraphServiceClient.
                GraphServiceClient client = await MicrosoftGraphClient.GetGraphServiceClient();

                // Load user profile.
                var user = await client.Users[id].Request().GetAsync();

                // Copy Microsoft-Graph User to DTO User
                objUser = CopyHandler.UserProperty(user);

                return(objUser);
            }
            catch (ServiceException ex)
            {
                if (ex.StatusCode == HttpStatusCode.NotFound)
                {
                    Log.Warning(ex.Message);
                    throw new NotFoundException();
                }
                else
                {
                    throw new Exception();
                }
            }
        }
        public async Task <UserResources> GetUsers(string filter, int?startIndex, int?count, string sortBy)
        {
            try
            {
                UserResources users = new UserResources();
                users.resources = new List <Models.User>();

                // Initialize the GraphServiceClient.
                GraphServiceClient client = await MicrosoftGraphClient.GetGraphServiceClient();

                // Load users profiles.
                var userList = await client.Users.Request().Filter($"{filter}").GetAsync();

                // Copy Microsoft User to DTO User
                foreach (var user in userList)
                {
                    var objUser = CopyHandler.UserProperty(user);
                    users.resources.Add(objUser);
                }
                users.totalResults = users.resources.Count;

                return(users);
            }
            catch (ServiceException ex)
            {
                if (ex.StatusCode == HttpStatusCode.BadRequest)
                {
                    Log.Warning(ex.Message);
                    throw new BadRequestException();
                }
                else if (ex.StatusCode == HttpStatusCode.NotFound)
                {
                    Log.Warning(ex.Message);
                    throw new NotFoundException();
                }
                else
                {
                    throw new Exception();
                }
            }
        }
예제 #5
0
        public async Task <IActionResult> GetUsersNotInTeam(string teamId)
        {
            UsersDto users = new UsersDto();

            try
            {
                users.Resources = new List <UserDto>();

                // Initialize the GraphServiceClient.
                GraphServiceClient client = await MicrosoftGraphClient.GetGraphServiceClient();

                // Load users profiles.
                var userList = await client.Users.Request().GetAsync();

                TeamModel team = await Mediator.Send(new GetTeamQuery { TeamId = new Guid(teamId) });

                // Copy Microsoft User to DTO User
                foreach (var user in userList)
                {
                    if (!team.Users.Any(x => x.UserId.ToString().Equals(user.Id)))
                    {
                        var objUser = CopyHandler.UserProperty(user);
                        users.Resources.Add(objUser);
                    }
                }
                users.TotalResults = users.Resources.Count;

                return(Ok(users));
            }
            catch (ServiceException ex)
            {
                if (ex.StatusCode == HttpStatusCode.BadRequest)
                {
                    return(BadRequest());
                }
                else
                {
                    return(NotFound());
                }
            }
        }