public async Task <ActionResult <Video> > PostVideo(URLDTO URL)
        {
            Video  newVideo;
            String videoId;

            try
            {
                videoId  = YouTubeHelper.GetVideoIdFromURL(URL.URL);
                newVideo = YouTubeHelper.GetVideoFromId(videoId);
            }
            catch {
                return(BadRequest("Invalid YouTube URL"));
            }
            _context.Video.Add(newVideo);
            await _context.SaveChangesAsync();

            TranscriptionsController transcriptionsController = new TranscriptionsController(new scriberContext());
            List <Transcription>     transcriptions           = YouTubeHelper.GetTranscriptions(videoId);

            Task addCaptions = Task.Run(async() =>
            {
                for (int i = 0; i < transcriptions.Count; i++)
                {
                    // Get the transcription objects form transcriptions and assign VideoId to id, the primary key of the newly inserted video
                    Transcription transcription = transcriptions.ElementAt(i);
                    transcription.VideoId       = newVideo.VideoId;
                    // Add this transcription to the database
                    await transcriptionsController.PostTranscription(transcription);
                    Console.WriteLine("inserting transcription" + i);
                }
            });


            return(CreatedAtAction("GetVideo", new { id = newVideo.VideoId }, newVideo));
        }
        public async Task <ActionResult <Video> > PostVideo(URLDTO URL)
        {
            String videoId  = YoutubeHelper.GetVideoIdFromURL(URL.URL);
            Video  newVideo = YoutubeHelper.GetVideoFromId(videoId);


            _context.Video.Add(newVideo);
            await _context.SaveChangesAsync();

            TranscriptionsController transcriptionsController = new TranscriptionsController(new youtubeContext());
            List <Transcription>     transcriptions           = YoutubeHelper.GetTranscriptions(videoId);

            //Go through each transaction and insert it into the database by calling PostTransactions()

            Task addCaptions = Task.Run(async() =>
            {
                for (int i = 0; i < transcriptions.Count; i++)
                {
                    Transcription transcription = transcriptions.ElementAt(i);
                    transcription.VideoId       = newVideo.VideoId;

                    await transcriptionsController.PostTranscription(transcription);
                    Console.WriteLine("inserting transcription" + i);
                }
            });

            return(CreatedAtAction("GetVideo", new { id = newVideo.VideoId }, newVideo));
        }
예제 #3
0
        public async Task <ActionResult <Book> > PostBook([FromBody] URLDTO data)
        {
            Book   book;
            String bookURL;
            String bookId;

            try
            {
                bookURL = data.URL; //get the url
                bookId  = GoogleBooksHelper.GetbookIdFromURL(bookURL);
                book    = GoogleBooksHelper.GetBookInfo(bookId, bookURL);
            }
            catch
            {
                return(BadRequest("Invalid Book URL"));
            }

            //Add this book object to the database
            _context.Book.Add(book);  // Book Repository Documentation/ Book Repo
            await _context.SaveChangesAsync();

            // Get the primary key of the newly created book record in the database
            int id = book.BookId;
            //Construct seperate thread
            bookAPIContext  tempcontext     = new bookAPIContext();
            WordsController wordscontroller = new WordsController(tempcontext);

            //Executed in background
            Task addWords = Task.Run(async() =>
            {
                //Get list of words from GoogleHelper
                List <Word> words = new List <Word>();

                words = GoogleBooksHelper.GetWords(bookId);


                for (int i = 0; i < words.Count; i++)
                {
                    Word word   = words.ElementAt(i);
                    word.BookId = id;
                    await wordscontroller.PostWord(word);
                }
            });

            //Return success code and the info on the video object
            return(CreatedAtAction("GetBook", new { id = book.BookId }, book));
        }
예제 #4
0
        public async Task <ActionResult <Blogger> > PostBlogger(URLDTO URL)
        {
            Blogger newBlogInfo = Bloggershelper.GetBlogInfo(URL.URL);

            int?orgblogId = newBlogInfo.PostRefId;

            // Add this video object to the database
            _context.Blogger.Add(newBlogInfo);
            await _context.SaveChangesAsync();

            int blogId = newBlogInfo.BlogId;

            REEviewContext  tempContext     = new REEviewContext();
            PostsController postsController = new PostsController(tempContext);

            // This will be executed in the background.
            Task addCaptions = Task.Run(async() =>
            {
                List <Posts> transcriptions = new List <Posts>();
                transcriptions = Bloggershelper.GetPostInfo(orgblogId, blogId);

                for (int i = 0; i < transcriptions.Count; i++)
                {
                    // Get the transcription objects form transcriptions and assign VideoId to id, the primary key of the newly inserted video
                    Posts posts  = transcriptions.ElementAt(i);
                    posts.BlogId = blogId;
                    posts.Blog   = newBlogInfo;
                    // Add this transcription to the database
                    await postsController.PostPosts(posts);
                }
            });


            // Return success code and the info on the video object
            // return CreatedAtAction("GetVideo", new { id = newBlogInfo.BlogId }, newBlogInfo);
            return(newBlogInfo);
        }