public FirstModel GetInfoAboutUserById(int id) { FirstModel firstModel = new FirstModel(); firstModel.userById = users.Find(user => user.id == id); if (firstModel.userById != null) { firstModel.userById.posts.ForEach(post => { if (firstModel.lastPost.createdAt < post.createdAt) { firstModel.lastPost = post; } }); if (firstModel.lastPost.comments != null) { firstModel.countCommentsLastPost = firstModel.lastPost.comments.Count; } firstModel.countTaskNotDone = firstModel.userById.todos.Where(todo => !todo.isComplete).Count(); int countComment = 0; firstModel.userById.posts.ForEach(post => { int currentCountComment = post.comments.Where(comment => comment.body.Length > 80).Count(); if (countComment < currentCountComment) { firstModel.mostPopularPostByLenght = post; countComment = currentCountComment; } }); firstModel.userById.posts.ForEach(post => { if (firstModel.mostPopularPostByLikes.likes < post.likes) { firstModel.mostPopularPostByLikes = post; } }); } return(firstModel); }
public void Start() { while (true) { Console.Clear(); Console.WriteLine("Выберите операцию:\n" + "1 - Получить количество комментов под постами конкретного пользователя (по айди)\n" + "2 - Получить список комментов под постами конкретного пользователя (по айди), где body коммента < 50 символов\n" + "3 - Получить список (id, name) из списка todos которые выполнены для конкретного пользователя (по айди)\n" + "4 - Получить список пользователей по алфавиту (по возрастанию) с отсортированными todo items по длине name (по убыванию)\n" + "5 - Получить информацию о пользователе по айди\n" + "6 - Получить информацию о посте по айди\n" + "7 - Выйти\n"); int selection = Convert.ToInt32(Console.ReadLine()); switch (selection) { case 1: { //recomended id = 11 Console.WriteLine("Введите aйди пользователя: "); int id = Convert.ToInt32(Console.ReadLine()); int count = manipulateData.GetCountCommentsByUserId(id); Console.WriteLine($"Количество комментариев: {count}"); Stop(); } break; case 2: { //recomended id = 46 Console.WriteLine("Введите aйди пользователя: "); int id = Convert.ToInt32(Console.ReadLine()); List <Comment> comments = manipulateData.GetCommentsByUserId(id); if (comments.Count == 0) { Console.WriteLine("No comments"); } else { comments.ForEach(comment => Console.WriteLine(comment)); } Stop(); } break; case 3: { //recomended id = 4 Console.WriteLine("Введите aйди пользователя: "); int id = Convert.ToInt32(Console.ReadLine()); List <Todo> todos = manipulateData.GetDoneTodosByUserId(id); if (todos.Count == 0) { Console.WriteLine("No todos"); } else { todos.ForEach(todo => Console.WriteLine(todo)); } Stop(); } break; case 4: { List <User> users = manipulateData.GetOrderedListOfUsers(); users.ForEach(user => Console.WriteLine(user.Show())); Stop(); } break; case 5: { //recomended id = 12 Console.WriteLine("Введите aйди пользователя: "); int id = Convert.ToInt32(Console.ReadLine()); FirstModel firstModel = manipulateData.GetInfoAboutUserById(id); Console.WriteLine(firstModel); Stop(); } break; case 6: { //recomended id = 48 Console.WriteLine("Введите aйди поста: "); int id = Convert.ToInt32(Console.ReadLine()); SecondModel secondModel = manipulateData.GetInfoAboutPostById(id); Console.WriteLine(secondModel); Stop(); } break; case 7: { Environment.Exit(0); } break; default: break; } } }