From 18c17156f173d0251ddc054d1e7624e767ed98f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=9A=D1=83=D0=BA?= =?UTF-8?q?=D0=BB=D0=B5=D0=B2?= Date: Tue, 30 Apr 2024 18:41:34 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=90=D0=B9=D0=BA=20=D1=8D=20=D0=B1?= =?UTF-8?q?=D0=BE=D1=81=D1=81=20=D0=B4=D0=B8=D1=80=D0=B5=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=20=D1=81=D1=82=D0=BE=D1=80=D1=8D=D0=B4=D0=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CarCenterDatabaseImplement.csproj | 1 - .../{CarCenteDb.cs => CarCenterDb.cs} | 0 .../Implements/DirectorStorage.cs | 38 +++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) rename CarCenterDatabaseImplement/{CarCenteDb.cs => CarCenterDb.cs} (100%) create mode 100644 CarCenterDatabaseImplement/Implements/DirectorStorage.cs diff --git a/CarCenterDatabaseImplement/CarCenterDatabaseImplement.csproj b/CarCenterDatabaseImplement/CarCenterDatabaseImplement.csproj index 24ad2e8..aed3a89 100644 --- a/CarCenterDatabaseImplement/CarCenterDatabaseImplement.csproj +++ b/CarCenterDatabaseImplement/CarCenterDatabaseImplement.csproj @@ -7,7 +7,6 @@ - diff --git a/CarCenterDatabaseImplement/CarCenteDb.cs b/CarCenterDatabaseImplement/CarCenterDb.cs similarity index 100% rename from CarCenterDatabaseImplement/CarCenteDb.cs rename to CarCenterDatabaseImplement/CarCenterDb.cs diff --git a/CarCenterDatabaseImplement/Implements/DirectorStorage.cs b/CarCenterDatabaseImplement/Implements/DirectorStorage.cs new file mode 100644 index 0000000..4bbbcf0 --- /dev/null +++ b/CarCenterDatabaseImplement/Implements/DirectorStorage.cs @@ -0,0 +1,38 @@ +using CarCenterContracts.BindingModels; +using CarCenterContracts.SearchModels; +using CarCenterContracts.StoragesContracts; +using CarCenterContracts.ViewModels; +using CarCenterDatabaseImplement.Models; + +namespace CarCenterDatabaseImplement.Implements +{ + public class DirectorStorage : IDirectorStorage + { + private void CheckSearchModel(DirectorSearchModel model) + { + if (model == null) + throw new ArgumentNullException("Передаваемая модель для поиска равна нулю", nameof(model)); + if (!model.Id.HasValue && string.IsNullOrEmpty(model.Login) && string.IsNullOrEmpty(model.Password)) + throw new ArgumentException("Все передаваемые поля поисковой модели оказались пусты или равны null"); + } + public DirectorViewModel? GetElement(DirectorSearchModel model) + { + CheckSearchModel(model); + using var context = new CarCenterDb(); + return context.Directors + .FirstOrDefault(x => x.Login.Equals(model.Login) && (string.IsNullOrEmpty(model.Password) || x.Password.Equals(model.Password))); + } + public DirectorViewModel? Insert(DirectorBindingModel model) + { + if (model == null) + { + return null; + } + var newDirector = Director.Create(model); + using var context = new CarCenterDb(); + context.Directors.Add(newDirector); + context.SaveChanges(); + return newDirector; + } + } +}