Ejemplo n.º 1
0
        private static Comment InitComment()
        {
            string text;

            while (true)
            {
                Console.Write("Введите текст комментария: ");
                text = Console.ReadLine();

                if (text.Length == 0)
                {
                    Console.WriteLine("Ошибка! Попробуйте снова!");
                }
                else
                {
                    break;
                }

                Console.ReadLine();
                Console.Clear();
            }

            List <Article> articles;

            using (var articlesRepository = new ArticlesRepository(connectionString))
            {
                articles = articlesRepository.GetAll().ToList();
            }

            foreach (var article in articles)
            {
                Console.WriteLine($"{article.Name}");
            }

            Console.Write("Введите полное название статьи:");
            string nameArticle = Console.ReadLine();

            Article tempArticle = articles.Where(a => a.Name.ToLower() == nameArticle.ToLower()).FirstOrDefault();

            var comment = new Comment
            {
                Text      = text,
                ArticleId = tempArticle.Id
            };

            return(comment);
        }
Ejemplo n.º 2
0
 public ArticleQuery(ArticlesRepository repository)
 {
     FieldAsync <ListGraphType <ArticleType> >(
         "articles",
         resolve: async context => await repository.GetAll()
         );
     FieldAsync <ArticleType>(
         name: "article",
         arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> >
     {
         Name        = "id",
         Description = "The id of the article you want to see"
     }),
         resolve: async context =>
     {
         var id = context.GetArgument <string>("id");
         return(await context.TryAsyncResolve(async c => await repository.GetById(Guid.Parse((ReadOnlySpan <char>)id))));
     }
         );
     FieldAsync <ListGraphType <ArticleType> >(
         "recentArticlesByCategory",
         arguments: new QueryArguments(new QueryArgument <NonNullGraphType <ArticlesTypeEnumType> >
     {
         Name = "category"
     }),
         resolve: async context =>
     {
         var type = context.GetArgument <ArticleTypesEnum>("category");
         return(await context.TryAsyncResolve(
                    async c => await repository.GetLatestArticlesForCategory(type)));
     }
         );
     FieldAsync <ListGraphType <ArticleType> >(
         "articlesForPublisherName",
         arguments: new QueryArguments(new QueryArgument <NonNullGraphType <StringGraphType> >
     {
         Name = "publisherName"
     }),
         resolve: async context =>
     {
         var pub = context.GetArgument <string>("publisherName");
         return(await context.TryAsyncResolve(
                    async c => await repository.GetArticlesOfPublisher(pub)
                    ));
     }
         );
 }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            DoMigration();

            while (true)
            {
                Console.WriteLine("1. Добавить статью\n2.Добавить комментарий\n3.Показать новости\n4.Выход");
                Console.Write("Выберите действие: ");

                if (!int.TryParse(Console.ReadLine(), out int action))
                {
                    Console.WriteLine("Ошибка! Введите цифры!");
                }
                else if (action < 0 || action > 5)
                {
                    Console.WriteLine("Не существует такого действия!");
                }

                if (action == 1)
                {
                    var article = InitArticle();

                    using (var articleRepository = new ArticlesRepository(connectionString))
                    {
                        articleRepository.Add(article);

                        Console.WriteLine("Статья успешно добавлена!");
                    }
                }
                else if (action == 2)
                {
                    var comment = InitComment();

                    using (var commentRepository = new CommentsRepository(connectionString))
                    {
                        commentRepository.Add(comment);

                        Console.WriteLine("Коммент успешно добавлен!");
                    }
                }
                else if (action == 3)
                {
                    List <Article> articles;

                    using (var articlesRepository = new ArticlesRepository(connectionString))
                    {
                        articles = articlesRepository.GetAll().ToList();
                    }

                    foreach (var article in articles)
                    {
                        Console.WriteLine($"{article.Name}");
                    }
                }
                else if (action == 4)
                {
                    break;
                }

                Console.ReadLine();
                Console.Clear();
            }
        }