From 840c1176d321e200200a05794880da5996efa5ba Mon Sep 17 00:00:00 2001 From: sardq Date: Sat, 11 May 2024 19:41:48 +0400 Subject: [PATCH] =?UTF-8?q?=D1=84=D0=B8=D0=BD=D0=B0=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D1=8B=D0=B5=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PlumbingRepair/PlumbingRepair.sln | 20 ++--- .../BusinessLogics/OrderLogic.cs | 8 +- .../Implements/MessageInfoStorage.cs | 24 ++--- .../Implements/OrderStorage.cs | 90 +++++++++++++------ ... => 20240503110424_InitCreate.Designer.cs} | 15 +--- ...Create.cs => 20240503110424_InitCreate.cs} | 38 +++----- .../PlumbingRepairDatabaseModelSnapshot.cs | 13 --- .../Models/Client.cs | 2 - .../Models/MessageInfo.cs | 1 - 9 files changed, 107 insertions(+), 104 deletions(-) rename PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/{20240503080749_InitCreate.Designer.cs => 20240503110424_InitCreate.Designer.cs} (95%) rename PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/{20240503080749_InitCreate.cs => 20240503110424_InitCreate.cs} (95%) diff --git a/PlumbingRepair/PlumbingRepair.sln b/PlumbingRepair/PlumbingRepair.sln index e91f191..5d951e8 100644 --- a/PlumbingRepair/PlumbingRepair.sln +++ b/PlumbingRepair/PlumbingRepair.sln @@ -17,9 +17,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairFileImplement EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairDatabaseImplement", "PlumbingRepairDatabaseImplement\PlumbingRepairDatabaseImplement.csproj", "{6DDC0CCD-97E0-4CB7-8024-C27DB9AEF97B}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairClientApp", "..\..\PlumbingRepair 7 база\PlumbingRepairClientApp\PlumbingRepairClientApp.csproj", "{4F1E898C-449A-4A60-95D8-BC7818019644}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairClientApp", "..\..\PlumbingRepair 7 база\PlumbingRepairClientApp\PlumbingRepairClientApp.csproj", "{712EBB90-7365-4F29-B7C6-91E3F5157B0C}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairRestApi", "..\..\PlumbingRepair 7 база\PlumbingRepairRestApi\PlumbingRepairRestApi.csproj", "{CEB61A52-7C4D-45CC-A48B-E52B295EE28E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairRestApi", "..\..\PlumbingRepair 7 база\PlumbingRepairRestApi\PlumbingRepairRestApi.csproj", "{6CCF4B9D-A4CC-4751-A471-19DAA710413B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -55,14 +55,14 @@ Global {6DDC0CCD-97E0-4CB7-8024-C27DB9AEF97B}.Debug|Any CPU.Build.0 = Debug|Any CPU {6DDC0CCD-97E0-4CB7-8024-C27DB9AEF97B}.Release|Any CPU.ActiveCfg = Release|Any CPU {6DDC0CCD-97E0-4CB7-8024-C27DB9AEF97B}.Release|Any CPU.Build.0 = Release|Any CPU - {4F1E898C-449A-4A60-95D8-BC7818019644}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4F1E898C-449A-4A60-95D8-BC7818019644}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4F1E898C-449A-4A60-95D8-BC7818019644}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4F1E898C-449A-4A60-95D8-BC7818019644}.Release|Any CPU.Build.0 = Release|Any CPU - {CEB61A52-7C4D-45CC-A48B-E52B295EE28E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {CEB61A52-7C4D-45CC-A48B-E52B295EE28E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CEB61A52-7C4D-45CC-A48B-E52B295EE28E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {CEB61A52-7C4D-45CC-A48B-E52B295EE28E}.Release|Any CPU.Build.0 = Release|Any CPU + {712EBB90-7365-4F29-B7C6-91E3F5157B0C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {712EBB90-7365-4F29-B7C6-91E3F5157B0C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {712EBB90-7365-4F29-B7C6-91E3F5157B0C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {712EBB90-7365-4F29-B7C6-91E3F5157B0C}.Release|Any CPU.Build.0 = Release|Any CPU + {6CCF4B9D-A4CC-4751-A471-19DAA710413B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6CCF4B9D-A4CC-4751-A471-19DAA710413B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6CCF4B9D-A4CC-4751-A471-19DAA710413B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6CCF4B9D-A4CC-4751-A471-19DAA710413B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/OrderLogic.cs b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/OrderLogic.cs index ff17bd4..ea535f9 100644 --- a/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/OrderLogic.cs @@ -137,8 +137,8 @@ namespace PlumbingRepairBusinessLogic.BusinessLogics mailModel = new MailSendInfoBindingModel { MailAddress = clientModel.Email, - Subject = $"Order №{orderModel.Id}", - Text = $"Your order №{orderModel.Id} by {orderModel.DateCreate} on {orderModel.Sum} was accepted!" + Subject = $"Заказ №{orderModel.Id}", + Text = $"Ваш заказ №{orderModel.Id} в {orderModel.DateCreate} на сумму {orderModel.Sum} был принят!" }; } else @@ -146,8 +146,8 @@ namespace PlumbingRepairBusinessLogic.BusinessLogics mailModel = new MailSendInfoBindingModel { MailAddress = clientModel.Email, - Subject = $"Order №{orderModel.Id}", - Text = $"Order №{orderModel.Id} status was changed to {orderModel.Status}" + Subject = $"Заказ №{orderModel.Id}", + Text = $"Заказ №{orderModel.Id} статус изменен в {orderModel.Status}" }; } diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/MessageInfoStorage.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/MessageInfoStorage.cs index c9d813b..83f07f9 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/MessageInfoStorage.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/MessageInfoStorage.cs @@ -20,32 +20,34 @@ namespace PlumbingRepairDatabaseImplement.Implements { using var context = new PlumbingRepairDatabase(); return context.Messages - .Where(x => x.ClientId == model.ClientId) + .Where(x => x.ClientId.HasValue && x.ClientId == model.ClientId) .Select(x => x.GetViewModel) .ToList(); } public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) { - using var context = new PlumbingRepairDatabase(); - 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; - } - return null; } public MessageInfoViewModel? Insert(MessageInfoBindingModel model) { using var context = new PlumbingRepairDatabase(); + model.ClientId = context.Clients.FirstOrDefault(x => x.Email.Equals(model.SenderName))?.Id; var newMessageInfo = MessageInfo.Create(model); - if (newMessageInfo == null || context.Messages.Any(x => x.MessageId.Equals(model.MessageId))) - { - return null; - } - context.Messages.Add(newMessageInfo); + if (newMessageInfo == null || context.Messages.Any(x => x.MessageId.Equals(model.MessageId))) + { + return null; + } + + + context.Messages.Add(newMessageInfo); context.SaveChanges(); return newMessageInfo.GetViewModel; } diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/OrderStorage.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/OrderStorage.cs index 8f90b98..4b46d5a 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/OrderStorage.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/OrderStorage.cs @@ -24,26 +24,75 @@ namespace PlumbingRepairDatabaseImplement.Implements public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue && !model.ImplementerId.HasValue && !model.Status.HasValue) + if (!model.Id.HasValue) + { return null; - + } using var context = new PlumbingRepairDatabase(); - - return context.Orders - .Include(x => x.Work) - .Include(x => x.Client) - .Include(x => x.Implementer) - .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) - || (model.ImplementerId.HasValue && model.Status.HasValue && x.ImplementerId == model.ImplementerId && x.Status == model.Status))? - .GetViewModel; - + if (model.Id.HasValue) + return AttachNames(context.Orders + .Include(x => x.Work) + .Include(x => x.Implementer) + .Include(x => x.Client) + .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) + ?.GetViewModel); + else if (model.ImplementerId.HasValue && model.Status.HasValue) + return AttachNames(context.Orders + .Include(x => x.Implementer) + .Include(x => x.Work) + .Include(x => x.Client) + .FirstOrDefault(x => model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId) + ?.GetViewModel); + return null; } public List GetFilteredList(OrderSearchModel model) { using var context = new PlumbingRepairDatabase(); - if (model.DateFrom.HasValue) + if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.ClientId.HasValue && !model.Status.HasValue) + { + return new(); + } + + + if (model.Id.HasValue) + { + return context.Orders + .Include(x => x.Work) + .Include(x => x.Implementer) + .Include(x => x.Client) + .Where(x => x.Id == model.Id) + .Select(x => AttachNames(x.GetViewModel)).ToList(); + } + if (model.Status.HasValue) + { + return context.Orders + .Include(x => x.Work) + .Include(x => x.Implementer) + .Include(x => x.Client) + .Where(x => x.ImplementerId == model.ImplementerId && x.Status == model.Status) + .Select(x => AttachNames(x.GetViewModel)).ToList(); + } + if (model.ClientId.HasValue) + { + return context.Orders + .Include(x => x.Client) + .Include(x => x.Work) + .Include(x => x.Implementer) + .Where(x => x.ClientId == model.ClientId) + .Select(x => AttachNames(x.GetViewModel)).ToList(); + } + if (model.ImplementerId.HasValue) + { + return context.Orders + .Include(x => x.Work) + .Include(x => x.Implementer) + .Include(x => x.Client) + .Where(x => x.ImplementerId == model.ImplementerId) + .Select(x => AttachNames(x.GetViewModel)).ToList(); + } + if (model.DateFrom != null && model.DateTo != null) { return context.Orders .Include(x => x.Work) @@ -53,19 +102,10 @@ namespace PlumbingRepairDatabaseImplement.Implements && (!model.ClientId.HasValue || x.ClientId == model.ClientId)) .Select(x => x.GetViewModel) .ToList(); - } - return context.Orders - .Include(x => x.Work) - .Include(x => x.Client) - .Include(x => x.Implementer) - .Where(x => (model.Id.HasValue && x.Id == model.Id) - || (model.ClientId.HasValue && x.ClientId == model.ClientId) - || (model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId) - || (model.Status.HasValue && x.Status == model.Status)) - .Select(x => x.GetViewModel) - .ToList(); - } + } + return new(); + } public List GetFullList() { @@ -89,7 +129,7 @@ namespace PlumbingRepairDatabaseImplement.Implements context.Orders.Add(newOrder); context.SaveChanges(); - return AttachNames(newOrder.GetViewModel); + return AttachNames(context.Orders.Include(x => x.Work).Include(x => x.Implementer).Include(x => x.Client).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel); } public OrderViewModel? Update(OrderBindingModel model) diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240503080749_InitCreate.Designer.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240503110424_InitCreate.Designer.cs similarity index 95% rename from PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240503080749_InitCreate.Designer.cs rename to PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240503110424_InitCreate.Designer.cs index 0442d10..f9ac047 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240503080749_InitCreate.Designer.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240503110424_InitCreate.Designer.cs @@ -12,7 +12,7 @@ using PlumbingRepairDatabaseImplement; namespace PlumbingRepairDatabaseImplement.Migrations { [DbContext(typeof(PlumbingRepairDatabase))] - [Migration("20240503080749_InitCreate")] + [Migration("20240503110424_InitCreate")] partial class InitCreate { protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -121,8 +121,6 @@ namespace PlumbingRepairDatabaseImplement.Migrations b.HasKey("MessageId"); - b.HasIndex("ClientId"); - b.ToTable("Messages"); }); @@ -215,15 +213,6 @@ namespace PlumbingRepairDatabaseImplement.Migrations b.ToTable("WorkComponents"); }); - modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.MessageInfo", b => - { - b.HasOne("PlumbingRepairDatabaseImplement.Models.Client", "Client") - .WithMany("Messages") - .HasForeignKey("ClientId"); - - b.Navigation("Client"); - }); - modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Order", b => { b.HasOne("PlumbingRepairDatabaseImplement.Models.Client", "Client") @@ -270,8 +259,6 @@ namespace PlumbingRepairDatabaseImplement.Migrations modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Client", b => { - b.Navigation("Messages"); - b.Navigation("Orders"); }); diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240503080749_InitCreate.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240503110424_InitCreate.cs similarity index 95% rename from PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240503080749_InitCreate.cs rename to PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240503110424_InitCreate.cs index 237c350..b9b676e 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240503080749_InitCreate.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240503110424_InitCreate.cs @@ -54,20 +54,6 @@ namespace PlumbingRepairDatabaseImplement.Migrations table.PrimaryKey("PK_Implementers", x => x.Id); }); - migrationBuilder.CreateTable( - name: "Works", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - WorkName = table.Column(type: "nvarchar(max)", nullable: false), - Price = table.Column(type: "float", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Works", x => x.Id); - }); - migrationBuilder.CreateTable( name: "Messages", columns: table => new @@ -82,11 +68,20 @@ namespace PlumbingRepairDatabaseImplement.Migrations constraints: table => { table.PrimaryKey("PK_Messages", x => x.MessageId); - table.ForeignKey( - name: "FK_Messages_Clients_ClientId", - column: x => x.ClientId, - principalTable: "Clients", - principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "Works", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + WorkName = table.Column(type: "nvarchar(max)", nullable: false), + Price = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Works", x => x.Id); }); migrationBuilder.CreateTable( @@ -153,11 +148,6 @@ namespace PlumbingRepairDatabaseImplement.Migrations onDelete: ReferentialAction.Cascade); }); - migrationBuilder.CreateIndex( - name: "IX_Messages_ClientId", - table: "Messages", - column: "ClientId"); - migrationBuilder.CreateIndex( name: "IX_Orders_ClientId", table: "Orders", diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/PlumbingRepairDatabaseModelSnapshot.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/PlumbingRepairDatabaseModelSnapshot.cs index 0e10741..45d67ac 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/PlumbingRepairDatabaseModelSnapshot.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/PlumbingRepairDatabaseModelSnapshot.cs @@ -119,8 +119,6 @@ namespace PlumbingRepairDatabaseImplement.Migrations b.HasKey("MessageId"); - b.HasIndex("ClientId"); - b.ToTable("Messages"); }); @@ -213,15 +211,6 @@ namespace PlumbingRepairDatabaseImplement.Migrations b.ToTable("WorkComponents"); }); - modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.MessageInfo", b => - { - b.HasOne("PlumbingRepairDatabaseImplement.Models.Client", "Client") - .WithMany("Messages") - .HasForeignKey("ClientId"); - - b.Navigation("Client"); - }); - modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Order", b => { b.HasOne("PlumbingRepairDatabaseImplement.Models.Client", "Client") @@ -268,8 +257,6 @@ namespace PlumbingRepairDatabaseImplement.Migrations modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Client", b => { - b.Navigation("Messages"); - b.Navigation("Orders"); }); diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Client.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Client.cs index 78942fc..74b6e79 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Client.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Client.cs @@ -20,8 +20,6 @@ namespace PlumbingRepairDatabaseImplement.Models [ForeignKey("ClientId")] public virtual List Orders{ get; set; } = new(); - [ForeignKey("ClientId")] - public virtual List Messages { get; set; } = new(); public static Client? Create(ClientBindingModel model) { diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/MessageInfo.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/MessageInfo.cs index 5e41e33..b4d86cd 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/MessageInfo.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/MessageInfo.cs @@ -19,7 +19,6 @@ namespace PlumbingRepairDatabaseImplement.Models public string Subject { get; set; } = string.Empty; [Required] public string Body { get; set; } = string.Empty; - public virtual Client? Client { get; set; } public static MessageInfo? Create(MessageInfoBindingModel model) {