Exemple #1
0
        public async Task <IActionResult> GetGroup(string id)
        {
            Models.Group objGroup = new Models.Group();
            try
            {
                // Initialize the GraphServiceClient.
                GraphServiceClient client = await MicrosoftGraphClient.GetGraphServiceClient();

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

                // Copy Microsoft-Graph Group to DTO Group
                objGroup = CopyHandler.GroupProperty(group);

                return(Ok(objGroup));
            }
            catch (ServiceException ex)
            {
                if (ex.StatusCode == HttpStatusCode.BadRequest)
                {
                    return(BadRequest());
                }
                else
                {
                    return(NotFound());
                }
            }
        }
        public async Task <Models.Group> GetGroup(string id)
        {
            try
            {
                Models.Group objGroup = new Models.Group();

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

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

                // Copy Microsoft-Graph Group to DTO Group
                objGroup = CopyHandler.GroupProperty(group);

                return(objGroup);
            }
            catch (ServiceException ex)
            {
                if (ex.StatusCode == HttpStatusCode.BadRequest)
                {
                    Log.Warning(ex.Message);
                    throw new NotFoundException();
                }
                else
                {
                    throw new Exception();
                }
            }
        }
        public async Task <GroupResources> GetGroups(string filter, int?startIndex, int?count, string sortBy)
        {
            try
            {
                GroupResources groups = new GroupResources();
                groups.resources = new List <Models.Group>();

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

                // Load groups profiles.
                var groupList = await client.Groups.Request().Filter($"{filter}").GetAsync();

                // Copy Microsoft-Graph Group to DTO Group
                foreach (var group in groupList)
                {
                    var objGroup = CopyHandler.GroupProperty(group);
                    groups.resources.Add(objGroup);
                }
                groups.totalResults = groups.resources.Count;

                return(groups);
            }
            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();
                }
            }
        }
Exemple #4
0
        public async Task <IActionResult> Get()
        {
            //return new string[] { "value1", "value2" };
            Groups groups = new Groups();

            try
            {
                groups.resources = new List <Models.Group>();

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

                // Load groups profiles.
                var groupList = await client.Groups.Request().GetAsync();

                // Copy Microsoft-Graph Group to DTO Group
                foreach (var group in groupList)
                {
                    var objGroup = CopyHandler.GroupProperty(group);
                    groups.resources.Add(objGroup);
                }
                groups.totalResults = groups.resources.Count;

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