From efe87a6a04fbba1b7132dea26e1b8c0a013a2ed8 Mon Sep 17 00:00:00 2001 From: "ityurner02@mail.ru" Date: Sun, 30 Apr 2023 13:04:29 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BE=D0=BD=D0=BE=20=D1=80=D0=B0=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/ClientStorage.cs | 38 +++++++++++-------- .../Implements/MessageInfoStorage.cs | 4 +- ...=> 20230430082314_WithMessage.Designer.cs} | 2 +- ...ssage.cs => 20230430082314_WithMessage.cs} | 0 .../Models/Message.cs | 6 +-- 5 files changed, 27 insertions(+), 23 deletions(-) rename PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/{20230429174158_WithMessage.Designer.cs => 20230430082314_WithMessage.Designer.cs} (99%) rename PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/{20230429174158_WithMessage.cs => 20230430082314_WithMessage.cs} (100%) diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/ClientStorage.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/ClientStorage.cs index b2a6b8e..ceb11f7 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/ClientStorage.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/ClientStorage.cs @@ -13,7 +13,6 @@ namespace PlumbingRepairDatabaseImplement.Implements { using var context = new PlumbingRepairDataBase(); return context.Clients - .Include(x => x.Orders) .Select(x => x.GetViewModel) .ToList(); } @@ -23,11 +22,15 @@ namespace PlumbingRepairDatabaseImplement.Implements { return new(); } - if (!string.IsNullOrEmpty(model.Email)) + if (model.Id.HasValue) + { + var res = GetElement(model); + return res != null ? new() { res } : new(); + } + if (!string.IsNullOrEmpty(model.Email)) { using var context = new PlumbingRepairDataBase(); return context.Clients - .Include(x => x.Orders) .Where(x => x.Email.Contains(model.Email)) .Select(x => x.GetViewModel) .ToList(); @@ -36,19 +39,22 @@ namespace PlumbingRepairDatabaseImplement.Implements } public ClientViewModel? GetElement(ClientSearchModel model) { - using var context = new PlumbingRepairDataBase(); - if (model.Id.HasValue) - { - return context.Clients - .FirstOrDefault(x => (x.Id == model.Id))?.GetViewModel; - } - else if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password)) - { - return context.Clients - .FirstOrDefault(x => (x.Email == model.Email && x.Password == model.Password))?.GetViewModel; - } - return new(); - } + if (string.IsNullOrEmpty(model.ClientFIO) && + string.IsNullOrEmpty(model.Email) && + string.IsNullOrEmpty(model.Password) && + !model.Id.HasValue) + { + return null; + } + using var context = new PlumbingRepairDataBase(); + var temp = context.Clients + .FirstOrDefault(x => (string.IsNullOrEmpty(model.ClientFIO) || x.ClientFIO == model.ClientFIO) && + (string.IsNullOrEmpty(model.Email) || x.Email == model.Email) && + (string.IsNullOrEmpty(model.Password) || x.Password == model.Password) && + (!model.Id.HasValue || x.Id == model.Id)) + ?.GetViewModel; + return temp; + } public ClientViewModel? Insert(ClientBindingModel model) { var newClient = Client.Create(model); diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/MessageInfoStorage.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/MessageInfoStorage.cs index 2511ee4..fce8c93 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/MessageInfoStorage.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/MessageInfoStorage.cs @@ -10,8 +10,10 @@ namespace PlumbingRepairDatabaseImplement.Implements { public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) { - if (model.MessageId == null) + if (string.IsNullOrEmpty(model.MessageId)) + { return null; + } using var context = new PlumbingRepairDataBase(); return context.Messages.FirstOrDefault(x => x.MessageId == model.MessageId)?.GetViewModel; } diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20230429174158_WithMessage.Designer.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20230430082314_WithMessage.Designer.cs similarity index 99% rename from PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20230429174158_WithMessage.Designer.cs rename to PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20230430082314_WithMessage.Designer.cs index 1c7f839..7d99ac3 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20230429174158_WithMessage.Designer.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20230430082314_WithMessage.Designer.cs @@ -12,7 +12,7 @@ using PlumbingRepairDatabaseImplement; namespace PlumbingRepairDatabaseImplement.Migrations { [DbContext(typeof(PlumbingRepairDataBase))] - [Migration("20230429174158_WithMessage")] + [Migration("20230430082314_WithMessage")] partial class WithMessage { /// diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20230429174158_WithMessage.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20230430082314_WithMessage.cs similarity index 100% rename from PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20230429174158_WithMessage.cs rename to PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20230430082314_WithMessage.cs diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Message.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Message.cs index 1b486dd..733c013 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Message.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Message.cs @@ -10,13 +10,9 @@ namespace PlumbingRepairDatabaseImplement.Models [Key] public string MessageId { get; private set; } = string.Empty; public int? ClientId { get; private set; } - [Required] public string SenderName { get; private set; } = string.Empty; - [Required] - public DateTime DateDelivery { get; private set; } - [Required] + public DateTime DateDelivery { get; private set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc); public string Subject { get; private set; } = string.Empty; - [Required] public string Body { get; private set; } = string.Empty; public virtual Client? Client { get; set; }