From 128580bce8a0636d1f42991961f1e07921bef975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A2=D0=B0=D0=B1=D0=B5=D0=B5=D0=B2=20=D0=90=D0=BB=D0=B5?= =?UTF-8?q?=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80?= Date: Thu, 30 May 2024 06:35:15 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20:)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/GuarantorLogic.cs | 18 ++++++++++--- .../Implements/GuarantorStorage.cs | 9 +++++++ .../20240428190245_InitMigration.cs | 22 ++++++++-------- .../ServiceStationDatabaseModelSnapshot.cs | 25 ++++++++++--------- .../Controllers/GuarantorController.cs | 2 +- 5 files changed, 48 insertions(+), 28 deletions(-) diff --git a/ServiceStation/ServiceStationBusinessLogic/BusinessLogics/GuarantorLogic.cs b/ServiceStation/ServiceStationBusinessLogic/BusinessLogics/GuarantorLogic.cs index 87c66fd..5f50dbd 100644 --- a/ServiceStation/ServiceStationBusinessLogic/BusinessLogics/GuarantorLogic.cs +++ b/ServiceStation/ServiceStationBusinessLogic/BusinessLogics/GuarantorLogic.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; namespace ServiceStationBusinessLogic.BusinessLogics @@ -120,16 +121,21 @@ namespace ServiceStationBusinessLogic.BusinessLogics throw new ArgumentNullException("Нет ФИО поручителя", nameof(model.GuarantorFIO)); } - if (string.IsNullOrEmpty(model.GuarantorPassword)) + if (string.IsNullOrEmpty(model.GuarantorPassword) || !Regex.IsMatch(model.GuarantorPassword, @"^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$", RegexOptions.IgnoreCase)) { - throw new ArgumentNullException("Нет пароля поручителя", nameof(model.GuarantorPassword)); + throw new ArgumentNullException("Пароль введен некорректно", nameof(model.GuarantorPassword)); } - if (string.IsNullOrEmpty(model.GuarantorNumber)) + if (string.IsNullOrEmpty(model.GuarantorNumber) || !Regex.IsMatch(model.GuarantorNumber, @"^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$", RegexOptions.IgnoreCase)) { throw new ArgumentNullException("Нет номера телефона поручителя", nameof(model.GuarantorNumber)); } + if (string.IsNullOrEmpty(model.GuarantorEmail) || !Regex.IsMatch(model.GuarantorEmail, @"([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)", RegexOptions.IgnoreCase)) + { + throw new ArgumentNullException("Почта введена некорректно", nameof(model.GuarantorEmail)); + } + _logger.LogInformation("Guarantor. GuarantorFIO:{GuarantorFIO}.GuarantorPassword:{GuarantorPassword}.GuarantorNumber:{GuarantorNumber} Id: {Id}", model.GuarantorFIO, model.GuarantorPassword, model.GuarantorNumber, model.Id); var element = _guarantorStorage.GetElement(new GuarantorSearchModel @@ -137,10 +143,14 @@ namespace ServiceStationBusinessLogic.BusinessLogics GuarantorNumber = model.GuarantorNumber }); - if (element != null && element.Id != model.Id) + if (element != null) { throw new InvalidOperationException("Поручитель с таким номером уже есть"); } + if (model.GuarantorNumber[0] == '+') + { + model.GuarantorNumber.TrimStart('+'); + } } } } diff --git a/ServiceStation/ServiceStationDatabaseImplement/Implements/GuarantorStorage.cs b/ServiceStation/ServiceStationDatabaseImplement/Implements/GuarantorStorage.cs index c44074f..4f587bf 100644 --- a/ServiceStation/ServiceStationDatabaseImplement/Implements/GuarantorStorage.cs +++ b/ServiceStation/ServiceStationDatabaseImplement/Implements/GuarantorStorage.cs @@ -51,6 +51,15 @@ namespace ServiceStationDatabaseImplement.Implements .FirstOrDefault(x => x.GuarantorNumber.Contains(model.GuarantorNumber) && x.GuarantorPassword.Contains(model.GuarantorPassword))? .GetViewModel; } + if (!string.IsNullOrEmpty(model.GuarantorNumber)) + { + return context.Guarantors + .Include(x => x.SpareParts) + .Include(x => x.Repairs) + .Include(x => x.Works) + .FirstOrDefault(x => x.GuarantorNumber.Contains(model.GuarantorNumber))? + .GetViewModel; + } return context.Guarantors .Include(x => x.SpareParts) .Include(x => x.Repairs) diff --git a/ServiceStation/ServiceStationDatabaseImplement/Migrations/20240428190245_InitMigration.cs b/ServiceStation/ServiceStationDatabaseImplement/Migrations/20240428190245_InitMigration.cs index 30b713c..6ff2230 100644 --- a/ServiceStation/ServiceStationDatabaseImplement/Migrations/20240428190245_InitMigration.cs +++ b/ServiceStation/ServiceStationDatabaseImplement/Migrations/20240428190245_InitMigration.cs @@ -222,17 +222,17 @@ namespace ServiceStationDatabaseImplement.Migrations constraints: table => { table.PrimaryKey("PK_SparePartRepairs", x => x.Id); - table.ForeignKey( - name: "FK_SparePartRepairs_Repairs_RepairId", - column: x => x.RepairId, - principalTable: "Repairs", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_SparePartRepairs_SpareParts_SparePartId", column: x => x.SparePartId, principalTable: "SpareParts", principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_SparePartRepairs_Repairs_RepairId", + column: x => x.RepairId, + principalTable: "Repairs", + principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); @@ -328,16 +328,16 @@ namespace ServiceStationDatabaseImplement.Migrations table: "Repairs", column: "GuarantorId"); - migrationBuilder.CreateIndex( - name: "IX_SparePartRepairs_RepairId", - table: "SparePartRepairs", - column: "RepairId"); - migrationBuilder.CreateIndex( name: "IX_SparePartRepairs_SparePartId", table: "SparePartRepairs", column: "SparePartId"); + migrationBuilder.CreateIndex( + name: "IX_SparePartRepairs_RepairId", + table: "SparePartRepairs", + column: "RepairId"); + migrationBuilder.CreateIndex( name: "IX_SpareParts_GuarantorId", table: "SpareParts", diff --git a/ServiceStation/ServiceStationDatabaseImplement/Migrations/ServiceStationDatabaseModelSnapshot.cs b/ServiceStation/ServiceStationDatabaseImplement/Migrations/ServiceStationDatabaseModelSnapshot.cs index 6191025..917a8d2 100644 --- a/ServiceStation/ServiceStationDatabaseImplement/Migrations/ServiceStationDatabaseModelSnapshot.cs +++ b/ServiceStation/ServiceStationDatabaseImplement/Migrations/ServiceStationDatabaseModelSnapshot.cs @@ -241,18 +241,18 @@ namespace ServiceStationDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("RepairId") - .HasColumnType("int"); - b.Property("SparePartId") + .HasColumnType("int"); + + b.Property("RepairId") .HasColumnType("int"); b.HasKey("Id"); - b.HasIndex("RepairId"); - b.HasIndex("SparePartId"); + b.HasIndex("RepairId"); + b.ToTable("SparePartRepairs"); }); @@ -430,21 +430,22 @@ namespace ServiceStationDatabaseImplement.Migrations modelBuilder.Entity("ServiceStationDatabaseImplement.Models.SparePartRepair", b => { - b.HasOne("ServiceStationDatabaseImplement.Models.Repair", "Repair") - .WithMany("SpareParts") - .HasForeignKey("RepairId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - b.HasOne("ServiceStationDatabaseImplement.Models.SparePart", "SparePart") .WithMany("SparePartRepairs") .HasForeignKey("SparePartId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.Navigation("Repair"); + b.HasOne("ServiceStationDatabaseImplement.Models.Repair", "Repair") + .WithMany("SpareParts") + .HasForeignKey("RepairId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); b.Navigation("SparePart"); + + b.Navigation("Repair"); + }); modelBuilder.Entity("ServiceStationDatabaseImplement.Models.SparePartWork", b => diff --git a/ServiceStation/ServiceStationRestApi/Controllers/GuarantorController.cs b/ServiceStation/ServiceStationRestApi/Controllers/GuarantorController.cs index e35ee18..cb36c96 100644 --- a/ServiceStation/ServiceStationRestApi/Controllers/GuarantorController.cs +++ b/ServiceStation/ServiceStationRestApi/Controllers/GuarantorController.cs @@ -39,7 +39,7 @@ namespace ServiceStationRestApi.Controllers { return _glogic.ReadElement(new GuarantorSearchModel { - GuarantorNumber = guarantorNumber, + GuarantorNumber = guarantorNumber.TrimStart(' '), GuarantorPassword = password }); }