From 5bb854182dcbf00a5582e8eb2fd4a0100f4a8dd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=9F=D1=83=D1=82=D0=B8?= =?UTF-8?q?=D0=BB=D0=B8=D0=BD?= Date: Wed, 19 Apr 2023 17:35:52 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D0=B8=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- News/News/Controller.cs | 16 ++++++++++++++++ News/News/EnterText.txt | 3 ++- News/News/Program.cs | 19 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/News/News/Controller.cs b/News/News/Controller.cs index c7f5e97..250ec87 100644 --- a/News/News/Controller.cs +++ b/News/News/Controller.cs @@ -56,5 +56,21 @@ namespace News Console.WriteLine(e.InnerException.Message); } } + + public Comment? GetComment(int UserId, int NewsId) + { + return _context.Comments.FirstOrDefault(x => x.UserId == UserId && x.NewsId == NewsId); + } + + public void RemoveComment(Comment comment) + { + _context.Comments.Remove(comment); + _context.SaveChanges(); + } + + public void UpdateComment(Comment comment) + { + _context.SaveChanges(); + } } } diff --git a/News/News/EnterText.txt b/News/News/EnterText.txt index c7e2d48..2e7c2a9 100644 --- a/News/News/EnterText.txt +++ b/News/News/EnterText.txt @@ -4,4 +4,5 @@ 3 Получить всех авторов 4 Получить всех пользователей 5 Добавить пользователя -6 Запустить тестирование всех функций \ No newline at end of file +6 Запустить тестирование всех функций +7 Изменить текст комментария или удалить комментарий \ No newline at end of file diff --git a/News/News/Program.cs b/News/News/Program.cs index 201c34b..7afe19d 100644 --- a/News/News/Program.cs +++ b/News/News/Program.cs @@ -47,6 +47,25 @@ namespace News case "6": Test(controller, context); break; + case "7": + Console.WriteLine($"Введите Id новости Рё Id пользователя"); + var userId = Convert.ToInt32(Console.ReadLine()); + var newsId = Convert.ToInt32(Console.ReadLine()); + var comment = controller.GetComment(userId, newsId); + Console.WriteLine($"1 для изменения, 2 для удаления"); + var r = Console.ReadLine(); + if (r == "1") + { + Console.WriteLine($"Введите новый текст комментария"); + var s = Console.ReadLine(); + comment.CommentText = s; + controller.UpdateComment(comment); + } + if (r == "2") + { + controller.RemoveComment(comment); + } + break; default: Console.WriteLine("Такой операции нет"); break;