Beispiel #1
0
        public List <ArticleTitle> GetArticlesTitles()
        {
            string sql = "SELECT t1.Id, t1.Title, t1.CreationDate, t2.* FROM Articles t1 "
                         + "INNER JOIN ArticlesCategories t1t2 ON t1.Id=t1t2.Article_Id "
                         + "INNER JOIN Categories t2 ON t2.Id=t1t2.Category_Id "
                         + "ORDER BY t1.CreationDate DESC "
            ;

            using (var connection = new SqlConnection(connectionString))
            {
                List <ArticleTitle> result = new List <ArticleTitle>();

                connection
                .Query <ArticleTitle, Category, ArticleTitle>(sql,
                                                              (_article, _category) =>
                {
                    ArticleTitle existing = result.FirstOrDefault(x => x.Id == _article.Id);
                    if (existing == null)
                    {
                        _article.Categories.Add(_category);
                        result.Add(_article);
                    }
                    else
                    {
                        existing.Categories.Add(_category);
                    }

                    return(_article);
                });

                return(result);
            }
        }
        public IHttpActionResult Articles(ArticleTitle title)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Passed information isn't valid."));
                }

                var da   = new DataAccess();
                var arts = da.GetArticles(title.Title);
                if (arts == null)
                {
                    return(NotFound());
                }

                // Let's convert the article objects
                var articles = Mapper.MapArticle(arts);

                if (articles == null)
                {
                    throw new NotImplementedException();
                }

                return(Ok(articles));
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Attempt to get articles from title " + title.Title + " failed: " + ex.Message);
                return(BadRequest("Something went wrong while saving comment."));
            }
        }
Beispiel #3
0
        public FakeArticle(ArticleTitle title)
        {
            _source = new FakePath(title.PlainText);

            Parts = new List <ArticlePart>()
            {
                ArticlePart.CreateHeader(title.TextWithLineBreak)
            };
        }
Beispiel #4
0
        public override int GetHashCode()
        {
            var toReturn =
                ArticleId.GetHashCode() ^
                NewsletterId.GetHashCode() ^
                ArticleSequence.GetHashCode() ^
                ImageFileLocation.GetHashCode() ^
                ArticleType.GetHashCode() ^
                ArticleTableOfContentsText.GetHashCode() ^
                ArticleTitle.GetHashCode() ^
                ArticleText.GetHashCode();

            return(toReturn);
        }
Beispiel #5
0
        public ActionResult Index(Category?category = null)
        {
            if (category == null)
            {
                return(View("Empty"));
            }


            IEnumerable <ArticleTitle> articleTitles = articlesRepository.Articles
                                                       .Where(a => a.Category == category)
                                                       .ToArray()
                                                       .Select(a =>
            {
                ArticleTitle articleTitle = new ArticleTitle();
                articleTitle.InjectFrom(a);
                return(articleTitle);
            });

            return(View(articleTitles));
        }
Beispiel #6
0
        public void FindTitleArticle(string article)
        {
            var   pattern = @"<Titulo>(.*)</Titulo>";
            Regex rgx     = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);

            MatchCollection matches = rgx.Matches(article);


            if (matches.Count > 0)
            {
                Match match = matches[0];


                //Tratamento do titulo

                ArticleTitle = match.Value;
                ArticleTitle = ArticleTitle.Replace("<Titulo>", "");
                ArticleTitle = ArticleTitle.Replace("</Titulo>", "");
            }
        }
 public void EnterArticleTitle(string title)
 {
     ArticleTitle.SendKeys(title);
 }
        private HttpRequestMessage CreateSearchRequestToService(Search search)
        {
            try
            {
                HttpRequestMessage requestMessage = CreateRequestToService(HttpMethod.Post, "api/Data/" + search.Criteria);
                if (search.Criteria == "Title")
                {
                    var at = new ArticleTitle()
                    {
                        Title = search.SearchString
                    };
                    requestMessage.Content = new ObjectContent <ArticleTitle>(at, new JsonMediaTypeFormatter());
                }
                else if (search.Criteria == "Topic")
                {
                    var at = new ArticleTopic()
                    {
                        Topic = search.SearchString
                    };
                    requestMessage.Content = new ObjectContent <ArticleTopic>(at, new JsonMediaTypeFormatter());
                }
                else if (search.Criteria == "Source")
                {
                    var at = new ArticleSource()
                    {
                        Name = search.SearchString
                    };
                    requestMessage.Content = new ObjectContent <ArticleSource>(at, new JsonMediaTypeFormatter());
                }
                else if (search.Criteria == "Country")
                {
                    var at = new ArticleCountry()
                    {
                        Country = search.SearchString
                    };
                    requestMessage.Content = new ObjectContent <ArticleCountry>(at, new JsonMediaTypeFormatter());
                }
                else if (search.Criteria == "Language")
                {
                    var at = new ArticleLanguage()
                    {
                        Language = search.SearchString
                    };
                    requestMessage.Content = new ObjectContent <ArticleLanguage>(at, new JsonMediaTypeFormatter());
                }
                else if (search.Criteria == "Date")
                {
                    var at = new ArticlePulished()
                    {
                        PublishedDate = Convert.ToDateTime(search.SearchString)
                    };
                    requestMessage.Content = new ObjectContent <ArticlePulished>(at, new JsonMediaTypeFormatter());
                }

                return(requestMessage);
            }
            catch (Exception ex)
            {
                // log the error here
                logger.Error(ex.Message);
                return(null);
            }
        }