Exemplo n.º 1
0
 public List <User> GetUsersEntity()
 {
     return(LinqRequests.GetUsersEntity(Users, GetPostsEntity(), Todos));
 }
Exemplo n.º 2
0
        public static void Action()
        {
            int act = 0;
            int userId, postId;

            while (true)
            {
                try
                {
                    act = int.Parse(Console.ReadLine());
                    break;
                }
                catch (FormatException)
                {
                    Console.Clear();
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Uncorrect format entered data!");
                    Console.ForegroundColor = ConsoleColor.White;
                    RequestInfo();
                    continue;
                }
            }

            Console.Clear();

            switch (act)
            {
            case 1:
            {
                if (postsEntity == null)
                {
                    postsEntity = dataSource.GetPostsEntity();
                }

                userId = GetId("user");

                var listPostCount = LinqRequests.CommentsCount(userId, postsEntity);

                if (listPostCount.Count() < 1)
                {
                    Console.WriteLine("This user Id:{0} doesnt have any posts.\n", userId);
                    break;
                }

                foreach (var i in listPostCount)
                {
                    Console.WriteLine("Post:\n {0}\nCount of comments: {1}\n", i.post, i.count);
                }
                break;
            }

            case 2:
            {
                if (postsEntity == null)
                {
                    postsEntity = dataSource.GetPostsEntity();
                }

                userId = GetId("user");

                var listPost = LinqRequests.GetUserComments(userId, postsEntity);

                if (listPost.Count() < 1)
                {
                    Console.WriteLine("This user Id:{0} doesnt have any comments in which body < 50 under post.\n", userId);
                    break;
                }

                foreach (var c in listPost)
                {
                    Console.WriteLine("Comment:\n{0}\n", c);
                }
                break;
            }

            case 3:
            {
                userId = GetId("user");

                var listIdName = LinqRequests.GetUserTodos(userId, dataSource.Todos);

                if (listIdName.Count() < 1)
                {
                    Console.WriteLine("This user Id:{0} doesnt have any completed task.\n", userId);
                    break;
                }

                foreach (var i in listIdName)
                {
                    Console.WriteLine("Todo Id: {0}; Name: {1}\n", i.Id, i.Name);
                }
                break;
            }

            case 4:
            {
                if (usersEntity == null)
                {
                    usersEntity = dataSource.GetUsersEntity();
                }

                foreach (var u in LinqRequests.GetSortedUsers(usersEntity))
                {
                    Console.WriteLine("User Name: {0}", u.Name);

                    foreach (var t in u.Todos)
                    {
                        Console.WriteLine("Todo: {0}", t.Name);
                    }
                    Console.WriteLine();
                }
                break;
            }

            case 5:
            {
                if (usersEntity == null)
                {
                    usersEntity = dataSource.GetUsersEntity();
                }

                userId = GetId("user");

                var i = LinqRequests.GetAdditionalUserInfo(userId, usersEntity);
                Console.WriteLine("User:\n{0}\n", i.User);
                Console.WriteLine("Last Post: {0}\n", i.LastPost == null ? "Absent": i.LastPost.ToString());
                Console.WriteLine("Count commnets: {0}\n", i.CountComments);
                Console.WriteLine("Uncompleted tasks: {0}\n", i.UncompletedTasks);
                Console.WriteLine("Most popular post by comments: {0}\n", i.MostPopularPostByComments == null ? "Absent" : i.MostPopularPostByComments.ToString());
                Console.WriteLine("Most popular post by likes: {0}\n", i.MostPopularPostByLikes == null ? "Absent" : i.MostPopularPostByLikes.ToString());

                break;
            }

            case 6:
            {
                if (postsEntity == null)
                {
                    postsEntity = dataSource.GetPostsEntity();
                }

                postId = GetId("post");

                var i = LinqRequests.GetAdditionalPostInfo(postId, postsEntity);
                Console.WriteLine("Post: {0}\n", i.Post);
                Console.WriteLine("Longest comment: {0}\n", i.LongestComment == null ? "Absent" : i.LongestComment.ToString());
                Console.WriteLine("Likest comment: {0}\n", i.LikestComment == null ? "Absent" : i.LikestComment.ToString());
                Console.WriteLine("Count comments where 0 likes or body < 80: {0}\n", i.CountComments);
                break;
            }

            case 0:
            {
                break;
            }
            }
        }
Exemplo n.º 3
0
 public List <Post> GetPostsEntity()
 {
     return(LinqRequests.GetPostsEntity(Posts, Comments));
 }