From f827ae191587063990a1217f5c230a8a86be9104 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Wed, 15 May 2024 23:59:52 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20=D0=BF?= =?UTF-8?q?=D0=BE=20=D1=85=D1=80=D0=B0=D0=BD=D0=B8=D0=BB=D0=B8=D1=89=D0=B0?= =?UTF-8?q?=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractPostgresqlStorage.cs | 15 ++++----------- .../Storages/DiagnoseStorage.cs | 6 +++--- .../Storages/DoctorStorage.cs | 10 +++++----- .../Storages/PatientStorage.cs | 16 ++++++++-------- .../Storages/SpecializationStorage.cs | 10 +++++----- .../Storages/VisitStorage.cs | 18 +++++++++--------- 6 files changed, 34 insertions(+), 41 deletions(-) diff --git a/Medical/MedicalPostgresqlDatabase/AbstractPostgresqlStorage.cs b/Medical/MedicalPostgresqlDatabase/AbstractPostgresqlStorage.cs index f088503..6c352a5 100644 --- a/Medical/MedicalPostgresqlDatabase/AbstractPostgresqlStorage.cs +++ b/Medical/MedicalPostgresqlDatabase/AbstractPostgresqlStorage.cs @@ -27,7 +27,7 @@ namespace MedicalPostgresqlDatabase protected abstract T CreateEntityFromReader(NpgsqlDataReader reader); - protected abstract Dictionary GetEntityAttributesDictionary(T item); + protected abstract Dictionary GetEntityAttributesDictionary(T item); public virtual void Delete(int id) { @@ -54,8 +54,8 @@ namespace MedicalPostgresqlDatabase { using var connection = GetConnection(); connection.Open(); - using var cmd = new NpgsqlCommand($"SELECT * FROM {TABLE_NAME} WHERE {PRIMARY_KEY_COLUMN_NAME} = @{PRIMARY_KEY_COLUMN_NAME}", connection); - cmd.Parameters.AddWithValue($"@{PRIMARY_KEY_COLUMN_NAME}", id); + using var cmd = new NpgsqlCommand($"SELECT * FROM {TABLE_NAME} WHERE {PRIMARY_KEY_COLUMN_NAME} = @id", connection); + cmd.Parameters.AddWithValue($"@id", id); _logger.LogDebug(cmd.CommandText); Stopwatch stopwatch = new(); stopwatch.Start(); @@ -167,14 +167,7 @@ namespace MedicalPostgresqlDatabase foreach (var key in dict.Keys) { - if (key == PRIMARY_KEY_COLUMN_NAME) - { - cmd.Parameters.AddWithValue($"@{key}", Convert.ToInt32(dict[key])); - } - else - { - cmd.Parameters.AddWithValue($"@{key}", dict[key]); - } + cmd.Parameters.AddWithValue($"@{key}", dict[key]); } _logger.LogDebug(cmd.CommandText); diff --git a/Medical/MedicalPostgresqlDatabase/Storages/DiagnoseStorage.cs b/Medical/MedicalPostgresqlDatabase/Storages/DiagnoseStorage.cs index 9eb1361..992e71e 100644 --- a/Medical/MedicalPostgresqlDatabase/Storages/DiagnoseStorage.cs +++ b/Medical/MedicalPostgresqlDatabase/Storages/DiagnoseStorage.cs @@ -18,11 +18,11 @@ namespace MedicalPostgresqlDatabase.Storages }; } - protected override Dictionary GetEntityAttributesDictionary(Diagnose item) + protected override Dictionary GetEntityAttributesDictionary(Diagnose item) { - var dict = new Dictionary + var dict = new Dictionary { - { PRIMARY_KEY_COLUMN_NAME, item.Id.ToString() }, + { PRIMARY_KEY_COLUMN_NAME, item.Id }, { "name", item.Name }, }; return dict; diff --git a/Medical/MedicalPostgresqlDatabase/Storages/DoctorStorage.cs b/Medical/MedicalPostgresqlDatabase/Storages/DoctorStorage.cs index 991916e..cb98154 100644 --- a/Medical/MedicalPostgresqlDatabase/Storages/DoctorStorage.cs +++ b/Medical/MedicalPostgresqlDatabase/Storages/DoctorStorage.cs @@ -22,16 +22,16 @@ namespace MedicalPostgresqlDatabase.Storages }; } - protected override Dictionary GetEntityAttributesDictionary(Doctor item) + protected override Dictionary GetEntityAttributesDictionary(Doctor item) { - var dict = new Dictionary + var dict = new Dictionary { - { PRIMARY_KEY_COLUMN_NAME, item.Id.ToString() }, + { PRIMARY_KEY_COLUMN_NAME, item.Id }, { "name", item.Name }, { "surname", item.Surname }, - { "patronymic", item.Patronymic }, + { "patronymic", item.Patronymic ?? string.Empty }, { "phone_number", item.PhoneNumber }, - { "specialization_id", item.SpecializationId.ToString() } + { "specialization_id", item.SpecializationId } }; return dict; } diff --git a/Medical/MedicalPostgresqlDatabase/Storages/PatientStorage.cs b/Medical/MedicalPostgresqlDatabase/Storages/PatientStorage.cs index a18134f..2f991d9 100644 --- a/Medical/MedicalPostgresqlDatabase/Storages/PatientStorage.cs +++ b/Medical/MedicalPostgresqlDatabase/Storages/PatientStorage.cs @@ -25,19 +25,19 @@ namespace MedicalPostgresqlDatabase.Storages }; } - protected override Dictionary GetEntityAttributesDictionary(Patient item) + protected override Dictionary GetEntityAttributesDictionary(Patient item) { - var dict = new Dictionary + var dict = new Dictionary { - { PRIMARY_KEY_COLUMN_NAME, item.Id.ToString() }, + { PRIMARY_KEY_COLUMN_NAME, item.Id }, { "name", item.Name }, { "surname", item.Surname }, - { "patronymic", item.Patronymic }, + { "patronymic", item.Patronymic ?? string.Empty }, { "phone_number", item.PhoneNumber }, - { "gender", item.Gender.ToString() }, - { "birthday", item.Birthday.ToString() }, - { "weight", item.Weight.ToString() }, - { "height", item.Height.ToString() }, + { "gender", item.Gender }, + { "birthday", item.Birthday }, + { "weight", item.Weight }, + { "height", item.Height }, }; return dict; } diff --git a/Medical/MedicalPostgresqlDatabase/Storages/SpecializationStorage.cs b/Medical/MedicalPostgresqlDatabase/Storages/SpecializationStorage.cs index a8804ff..af2e920 100644 --- a/Medical/MedicalPostgresqlDatabase/Storages/SpecializationStorage.cs +++ b/Medical/MedicalPostgresqlDatabase/Storages/SpecializationStorage.cs @@ -21,14 +21,14 @@ namespace MedicalPostgresqlDatabase.Storages }; } - protected override Dictionary GetEntityAttributesDictionary(Specialization item) + protected override Dictionary GetEntityAttributesDictionary(Specialization item) { - var dict = new Dictionary + var dict = new Dictionary { - { PRIMARY_KEY_COLUMN_NAME, item.Id.ToString() }, + { PRIMARY_KEY_COLUMN_NAME, item.Id }, { "name", item.Name }, - { "is_pediatric", item.IsPediatric.ToString() }, - { "is_therapeutic", item.IsTherapeutic.ToString() }, + { "is_pediatric", item.IsPediatric }, + { "is_therapeutic", item.IsTherapeutic }, }; return dict; } diff --git a/Medical/MedicalPostgresqlDatabase/Storages/VisitStorage.cs b/Medical/MedicalPostgresqlDatabase/Storages/VisitStorage.cs index e4858bb..e3877f2 100644 --- a/Medical/MedicalPostgresqlDatabase/Storages/VisitStorage.cs +++ b/Medical/MedicalPostgresqlDatabase/Storages/VisitStorage.cs @@ -24,17 +24,17 @@ namespace MedicalPostgresqlDatabase.Storages }; } - protected override Dictionary GetEntityAttributesDictionary(Visit item) + protected override Dictionary GetEntityAttributesDictionary(Visit item) { - var dict = new Dictionary + var dict = new Dictionary { - { PRIMARY_KEY_COLUMN_NAME, item.Id.ToString() }, - { "patient_id", item.PatientId.ToString() }, - { "doctor_id", item.DoctorId.ToString() }, - { "diagnose_id", item.DiagnoseId.ToString() }, - { "comment", item.Comment ?? string.Empty }, - { "date", item.Date.ToString() }, - { "time", item.Time.ToString() }, + { PRIMARY_KEY_COLUMN_NAME, item.Id }, + { "patient_id", item.PatientId }, + { "doctor_id", item.DoctorId }, + { "diagnose_id", item.DiagnoseId }, + { "comment", item.Comment }, + { "date", item.Date }, + { "time", item.Time }, }; return dict; }