Esempio n. 1
0
        public async Task <ActionResult> CreateSubscription()
        {
            try
            {
                var subscription = await subscriptionsRepository.CreateOrReuseSubscription();

                var viewModel = new SubscriptionViewModel();
                viewModel.Subscription = subscription;
                return(View("Subscription", viewModel));
            }
            catch (Exception ex)
            {
                if (ex is AdalException)
                {
                    throw ex;
                }
                return(RedirectToAction("Index", "Error", new { message = ex.Message }));
            }
        }
        public async Task <ActionResult> Index(string channelId)
        {
            try
            {
                var accessTokenSharePoint = await AadHelper.GetAccessTokenForSharePoint();

                var accessTokenMSGraph = await AadHelper.GetAccessTokenForMicrosoftGraph();

                var sharePointRepository    = new VideoChannelRepository(accessTokenSharePoint);
                var groupsRepository        = new GroupsRepository(graphClient);
                var subscriptionsRepository = new SubscriptionsRepository(graphClient, this.Session, HttpRuntime.Cache);

                var channel = await sharePointRepository.GetChannel(channelId);

                var videos = await sharePointRepository.GetChannelVideos(channelId);

                var groups = await groupsRepository.GetGroups();

                var viewModel = new VideoListViewModel
                {
                    ChannelId    = channelId,
                    ChannelTitle = channel.Title,
                    Videos       = videos,
                    Groups       = groups
                };

                // integration of the webhooks example
                Microsoft.Graph.Subscription result = await subscriptionsRepository.CreateOrReuseSubscription();

                return(View(viewModel));
            }
            catch (Exception ex)
            {
                if (ex is AdalException)
                {
                    // let the ActionFilterAttribute take care of it
                    throw ex;
                }

                return(RedirectToAction("Index", "Error", new { message = ex.Message }));
            }
        }