Exemple #1
0
        /// <summary>
        /// Get group information by email
        /// </summary>
        /// <param name="email">Group email</param>
        /// <param name="accessToken">Microsoft Graph access token</param>
        /// <returns>Group ID</returns>
        public async Task <string> GetGroupId(string email, string accessToken)
        {
            try
            {
                var endpoint            = $"{GroupEndpoint}?$fileter=mail eq '{email}'";
                var httpResponseMessage = await _httpService.AuthenticatedGet(endpoint, accessToken);

                var content = await httpResponseMessage.Content.ReadAsStringAsync();

                var groupResponse = JsonConvert.DeserializeObject <GroupResponse>(content);
                var groupId       = groupResponse.Value[0].Id;
                return(groupId);
            }
            catch (Exception e)
            {
                _loggingService.Error(e, "Error in GroupService.GetGroupID");
                throw;
            }
        }
        /// <summary>
        /// Get all rooms
        /// </summary>
        /// <param name="accessToken">User Acces Token</param>
        /// <returns>List of all rooms</returns>
        public async Task <List <Room> > GetRooms(string accessToken)
        {
            try
            {
                var httpResponseMessage = await _httpService.AuthenticatedGet("https://graph.microsoft.com/beta/me/findrooms", accessToken);

                var roomSearchResponse = JsonConvert.DeserializeObject <RoomsListResponse>(await httpResponseMessage.Content.ReadAsStringAsync());
                return(roomSearchResponse != null ? roomSearchResponse.Value : new List <Room>());
            }
            catch (Exception ex)
            {
                _loggingService.Error(ex);
                throw;
            }
        }
Exemple #3
0
        /// <summary>
        /// Provide emails and additional information for users by their name
        /// </summary>
        /// <param name="users">List of users</param>
        /// <param name="accessToken">Microsoft Graph Access Token</param>
        /// <returns></returns>
        public async Task <List <Model.Person> > GetPeolpe(List <User> users, string accessToken)
        {
            if (users == null || users.Count == 0 || string.IsNullOrEmpty(accessToken))
            {
                return(new List <Model.Person>());
            }
            try
            {
                var queryBuilder = new StringBuilder();
                queryBuilder.Append(PeopleEndpoint);
                for (var i = 0; i < users.Count; i++)
                {
                    if (i > 0 && i < users.Count - 1)
                    {
                        queryBuilder.Append(" or ");
                    }

                    if (!string.IsNullOrEmpty(users[i].GivenName) && !string.IsNullOrEmpty(users[i].Surname))
                    {
                        queryBuilder.Append($"(Givenname eq '{users[i].GivenName}' and Surname eq '{users[i].Surname}')");
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(users[i].GivenName) && string.IsNullOrEmpty(users[i].Surname))
                        {
                            queryBuilder.Append($"Givenname eq '{users[i].GivenName}'");
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(users[i].GivenName) && !string.IsNullOrEmpty(users[i].Surname))
                            {
                                queryBuilder.Append($"Surname eq '{users[i].Surname}'");
                            }
                        }
                    }
                }
                var endpoint            = queryBuilder.ToString();
                var httpResponseMessage = await HttpService.AuthenticatedGet(endpoint, accessToken);

                var userSearchResponse = JsonConvert.DeserializeObject <PersonSearchResponse>(await httpResponseMessage.Content.ReadAsStringAsync());
                return(userSearchResponse != null ? userSearchResponse.Value : new List <Model.Person>());
            }
            catch (Exception exception)
            {
                LoggingService.Error(exception, "Error in PeopleService.GetPeople");
                throw;
            }
        }