1000 по id

This commit is contained in:
Владимир Данилов 2024-05-20 17:19:20 +04:00
parent cb6251ab2b
commit 0a3d0f073f
3 changed files with 23 additions and 8 deletions

View File

@ -15,6 +15,8 @@ namespace NewsBlogAbstractions.WorkAbstractions
Author? Create(Author author); Author? Create(Author author);
Author? CreateId(Author author);
Author? Update(Author author); Author? Update(Author author);
Author? Delete(int id); Author? Delete(int id);

View File

@ -23,6 +23,19 @@ namespace NewsBlogDatabaseImplementation.WorkImplementation
return author; 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) public Author? Delete(int id)
{ {
var element = Get(id); var element = Get(id);

View File

@ -66,11 +66,12 @@ namespace NewsBlogView
{ {
Author author = new() Author author = new()
{ {
Id = i + 1000,
Name = "ÔÈÎ " + i, Name = "ÔÈÎ " + i,
Description = "Îïèñàíèå " + i, Description = "Îïèñàíèå " + i,
Phone = "Íîìåð " + i Phone = "Íîìåð " + i
}; };
authorLogic.Create(author); authorLogic.CreateId(author);
} }
DateTime endTime = DateTime.Now; DateTime endTime = DateTime.Now;
@ -84,7 +85,8 @@ namespace NewsBlogView
if (service is IAuthorWork authorLogic) if (service is IAuthorWork authorLogic)
{ {
DateTime startTime = DateTime.Now; DateTime startTime = DateTime.Now;
authorLogic.GetAll(); for (int i =0; i < 1000; i++)
authorLogic.Get(i + 1000);
DateTime endTime = DateTime.Now; DateTime endTime = DateTime.Now;
labelTest.Text = $"Ïîëó÷åíèå 1000 ñòðîê âûïîëíåíî çà {(endTime - startTime).TotalMilliseconds} ìèëëèñåêóíä"; labelTest.Text = $"Ïîëó÷åíèå 1000 ñòðîê âûïîëíåíî çà {(endTime - startTime).TotalMilliseconds} ìèëëèñåêóíä";
@ -96,13 +98,12 @@ namespace NewsBlogView
var service = Program.ServiceProvider?.GetService(typeof(IAuthorWork)); var service = Program.ServiceProvider?.GetService(typeof(IAuthorWork));
if (service is IAuthorWork authorLogic) if (service is IAuthorWork authorLogic)
{ {
List<int> ids = authorLogic.GetAll().Select(area => area.Id).ToList();
DateTime startTime = DateTime.Now; DateTime startTime = DateTime.Now;
for (int i = 0; i < ids.Count; i++) for (int i = 0; i < 1000; i++)
{ {
Author author = new() Author author = new()
{ {
Id = ids[i], Id = i + 1000,
Name = "ÔÈÎ " + i + 2000, Name = "ÔÈÎ " + i + 2000,
Description = "Îïèñàíèå " + i + 2000, Description = "Îïèñàíèå " + i + 2000,
Phone = "Íîìåð " + i + 2000 Phone = "Íîìåð " + i + 2000
@ -120,11 +121,10 @@ namespace NewsBlogView
var service = Program.ServiceProvider?.GetService(typeof(IAuthorWork)); var service = Program.ServiceProvider?.GetService(typeof(IAuthorWork));
if (service is IAuthorWork authorLogic) if (service is IAuthorWork authorLogic)
{ {
List<int> ids = authorLogic.GetAll().Select(area => area.Id).ToList();
DateTime startTime = DateTime.Now; 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; DateTime endTime = DateTime.Now;