コード例 #1
0
ファイル: EFModelTest.cs プロジェクト: MKruglov/1sSupportBack
        public void CanInitialOpenedArticle()
        {
            var provider = new Provider(providerName, dateProviderEnd);
            var user     = new User(userLogin, userEmail, userInn)
            {
                Provider = provider
            };
            var session = new Session(user);
            var query   = new SearchingQuery(queryText, session);
            var article = new Article(articleTitle, articleText);
            var date    = DateTime.Now;

            var openedArticle = new OpenedArticle(date, article, query);

            Assert.NotNull(openedArticle);
            Assert.Equal(openedArticle.Article, article);
            Assert.Equal(openedArticle.SearchingQuery, query);
            Assert.Equal(openedArticle.Time, date);
        }
コード例 #2
0
        public async Task <IActionResult> GetArticle(
            [FromQuery][Range(1, int.MaxValue)] int id,
            [FromQuery] string query)
        {
            var article = await(from a in context.Articles where a.Id == id select a).FirstOrDefaultAsync();
            var queryDB =
                await(from q in context.SearchingQueries where q.Text == query select q).FirstOrDefaultAsync();

            if (article == null || queryDB == null)
            {
                return(NotFound(id));
            }

            var openedArticle = new OpenedArticle(DateTime.UtcNow, article, queryDB);

            context.OpenedArticles.Add(openedArticle);
            context.SaveChangesAsync();

            return(Ok(new { article.Id, article.Title, article.Text }));
        }