diff --git a/NewsBlog/NewsBlogAbstractions/WorkAbstractions/IAuthorWork.cs b/NewsBlog/NewsBlogAbstractions/WorkAbstractions/IAuthorWork.cs index c07fdab..b06610e 100644 --- a/NewsBlog/NewsBlogAbstractions/WorkAbstractions/IAuthorWork.cs +++ b/NewsBlog/NewsBlogAbstractions/WorkAbstractions/IAuthorWork.cs @@ -15,6 +15,8 @@ namespace NewsBlogAbstractions.WorkAbstractions Author? Create(Author author); + Author? CreateId(Author author); + Author? Update(Author author); Author? Delete(int id); diff --git a/NewsBlog/NewsBlogDatabaseImplementation/WorkImplementation/AuthorWork.cs b/NewsBlog/NewsBlogDatabaseImplementation/WorkImplementation/AuthorWork.cs index de655dd..d996345 100644 --- a/NewsBlog/NewsBlogDatabaseImplementation/WorkImplementation/AuthorWork.cs +++ b/NewsBlog/NewsBlogDatabaseImplementation/WorkImplementation/AuthorWork.cs @@ -23,6 +23,19 @@ namespace NewsBlogDatabaseImplementation.WorkImplementation return author; } + public Author? CreateId(Author author) + { + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand("INSERT INTO author (author_id, name, description, phone) VALUES (@Author_id, @Name, @Description, @Phone)", con); + cmd.Parameters.AddWithValue("@Author_id", author.Id); + cmd.Parameters.AddWithValue("@Name", author.Name); + cmd.Parameters.AddWithValue("@Description", author.Description); + cmd.Parameters.AddWithValue("@Phone", author.Phone); + cmd.ExecuteNonQuery(); + return author; + } + public Author? Delete(int id) { var element = Get(id); diff --git a/NewsBlog/NewsBlogView/FormMain.cs b/NewsBlog/NewsBlogView/FormMain.cs index 6054b70..0ca8c5e 100644 --- a/NewsBlog/NewsBlogView/FormMain.cs +++ b/NewsBlog/NewsBlogView/FormMain.cs @@ -66,11 +66,12 @@ namespace NewsBlogView { Author author = new() { + Id = i + 1000, Name = "ФИО " + i, Description = "Описание " + i, Phone = "Номер " + i }; - authorLogic.Create(author); + authorLogic.CreateId(author); } DateTime endTime = DateTime.Now; @@ -84,7 +85,8 @@ namespace NewsBlogView if (service is IAuthorWork authorLogic) { DateTime startTime = DateTime.Now; - authorLogic.GetAll(); + for (int i =0; i < 1000; i++) + authorLogic.Get(i + 1000); DateTime endTime = DateTime.Now; labelTest.Text = $"Получение 1000 строк выполнено за {(endTime - startTime).TotalMilliseconds} миллисекунд"; @@ -96,13 +98,12 @@ namespace NewsBlogView var service = Program.ServiceProvider?.GetService(typeof(IAuthorWork)); if (service is IAuthorWork authorLogic) { - List ids = authorLogic.GetAll().Select(area => area.Id).ToList(); DateTime startTime = DateTime.Now; - for (int i = 0; i < ids.Count; i++) + for (int i = 0; i < 1000; i++) { Author author = new() { - Id = ids[i], + Id = i + 1000, Name = "ФИО " + i + 2000, Description = "Описание " + i + 2000, Phone = "Номер " + i + 2000 @@ -120,11 +121,10 @@ namespace NewsBlogView var service = Program.ServiceProvider?.GetService(typeof(IAuthorWork)); if (service is IAuthorWork authorLogic) { - List ids = authorLogic.GetAll().Select(area => area.Id).ToList(); DateTime startTime = DateTime.Now; - for (int i = 0; i < ids.Count; i++) + for (int i = 0; i < 1000; i++) { - authorLogic.Delete(ids[i]); + authorLogic.Delete(i + 1000); } DateTime endTime = DateTime.Now;