Ejemplo n.º 1
0
        public async Task <IActionResult> GetTrendingKeywords()
        {
            List <string> topics = await _dal.GetTrendingTopicsAsync();

            string           keywords = String.Join("|", topics);
            TrendingKeywords tk       = new TrendingKeywords();

            tk.Keyword = keywords;

            if (ModelState.IsValid)
            {
                _context.TrendingKeywords.Add(tk);
                _context.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> AddFavorite(string Title, string Source, int PageId, string Article)
        {
            // Check if the Favorite already exists
            string            userKey       = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            List <Favorites>  userFavorites = _context.Favorites.Where(x => x.UserId == userKey).ToList();
            List <Favorites>  checkTarget   = userFavorites.Where(x => x.PageId == PageId).ToList();
            List <Audiofiles> matches       = _context.Audiofiles.Where(x => x.PageId == PageId).ToList();

            if (matches.Count == 0)
            {
                string fileURL = await TextToSpeech.SynthesizeAudioAsync(Article, Title);

                Audiofiles af = new Audiofiles();
                af.SectionNumber  = 1;
                af.PageId         = PageId;
                af.StorageAddress = fileURL;

                if (ModelState.IsValid)
                {
                    _context.Audiofiles.Add(af);
                    _context.SaveChanges();
                }
            }

            // If it doesn't already exist, create a new one.
            if (checkTarget.Count == 0)
            {
                Favorites F = new Favorites();

                F.Title  = Title;
                F.Source = Source;
                F.PageId = PageId;
                F.UserId = User.FindFirst(ClaimTypes.NameIdentifier).Value;
                F.Tags   = "";

                if (ModelState.IsValid)
                {
                    _context.Favorites.Add(F);
                    _context.SaveChanges();
                }
            }

            return(RedirectToAction("ViewFavorites"));
        }