public ActionResult UpdateDatabase()
        {
            ResponseNewsAppModels jsonModel    = new ResponseNewsAppModels();
            List <DisplayArticle> articleList  = new List <DisplayArticle>();
            List <Category>       categoryList = db.Categories.ToList();

            foreach (var category in categoryList)
            {
                string jsonObject = jsonModel.TransportJsonNewsWithApp(category.name);
                IEnumerable <NewArticle> listArticle = JsonConvert.DeserializeObject <IEnumerable <NewArticle> >(jsonObject) as IEnumerable <NewArticle>;

                foreach (var article in listArticle)
                {
                    displayArticle = new DisplayArticle
                    {
                        author      = article.newAuthor,
                        title       = article.newTitle,
                        description = article.newDescription,
                        url         = article.newUrl,
                        urlToImage  = article.newUrlToImage,
                        publishetAt = article.newPublishetAt,
                        source      = article.newSource.newName,
                        idCateogry  = category.idCategory
                    };

                    articleList.Add(displayArticle);
                }
            }
            db.Articles.AddRange(articleList);
            db.SaveChanges();
            var message = "Zaktualizowano wszystkie artykuły ";

            return(RedirectToAction("ControlPanel", new { information = message }));
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ViewArticle"/> class.
        /// </summary>
        /// <param name="article">The article.</param>
        /// <param name="filePath">The file path.</param>
        public ViewArticle(DisplayArticle article, string filePath)
        {
            InitializeComponent();

            TextBoxes = new List <TextBox>();

            TextBoxes.Add(WhoTextBox);
            TextBoxes.Add(WhenTextBox);
            TextBoxes.Add(WhereTextBox);
            TextBoxes.Add(WhatTextBox);
            TextBoxes.Add(WhyTextBox);

            SetTextBoxesIsReadOnly(true);

            Article  = article;
            FilePath = filePath;

            TitleTextBlock.Text   = article.Article.Title;
            this.Title            = TitleTextBlock.Text;
            AuthorTextBlock.Text  = article.Article.Author;
            DateTextBlock.Text    = article.Article.Date.ToString();
            Hyperlink.NavigateUri = new Uri(article.Article.Link);
            SetBodyTextBlock();

            WhoTextBox.Text   = article.Annotation.Who;
            WhenTextBox.Text  = article.Annotation.FormattedWhen;
            WhereTextBox.Text = article.Annotation.Where;
            WhatTextBox.Text  = article.Annotation.What;
            WhyTextBox.Text   = article.Annotation.Why;
        }
Esempio n. 3
0
        public IActionResult SearchDetail(int id)
        {
            var            model          = articleRepository.Get(id);
            DisplayArticle displayArticle = new DisplayArticle();
            Article        article        = new Article();

            article           = model;
            article.ViewCount = article.ViewCount + 1;
            articleRepository.Update(model);
            displayArticle.ResultArticle = article;
            displayArticle.Articles      = articleRepository.GetAll().Take(2).ToList();
            return(View(displayArticle));
        }
        public async Task <IActionResult> Get(string slug)
        {
            var article = await _context.Entries
                          .Include(a => a.ApplicationUser)
                          .Include(a => a.EntryToTopics)
                          .ThenInclude(et => et.Topic)
                          .FirstOrDefaultAsync(a => a.Slug == slug);

            // find Entries with similar topics
            // get topics linked to article
            var topics = article.EntryToTopics.Select(et => et.Topic);
            // get topic ids
            var topicIds = topics.Select(t => t.Id).ToList();

            var reccomendations = await _context.Entries
                                  .Include(a => a.EntryToTopics)
                                  .Where(a => a.EntryToTopics.Any(et => topicIds.Contains(et.Topic.Id)))
                                  .Where(a => a.Id != article.Id)
                                  .OrderByDescending(a => a.Date)
                                  .AsNoTracking()
                                  .ToListAsync();

            DisplayArticle model = new DisplayArticle()
            {
                Article         = article,
                Topics          = topics,
                Reccomendations = reccomendations.Select(r => ReccomendationBlockViewComponent.ToViewModel(r))
            };

            ViewData["OGTitle"]       = article.HeadLine;
            ViewData["OGDescription"] = article.Paragraph;
            ViewData["OGImage"]       = "https://www.renegadenews.net/images/uploads/" + article.Img;
            ViewData["OGUrl"]         = "https://www.renegadenews.net/Article/" + article.Slug;

            // update page view
            article.PageViews++;
            _context.Entry(article).Property(p => p.PageViews).IsModified = true;
            await _context.SaveChangesAsync();

            return(View("Index", model));
        }