예제 #1
0
        //Query6:Получить следующую структуру (передать Id поста в параметры)
        //Пост
        //Самый длинный коммент поста
        //Самый залайканный коммент поста
        //Количество комментов под постом где или 0 лайков или длина текста< 80
        private PostStruct Query6(int postId)
        {
            PostStruct postStruct = new PostStruct();

            try
            {
                var      data        = getDataDelegate.Invoke();
                FullPost currentPost = data.SelectMany(u => u.Posts)
                                       .Where(u => u.Id == postId)
                                       .FirstOrDefault();
                postStruct.LongestComm = currentPost.Comments
                                         .OrderBy(c => c.Body.Length)
                                         .LastOrDefault();
                postStruct.LikestComm = currentPost.Comments
                                        .OrderBy(c => c.Likes)
                                        .LastOrDefault();
                List <Comment> subresult = currentPost.Comments
                                           .Where(p => p.Likes == 0 || p.Body.Length < 80).ToList();

                Console.WriteLine($"Current: {currentPost} \nAll comments: ");

                foreach (var item in currentPost.Comments)
                {
                    Console.WriteLine(item);
                }
                Console.WriteLine("\nSelected comments");
                foreach (var item in subresult)
                {
                    Console.WriteLine(item);
                }
                postStruct.LowRatedCommsCount = subresult.Count();
            }
            catch (Exception ex)
            {
                Console.Clear();
                Console.WriteLine(ex.Message);
                Console.ReadKey();
            }

            return(postStruct);
        }
예제 #2
0
파일: Menu.cs 프로젝트: TattiS/Task1App
        private void Show(PostStruct post)
        {
            Console.Write("The longest comment: ");
            if (post.LongestComm != null)
            {
                Console.WriteLine(post.LongestComm);
            }
            else
            {
                Console.WriteLine("None");
            }

            Console.Write("The likest comment: ");
            if (post.LikestComm != null)
            {
                Console.WriteLine(post.LikestComm);
            }
            else
            {
                Console.WriteLine("None");
            }

            Console.WriteLine($"The number of low-rated comments: {post.LowRatedCommsCount}");
        }