public VideoWithLatest Get() { //var videos = new List<Video>(); var youtubeOperations = new YoutubeOperations(); var databaseInteraction = new MongoDbInteraction(new MongoDbConnection { CollectionName = "videos", DatabaseName = "StrawHatEntertainment" }, new MongoClient("mongodb://localhost")); var videos = databaseInteraction.FindAll<Videos>().Result; //var tokenInfo = BsonSerializer.Deserialize<TokenInfo>(databaseInteraction.FindAll<BsonDocument>().Result[0]); //youtubeOperations.GetVideoList(tokenInfo, videos); //var videoList = videos.Where(x => x.VideoList.Any()).ToList(); var videoWithLatest = new VideoWithLatest(); videoWithLatest.latestVideo = videos.Select(x => x.VideoList.OrderByDescending(y => y.PublishedDate).FirstOrDefault()).FirstOrDefault(); videoWithLatest.videos = new List<Video>(); foreach (var video in videos) { videoWithLatest.videos.AddRange(video.VideoList); } return videoWithLatest; }
// GET: Youtube public ActionResult Index() { var databaseInteraction = new MongoDbInteraction(new MongoDbConnection { CollectionName = "googleAuthorization", DatabaseName = "StrawHatEntertainment" }, new MongoClient("mongodb://localhost")); var results = databaseInteraction.FindAll<BsonDocument>().Result; if (results.Count() == 0) { var authEndpoint = "https://accounts.google.com/o/oauth2/auth?"; NameValueCollection queryString = System.Web.HttpUtility.ParseQueryString(string.Empty); queryString["response_type"] = "code"; queryString["client_id"] = "585224365875-s7phb7mlduaa5e93r2qojjldcgi4o2vj.apps.googleusercontent.com"; queryString["redirect_uri"] = "http://localhost:55102/youtube/HandleClientCode"; queryString["scope"] = "https://www.googleapis.com/auth/youtube"; queryString["access_type"] = "offline"; queryString["approval_prompt"] = "force"; var authorizationUrl = authEndpoint + queryString.ToString(); return Redirect(authorizationUrl); } var googleAuthentication = results.Select(x => BsonSerializer.Deserialize<TokenInfo>(x)).ToList()[0]; return View("~/Views/Home/Index.cshtml"); }