правки :)

This commit is contained in:
Табеев Александр 2024-05-30 06:35:15 +04:00
parent 295e3ee360
commit 128580bce8
5 changed files with 48 additions and 28 deletions

View File

@ -8,6 +8,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ServiceStationBusinessLogic.BusinessLogics namespace ServiceStationBusinessLogic.BusinessLogics
@ -120,16 +121,21 @@ namespace ServiceStationBusinessLogic.BusinessLogics
throw new ArgumentNullException("Нет ФИО поручителя", nameof(model.GuarantorFIO)); 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)); 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); _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 var element = _guarantorStorage.GetElement(new GuarantorSearchModel
@ -137,10 +143,14 @@ namespace ServiceStationBusinessLogic.BusinessLogics
GuarantorNumber = model.GuarantorNumber GuarantorNumber = model.GuarantorNumber
}); });
if (element != null && element.Id != model.Id) if (element != null)
{ {
throw new InvalidOperationException("Поручитель с таким номером уже есть"); throw new InvalidOperationException("Поручитель с таким номером уже есть");
} }
if (model.GuarantorNumber[0] == '+')
{
model.GuarantorNumber.TrimStart('+');
}
} }
} }
} }

View File

@ -51,6 +51,15 @@ namespace ServiceStationDatabaseImplement.Implements
.FirstOrDefault(x => x.GuarantorNumber.Contains(model.GuarantorNumber) && x.GuarantorPassword.Contains(model.GuarantorPassword))? .FirstOrDefault(x => x.GuarantorNumber.Contains(model.GuarantorNumber) && x.GuarantorPassword.Contains(model.GuarantorPassword))?
.GetViewModel; .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 return context.Guarantors
.Include(x => x.SpareParts) .Include(x => x.SpareParts)
.Include(x => x.Repairs) .Include(x => x.Repairs)

View File

@ -222,17 +222,17 @@ namespace ServiceStationDatabaseImplement.Migrations
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_SparePartRepairs", x => x.Id); 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( table.ForeignKey(
name: "FK_SparePartRepairs_SpareParts_SparePartId", name: "FK_SparePartRepairs_SpareParts_SparePartId",
column: x => x.SparePartId, column: x => x.SparePartId,
principalTable: "SpareParts", principalTable: "SpareParts",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_SparePartRepairs_Repairs_RepairId",
column: x => x.RepairId,
principalTable: "Repairs",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict); onDelete: ReferentialAction.Restrict);
}); });
@ -328,16 +328,16 @@ namespace ServiceStationDatabaseImplement.Migrations
table: "Repairs", table: "Repairs",
column: "GuarantorId"); column: "GuarantorId");
migrationBuilder.CreateIndex(
name: "IX_SparePartRepairs_RepairId",
table: "SparePartRepairs",
column: "RepairId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_SparePartRepairs_SparePartId", name: "IX_SparePartRepairs_SparePartId",
table: "SparePartRepairs", table: "SparePartRepairs",
column: "SparePartId"); column: "SparePartId");
migrationBuilder.CreateIndex(
name: "IX_SparePartRepairs_RepairId",
table: "SparePartRepairs",
column: "RepairId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_SpareParts_GuarantorId", name: "IX_SpareParts_GuarantorId",
table: "SpareParts", table: "SpareParts",

View File

@ -241,18 +241,18 @@ namespace ServiceStationDatabaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("RepairId") b.Property<int>("SparePartId")
.HasColumnType("int"); .HasColumnType("int");
b.Property<int>("SparePartId") b.Property<int>("RepairId")
.HasColumnType("int"); .HasColumnType("int");
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("RepairId");
b.HasIndex("SparePartId"); b.HasIndex("SparePartId");
b.HasIndex("RepairId");
b.ToTable("SparePartRepairs"); b.ToTable("SparePartRepairs");
}); });
@ -430,21 +430,22 @@ namespace ServiceStationDatabaseImplement.Migrations
modelBuilder.Entity("ServiceStationDatabaseImplement.Models.SparePartRepair", b => 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") b.HasOne("ServiceStationDatabaseImplement.Models.SparePart", "SparePart")
.WithMany("SparePartRepairs") .WithMany("SparePartRepairs")
.HasForeignKey("SparePartId") .HasForeignKey("SparePartId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.Navigation("Repair"); b.HasOne("ServiceStationDatabaseImplement.Models.Repair", "Repair")
.WithMany("SpareParts")
.HasForeignKey("RepairId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("SparePart"); b.Navigation("SparePart");
b.Navigation("Repair");
}); });
modelBuilder.Entity("ServiceStationDatabaseImplement.Models.SparePartWork", b => modelBuilder.Entity("ServiceStationDatabaseImplement.Models.SparePartWork", b =>

View File

@ -39,7 +39,7 @@ namespace ServiceStationRestApi.Controllers
{ {
return _glogic.ReadElement(new GuarantorSearchModel return _glogic.ReadElement(new GuarantorSearchModel
{ {
GuarantorNumber = guarantorNumber, GuarantorNumber = guarantorNumber.TrimStart(' '),
GuarantorPassword = password GuarantorPassword = password
}); });
} }