База данных для Исполнителя

This commit is contained in:
Софья Якобчук 2024-05-27 02:43:57 +04:00
parent de7b62944f
commit 67f4dc1593
15 changed files with 2324 additions and 202 deletions

View File

@ -93,8 +93,7 @@ namespace LawCompanyDatabaseImplement.Implements
using var transaction = context.Database.BeginTransaction();
try
{
var _case = context.Cases.FirstOrDefault(rec =>
rec.Id == model.Id);
var _case = context.Cases.FirstOrDefault(rec => rec.Id == model.Id);
if (_case == null)
{
return null;
@ -102,21 +101,19 @@ namespace LawCompanyDatabaseImplement.Implements
_case.Update(model);
context.SaveChanges();
_case.UpdateClients(context, model);
transaction.Commit();
return _case.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
public CaseViewModel? Delete(CaseBindingModel model)
{
using var context = new LawCompanyDatabase();
var element = context.Cases
.Include(x => x.Clients)
.FirstOrDefault(rec => rec.Id == model.Id);
var element = context.Cases.Include(x => x.Clients).FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Cases.Remove(element);

View File

@ -3,6 +3,7 @@ using LawCompanyContracts.SearchModels;
using LawCompanyContracts.StoragesContracts;
using LawCompanyContracts.ViewModels;
using LawCompanyDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace LawCompanyDatabaseImplement.Implements
{
@ -11,9 +12,7 @@ namespace LawCompanyDatabaseImplement.Implements
public List<ExecutorViewModel> GetFullList()
{
using var context = new LawCompanyDatabase();
return context.Executors
.Select(x => x.GetViewModel)
.ToList();
return context.Executors.Select(x => x.GetViewModel).ToList();
}
public List<ExecutorViewModel> GetFilteredList(ExecutorSearchModel model)
@ -23,38 +22,53 @@ namespace LawCompanyDatabaseImplement.Implements
{
return new();
}
if (!string.IsNullOrEmpty(model.Email))
{
using var context = new LawCompanyDatabase();
return context.Executors
.Where(x => x.Email.Equals(model.Email))
.Select(x => x.GetViewModel)
.ToList();
}
else
{
using var context = new LawCompanyDatabase();
return context.Executors
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
}
using var context = new LawCompanyDatabase();
return context.Executors
.Include(x => x.Cases)
.Include(x => x.Clients)
.Include(x => x.Visits)
.Where(x => x.Email.Contains(model.Email) && x.Password == model.Password)
.Select(x => x.GetViewModel)
.ToList();
}
public ExecutorViewModel? GetElement(ExecutorSearchModel model)
{
if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue && string.IsNullOrEmpty(model.FIO)
&& string.IsNullOrEmpty(model.Password))
{
return null;
}
using var context = new LawCompanyDatabase();
using var context = new LawCompanyDatabase();
return context.Executors
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Email)
&& x.Email == model.Email) || (model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
if (model.Id.HasValue)
{
return context.Executors
.Include(x => x.Cases)
.Include(x => x.Clients)
.Include(x => x.Visits)
.FirstOrDefault(x => x.Id == model.Id)?
.GetViewModel;
}
if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password))
{
return context.Executors
.Include(x => x.Cases)
.Include(x => x.Clients)
.Include(x => x.Visits)
.FirstOrDefault(x => x.Email.Equals(model.Email) && x.Password.Equals(model.Password))?
.GetViewModel;
}
if (!string.IsNullOrEmpty(model.Email))
{
return context.Executors
.Include(x => x.Cases)
.Include(x => x.Clients)
.Include(x => x.Visits)
.FirstOrDefault(x => x.Email.Equals(model.Email))?
.GetViewModel;
}
return null;
}
public ExecutorViewModel? Insert(ExecutorBindingModel model)
{

View File

@ -3,96 +3,111 @@ using LawCompanyContracts.SearchModels;
using LawCompanyContracts.StoragesContracts;
using LawCompanyContracts.ViewModels;
using LawCompanyDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace LawCompanyDatabaseImplement.Implements
{
public class GuarantorStorage : IGuarantorStorage
{
public List<GuarantorViewModel> GetFullList()
{
using var context = new LawCompanyDatabase();
return context.Guarantors
.Select(x => x.GetViewModel)
.ToList();
}
public class GuarantorStorage : IGuarantorStorage
{
public List<GuarantorViewModel> GetFullList()
{
using var context = new LawCompanyDatabase();
return context.Guarantors.Select(x => x.GetViewModel).ToList();
}
public List<GuarantorViewModel> GetFilteredList(GuarantorSearchModel model)
{
if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue && string.IsNullOrEmpty(model.FIO)
&& string.IsNullOrEmpty(model.Password))
{
return new();
}
if (!string.IsNullOrEmpty(model.Email))
{
using var context = new LawCompanyDatabase();
return context.Guarantors
.Where(x => x.Email.Equals(model.Email))
.Select(x => x.GetViewModel)
.ToList();
}
else
{
using var context = new LawCompanyDatabase();
return context.Guarantors
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
}
public List<GuarantorViewModel> GetFilteredList(GuarantorSearchModel model)
{
if (string.IsNullOrEmpty(model.Email) && string.IsNullOrEmpty(model.FIO)
&& string.IsNullOrEmpty(model.Password))
{
return new();
}
public GuarantorViewModel? GetElement(GuarantorSearchModel model)
{
if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue && string.IsNullOrEmpty(model.FIO)
&& string.IsNullOrEmpty(model.Password))
{
return null;
}
using var context = new LawCompanyDatabase();
using var context = new LawCompanyDatabase();
return context.Guarantors
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Email)
&& x.Email == model.Email) || (model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
return context.Guarantors
.Include(x => x.Consultations)
.Include(x => x.Lawyers)
.Include(x => x.Hearings)
.Where(x => x.Email.Contains(model.Email) && x.Password == model.Password)
.Select(x => x.GetViewModel)
.ToList();
}
public GuarantorViewModel? Insert(GuarantorBindingModel model)
{
using var context = new LawCompanyDatabase();
var newGuarantor = Guarantor.Create(context, model);
if (newGuarantor == null)
{
return null;
}
context.Guarantors.Add(newGuarantor);
context.SaveChanges();
return newGuarantor.GetViewModel;
}
public GuarantorViewModel? GetElement(GuarantorSearchModel model)
{
using var context = new LawCompanyDatabase();
public GuarantorViewModel? Update(GuarantorBindingModel model)
{
using var context = new LawCompanyDatabase();
var executor = context.Guarantors.FirstOrDefault(x => x.Id == model.Id);
if (executor == null)
{
return null;
}
executor.Update(model);
context.SaveChanges();
return executor.GetViewModel;
}
if (model.Id.HasValue)
{
return context.Guarantors
.Include(x => x.Consultations)
.Include(x => x.Lawyers)
.Include(x => x.Hearings)
.FirstOrDefault(x => x.Id == model.Id)?
.GetViewModel;
}
public GuarantorViewModel? Delete(GuarantorBindingModel model)
{
using var context = new LawCompanyDatabase();
var element = context.Guarantors.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Guarantors.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password))
{
return context.Guarantors
.Include(x => x.Consultations)
.Include(x => x.Lawyers)
.Include(x => x.Hearings)
.FirstOrDefault(x => x.Email.Equals(model.Email) && x.Password.Equals(model.Password))?
.GetViewModel;
}
if (!string.IsNullOrEmpty(model.Email))
{
return context.Guarantors
.Include(x => x.Consultations)
.Include(x => x.Lawyers)
.Include(x => x.Hearings)
.FirstOrDefault(x => x.Email.Equals(model.Email))?
.GetViewModel;
}
return null;
}
public GuarantorViewModel? Insert(GuarantorBindingModel model)
{
using var context = new LawCompanyDatabase();
var newGuarantor = Guarantor.Create(context, model);
if (newGuarantor == null)
{
return null;
}
context.Guarantors.Add(newGuarantor);
context.SaveChanges();
return newGuarantor.GetViewModel;
}
public GuarantorViewModel? Update(GuarantorBindingModel model)
{
using var context = new LawCompanyDatabase();
var executor = context.Guarantors.FirstOrDefault(x => x.Id == model.Id);
if (executor == null)
{
return null;
}
executor.Update(model);
context.SaveChanges();
return executor.GetViewModel;
}
public GuarantorViewModel? Delete(GuarantorBindingModel model)
{
using var context = new LawCompanyDatabase();
var element = context.Guarantors.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Guarantors.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -30,7 +30,7 @@ namespace LawCompanyDatabaseImplement.Implements
{
using var context = new LawCompanyDatabase();
return context.Visits
.Include(x => x.Clients).ThenInclude(x => x.Client)
.Include(x => x.Clients).ThenInclude(x => x.Client)
.Where(x => x.ExecutorId == model.ExecutorId && x.VisitDate >= model.DateFrom && x.VisitDate <= model.DateTo)
.Select(x => x.GetViewModel)
.ToList();
@ -121,8 +121,7 @@ namespace LawCompanyDatabaseImplement.Implements
using var transaction = context.Database.BeginTransaction();
try
{
var visit = context.Visits.FirstOrDefault(rec =>
rec.Id == model.Id);
var visit = context.Visits.FirstOrDefault(rec => rec.Id == model.Id);
if (visit == null)
{
return null;
@ -142,9 +141,7 @@ namespace LawCompanyDatabaseImplement.Implements
public VisitViewModel? Delete(VisitBindingModel model)
{
using var context = new LawCompanyDatabase();
var element = context.Visits
.Include(x => x.Clients)
.FirstOrDefault(rec => rec.Id == model.Id);
var element = context.Visits.Include(x => x.Clients).FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Visits.Remove(element);

View File

@ -16,7 +16,7 @@ namespace LawCompanyDatabaseImplement
if (optionsBuilder.IsConfigured == false)
{
//optionsBuilder.UseSqlServer(@"Data Source=LAPTOP-6GNIALH9\SQLEXPRESS;Initial Catalog=LawCompanyDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-H8060U3\SQLEXPRESS;Initial Catalog=LawCompanyDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-7DB3VEN\SQLEXPRESS;Initial Catalog=Test;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}

View File

@ -0,0 +1,543 @@
// <auto-generated />
using System;
using LawCompanyDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace LawCompanyDatabaseImplement.Migrations
{
[DbContext(typeof(LawCompanyDatabase))]
[Migration("20240526073959_test")]
partial class test
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.17")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Case", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("CaseType")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int>("ExecutorId")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("Status")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ExecutorId");
b.ToTable("Cases");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.CaseClient", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("CaseId")
.HasColumnType("int");
b.Property<int>("ClientId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CaseId");
b.HasIndex("ClientId");
b.ToTable("CaseClients");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("ExecutorId")
.HasColumnType("int");
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Phone")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("ExecutorId");
b.ToTable("Clients");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Consultation", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("CaseId")
.HasColumnType("int");
b.Property<DateTime>("ConsultationDate")
.HasColumnType("datetime2");
b.Property<double>("Cost")
.HasColumnType("float");
b.Property<int>("GuarantorId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CaseId");
b.HasIndex("GuarantorId");
b.ToTable("Consultations");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.ConsultationLawyer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ConsultationId")
.HasColumnType("int");
b.Property<int>("LawyerId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ConsultationId");
b.HasIndex("LawyerId");
b.ToTable("ConsultationLawyers");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Executor", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Executors");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Guarantor", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Guarantors");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Hearing", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("GuarantorId")
.HasColumnType("int");
b.Property<DateTime>("HearingDate")
.HasColumnType("datetime2");
b.Property<string>("Judge")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("GuarantorId");
b.ToTable("Hearings");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.HearingLawyer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("HearingId")
.HasColumnType("int");
b.Property<int>("LawyerId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("HearingId");
b.HasIndex("LawyerId");
b.ToTable("HearingLawyers");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Lawyer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int?>("GuarantorId")
.HasColumnType("int");
b.Property<string>("Phone")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("GuarantorId");
b.ToTable("Lawyers");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Visit", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ExecutorId")
.HasColumnType("int");
b.Property<int>("HearingId")
.HasColumnType("int");
b.Property<DateTime>("VisitDate")
.HasColumnType("datetime2");
b.HasKey("Id");
b.HasIndex("ExecutorId");
b.HasIndex("HearingId");
b.ToTable("Visits");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.VisitClient", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<int>("VisitId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("VisitId");
b.ToTable("VisitClients");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Case", b =>
{
b.HasOne("LawCompanyDatabaseImplement.Models.Executor", null)
.WithMany("Cases")
.HasForeignKey("ExecutorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.CaseClient", b =>
{
b.HasOne("LawCompanyDatabaseImplement.Models.Case", "Case")
.WithMany("Clients")
.HasForeignKey("CaseId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LawCompanyDatabaseImplement.Models.Client", "Client")
.WithMany("CaseClients")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Case");
b.Navigation("Client");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Client", b =>
{
b.HasOne("LawCompanyDatabaseImplement.Models.Executor", null)
.WithMany("Clients")
.HasForeignKey("ExecutorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Consultation", b =>
{
b.HasOne("LawCompanyDatabaseImplement.Models.Case", "Case")
.WithMany()
.HasForeignKey("CaseId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LawCompanyDatabaseImplement.Models.Guarantor", null)
.WithMany("Consultations")
.HasForeignKey("GuarantorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Case");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.ConsultationLawyer", b =>
{
b.HasOne("LawCompanyDatabaseImplement.Models.Consultation", "Consultation")
.WithMany("Lawyers")
.HasForeignKey("ConsultationId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LawCompanyDatabaseImplement.Models.Lawyer", "Lawyer")
.WithMany("ConsultationLawyers")
.HasForeignKey("LawyerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Consultation");
b.Navigation("Lawyer");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Hearing", b =>
{
b.HasOne("LawCompanyDatabaseImplement.Models.Guarantor", null)
.WithMany("Hearings")
.HasForeignKey("GuarantorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.HearingLawyer", b =>
{
b.HasOne("LawCompanyDatabaseImplement.Models.Hearing", "Hearing")
.WithMany("Lawyers")
.HasForeignKey("HearingId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LawCompanyDatabaseImplement.Models.Lawyer", "Lawyer")
.WithMany("HearingLawyers")
.HasForeignKey("LawyerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Hearing");
b.Navigation("Lawyer");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Lawyer", b =>
{
b.HasOne("LawCompanyDatabaseImplement.Models.Guarantor", null)
.WithMany("Lawyers")
.HasForeignKey("GuarantorId");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Visit", b =>
{
b.HasOne("LawCompanyDatabaseImplement.Models.Executor", null)
.WithMany("Visits")
.HasForeignKey("ExecutorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LawCompanyDatabaseImplement.Models.Hearing", "Hearing")
.WithMany()
.HasForeignKey("HearingId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Hearing");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.VisitClient", b =>
{
b.HasOne("LawCompanyDatabaseImplement.Models.Client", "Client")
.WithMany("ClientVisits")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LawCompanyDatabaseImplement.Models.Visit", "Visit")
.WithMany("Clients")
.HasForeignKey("VisitId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
b.Navigation("Visit");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Case", b =>
{
b.Navigation("Clients");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Client", b =>
{
b.Navigation("CaseClients");
b.Navigation("ClientVisits");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Consultation", b =>
{
b.Navigation("Lawyers");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Executor", b =>
{
b.Navigation("Cases");
b.Navigation("Clients");
b.Navigation("Visits");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Guarantor", b =>
{
b.Navigation("Consultations");
b.Navigation("Hearings");
b.Navigation("Lawyers");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Hearing", b =>
{
b.Navigation("Lawyers");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Lawyer", b =>
{
b.Navigation("ConsultationLawyers");
b.Navigation("HearingLawyers");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Visit", b =>
{
b.Navigation("Clients");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,412 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace LawCompanyDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class test : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Executors",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
FIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
Email = table.Column<string>(type: "nvarchar(max)", nullable: false),
Password = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Executors", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Guarantors",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
FIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
Email = table.Column<string>(type: "nvarchar(max)", nullable: false),
Password = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Guarantors", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Cases",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
CaseType = table.Column<string>(type: "nvarchar(max)", nullable: false),
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true),
Status = table.Column<int>(type: "int", nullable: false),
ExecutorId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Cases", x => x.Id);
table.ForeignKey(
name: "FK_Cases_Executors_ExecutorId",
column: x => x.ExecutorId,
principalTable: "Executors",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Clients",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
FIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
Email = table.Column<string>(type: "nvarchar(max)", nullable: false),
Phone = table.Column<string>(type: "nvarchar(max)", nullable: false),
ExecutorId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Clients", x => x.Id);
table.ForeignKey(
name: "FK_Clients_Executors_ExecutorId",
column: x => x.ExecutorId,
principalTable: "Executors",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Hearings",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
HearingDate = table.Column<DateTime>(type: "datetime2", nullable: false),
Judge = table.Column<string>(type: "nvarchar(max)", nullable: false),
GuarantorId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Hearings", x => x.Id);
table.ForeignKey(
name: "FK_Hearings_Guarantors_GuarantorId",
column: x => x.GuarantorId,
principalTable: "Guarantors",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Lawyers",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
FIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
Email = table.Column<string>(type: "nvarchar(max)", nullable: false),
Phone = table.Column<string>(type: "nvarchar(max)", nullable: false),
GuarantorId = table.Column<int>(type: "int", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Lawyers", x => x.Id);
table.ForeignKey(
name: "FK_Lawyers_Guarantors_GuarantorId",
column: x => x.GuarantorId,
principalTable: "Guarantors",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "Consultations",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Cost = table.Column<double>(type: "float", nullable: false),
ConsultationDate = table.Column<DateTime>(type: "datetime2", nullable: false),
CaseId = table.Column<int>(type: "int", nullable: false),
GuarantorId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Consultations", x => x.Id);
table.ForeignKey(
name: "FK_Consultations_Cases_CaseId",
column: x => x.CaseId,
principalTable: "Cases",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Consultations_Guarantors_GuarantorId",
column: x => x.GuarantorId,
principalTable: "Guarantors",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "CaseClients",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
CaseId = table.Column<int>(type: "int", nullable: false),
ClientId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_CaseClients", x => x.Id);
table.ForeignKey(
name: "FK_CaseClients_Cases_CaseId",
column: x => x.CaseId,
principalTable: "Cases",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_CaseClients_Clients_ClientId",
column: x => x.ClientId,
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "Visits",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
VisitDate = table.Column<DateTime>(type: "datetime2", nullable: false),
HearingId = table.Column<int>(type: "int", nullable: false),
ExecutorId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Visits", x => x.Id);
table.ForeignKey(
name: "FK_Visits_Executors_ExecutorId",
column: x => x.ExecutorId,
principalTable: "Executors",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Visits_Hearings_HearingId",
column: x => x.HearingId,
principalTable: "Hearings",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "HearingLawyers",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
HearingId = table.Column<int>(type: "int", nullable: false),
LawyerId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_HearingLawyers", x => x.Id);
table.ForeignKey(
name: "FK_HearingLawyers_Hearings_HearingId",
column: x => x.HearingId,
principalTable: "Hearings",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_HearingLawyers_Lawyers_LawyerId",
column: x => x.LawyerId,
principalTable: "Lawyers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "ConsultationLawyers",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ConsultationId = table.Column<int>(type: "int", nullable: false),
LawyerId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ConsultationLawyers", x => x.Id);
table.ForeignKey(
name: "FK_ConsultationLawyers_Consultations_ConsultationId",
column: x => x.ConsultationId,
principalTable: "Consultations",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ConsultationLawyers_Lawyers_LawyerId",
column: x => x.LawyerId,
principalTable: "Lawyers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "VisitClients",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ClientId = table.Column<int>(type: "int", nullable: false),
VisitId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_VisitClients", x => x.Id);
table.ForeignKey(
name: "FK_VisitClients_Clients_ClientId",
column: x => x.ClientId,
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_VisitClients_Visits_VisitId",
column: x => x.VisitId,
principalTable: "Visits",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
name: "IX_CaseClients_CaseId",
table: "CaseClients",
column: "CaseId");
migrationBuilder.CreateIndex(
name: "IX_CaseClients_ClientId",
table: "CaseClients",
column: "ClientId");
migrationBuilder.CreateIndex(
name: "IX_Cases_ExecutorId",
table: "Cases",
column: "ExecutorId");
migrationBuilder.CreateIndex(
name: "IX_Clients_ExecutorId",
table: "Clients",
column: "ExecutorId");
migrationBuilder.CreateIndex(
name: "IX_ConsultationLawyers_ConsultationId",
table: "ConsultationLawyers",
column: "ConsultationId");
migrationBuilder.CreateIndex(
name: "IX_ConsultationLawyers_LawyerId",
table: "ConsultationLawyers",
column: "LawyerId");
migrationBuilder.CreateIndex(
name: "IX_Consultations_CaseId",
table: "Consultations",
column: "CaseId");
migrationBuilder.CreateIndex(
name: "IX_Consultations_GuarantorId",
table: "Consultations",
column: "GuarantorId");
migrationBuilder.CreateIndex(
name: "IX_HearingLawyers_HearingId",
table: "HearingLawyers",
column: "HearingId");
migrationBuilder.CreateIndex(
name: "IX_HearingLawyers_LawyerId",
table: "HearingLawyers",
column: "LawyerId");
migrationBuilder.CreateIndex(
name: "IX_Hearings_GuarantorId",
table: "Hearings",
column: "GuarantorId");
migrationBuilder.CreateIndex(
name: "IX_Lawyers_GuarantorId",
table: "Lawyers",
column: "GuarantorId");
migrationBuilder.CreateIndex(
name: "IX_VisitClients_ClientId",
table: "VisitClients",
column: "ClientId");
migrationBuilder.CreateIndex(
name: "IX_VisitClients_VisitId",
table: "VisitClients",
column: "VisitId");
migrationBuilder.CreateIndex(
name: "IX_Visits_ExecutorId",
table: "Visits",
column: "ExecutorId");
migrationBuilder.CreateIndex(
name: "IX_Visits_HearingId",
table: "Visits",
column: "HearingId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "CaseClients");
migrationBuilder.DropTable(
name: "ConsultationLawyers");
migrationBuilder.DropTable(
name: "HearingLawyers");
migrationBuilder.DropTable(
name: "VisitClients");
migrationBuilder.DropTable(
name: "Consultations");
migrationBuilder.DropTable(
name: "Lawyers");
migrationBuilder.DropTable(
name: "Clients");
migrationBuilder.DropTable(
name: "Visits");
migrationBuilder.DropTable(
name: "Cases");
migrationBuilder.DropTable(
name: "Hearings");
migrationBuilder.DropTable(
name: "Executors");
migrationBuilder.DropTable(
name: "Guarantors");
}
}
}

View File

@ -0,0 +1,541 @@
// <auto-generated />
using System;
using LawCompanyDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace LawCompanyDatabaseImplement.Migrations
{
[DbContext(typeof(LawCompanyDatabase))]
[Migration("20240526100556_test1")]
partial class test1
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.17")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Case", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("CaseType")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int>("ExecutorId")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("Status")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ExecutorId");
b.ToTable("Cases");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.CaseClient", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("CaseId")
.HasColumnType("int");
b.Property<int>("ClientId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CaseId");
b.HasIndex("ClientId");
b.ToTable("CaseClients");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("ExecutorId")
.HasColumnType("int");
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Phone")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("ExecutorId");
b.ToTable("Clients");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Consultation", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("CaseId")
.HasColumnType("int");
b.Property<DateTime>("ConsultationDate")
.HasColumnType("datetime2");
b.Property<double>("Cost")
.HasColumnType("float");
b.Property<int>("GuarantorId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CaseId");
b.HasIndex("GuarantorId");
b.ToTable("Consultations");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.ConsultationLawyer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ConsultationId")
.HasColumnType("int");
b.Property<int>("LawyerId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ConsultationId");
b.HasIndex("LawyerId");
b.ToTable("ConsultationLawyers");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Executor", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Executors");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Guarantor", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Guarantors");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Hearing", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("GuarantorId")
.HasColumnType("int");
b.Property<DateTime>("HearingDate")
.HasColumnType("datetime2");
b.Property<string>("Judge")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("GuarantorId");
b.ToTable("Hearings");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.HearingLawyer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("HearingId")
.HasColumnType("int");
b.Property<int>("LawyerId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("HearingId");
b.HasIndex("LawyerId");
b.ToTable("HearingLawyers");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Lawyer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int?>("GuarantorId")
.HasColumnType("int");
b.Property<string>("Phone")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("GuarantorId");
b.ToTable("Lawyers");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Visit", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ExecutorId")
.HasColumnType("int");
b.Property<int?>("HearingId")
.HasColumnType("int");
b.Property<DateTime>("VisitDate")
.HasColumnType("datetime2");
b.HasKey("Id");
b.HasIndex("ExecutorId");
b.HasIndex("HearingId");
b.ToTable("Visits");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.VisitClient", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<int>("VisitId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("VisitId");
b.ToTable("VisitClients");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Case", b =>
{
b.HasOne("LawCompanyDatabaseImplement.Models.Executor", null)
.WithMany("Cases")
.HasForeignKey("ExecutorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.CaseClient", b =>
{
b.HasOne("LawCompanyDatabaseImplement.Models.Case", "Case")
.WithMany("Clients")
.HasForeignKey("CaseId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LawCompanyDatabaseImplement.Models.Client", "Client")
.WithMany("CaseClients")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Case");
b.Navigation("Client");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Client", b =>
{
b.HasOne("LawCompanyDatabaseImplement.Models.Executor", null)
.WithMany("Clients")
.HasForeignKey("ExecutorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Consultation", b =>
{
b.HasOne("LawCompanyDatabaseImplement.Models.Case", "Case")
.WithMany()
.HasForeignKey("CaseId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LawCompanyDatabaseImplement.Models.Guarantor", null)
.WithMany("Consultations")
.HasForeignKey("GuarantorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Case");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.ConsultationLawyer", b =>
{
b.HasOne("LawCompanyDatabaseImplement.Models.Consultation", "Consultation")
.WithMany("Lawyers")
.HasForeignKey("ConsultationId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LawCompanyDatabaseImplement.Models.Lawyer", "Lawyer")
.WithMany("ConsultationLawyers")
.HasForeignKey("LawyerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Consultation");
b.Navigation("Lawyer");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Hearing", b =>
{
b.HasOne("LawCompanyDatabaseImplement.Models.Guarantor", null)
.WithMany("Hearings")
.HasForeignKey("GuarantorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.HearingLawyer", b =>
{
b.HasOne("LawCompanyDatabaseImplement.Models.Hearing", "Hearing")
.WithMany("Lawyers")
.HasForeignKey("HearingId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LawCompanyDatabaseImplement.Models.Lawyer", "Lawyer")
.WithMany("HearingLawyers")
.HasForeignKey("LawyerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Hearing");
b.Navigation("Lawyer");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Lawyer", b =>
{
b.HasOne("LawCompanyDatabaseImplement.Models.Guarantor", null)
.WithMany("Lawyers")
.HasForeignKey("GuarantorId");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Visit", b =>
{
b.HasOne("LawCompanyDatabaseImplement.Models.Executor", null)
.WithMany("Visits")
.HasForeignKey("ExecutorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LawCompanyDatabaseImplement.Models.Hearing", "Hearing")
.WithMany()
.HasForeignKey("HearingId");
b.Navigation("Hearing");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.VisitClient", b =>
{
b.HasOne("LawCompanyDatabaseImplement.Models.Client", "Client")
.WithMany("ClientVisits")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LawCompanyDatabaseImplement.Models.Visit", "Visit")
.WithMany("Clients")
.HasForeignKey("VisitId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
b.Navigation("Visit");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Case", b =>
{
b.Navigation("Clients");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Client", b =>
{
b.Navigation("CaseClients");
b.Navigation("ClientVisits");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Consultation", b =>
{
b.Navigation("Lawyers");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Executor", b =>
{
b.Navigation("Cases");
b.Navigation("Clients");
b.Navigation("Visits");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Guarantor", b =>
{
b.Navigation("Consultations");
b.Navigation("Hearings");
b.Navigation("Lawyers");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Hearing", b =>
{
b.Navigation("Lawyers");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Lawyer", b =>
{
b.Navigation("ConsultationLawyers");
b.Navigation("HearingLawyers");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Visit", b =>
{
b.Navigation("Clients");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,59 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace LawCompanyDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class test1 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Visits_Hearings_HearingId",
table: "Visits");
migrationBuilder.AlterColumn<int>(
name: "HearingId",
table: "Visits",
type: "int",
nullable: true,
oldClrType: typeof(int),
oldType: "int");
migrationBuilder.AddForeignKey(
name: "FK_Visits_Hearings_HearingId",
table: "Visits",
column: "HearingId",
principalTable: "Hearings",
principalColumn: "Id");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Visits_Hearings_HearingId",
table: "Visits");
migrationBuilder.AlterColumn<int>(
name: "HearingId",
table: "Visits",
type: "int",
nullable: false,
defaultValue: 0,
oldClrType: typeof(int),
oldType: "int",
oldNullable: true);
migrationBuilder.AddForeignKey(
name: "FK_Visits_Hearings_HearingId",
table: "Visits",
column: "HearingId",
principalTable: "Hearings",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
}
}

View File

@ -0,0 +1,537 @@
// <auto-generated />
using System;
using LawCompanyDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace LawCompanyDatabaseImplement.Migrations
{
[DbContext(typeof(LawCompanyDatabase))]
[Migration("20240526114610_test3")]
partial class test3
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.17")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Case", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int>("ExecutorId")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("Status")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ExecutorId");
b.ToTable("Cases");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.CaseClient", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("CaseId")
.HasColumnType("int");
b.Property<int>("ClientId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CaseId");
b.HasIndex("ClientId");
b.ToTable("CaseClients");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("ExecutorId")
.HasColumnType("int");
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Phone")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("ExecutorId");
b.ToTable("Clients");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Consultation", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("CaseId")
.HasColumnType("int");
b.Property<DateTime>("ConsultationDate")
.HasColumnType("datetime2");
b.Property<double>("Cost")
.HasColumnType("float");
b.Property<int>("GuarantorId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CaseId");
b.HasIndex("GuarantorId");
b.ToTable("Consultations");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.ConsultationLawyer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ConsultationId")
.HasColumnType("int");
b.Property<int>("LawyerId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ConsultationId");
b.HasIndex("LawyerId");
b.ToTable("ConsultationLawyers");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Executor", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Executors");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Guarantor", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Guarantors");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Hearing", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("GuarantorId")
.HasColumnType("int");
b.Property<DateTime>("HearingDate")
.HasColumnType("datetime2");
b.Property<string>("Judge")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("GuarantorId");
b.ToTable("Hearings");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.HearingLawyer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("HearingId")
.HasColumnType("int");
b.Property<int>("LawyerId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("HearingId");
b.HasIndex("LawyerId");
b.ToTable("HearingLawyers");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Lawyer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int?>("GuarantorId")
.HasColumnType("int");
b.Property<string>("Phone")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("GuarantorId");
b.ToTable("Lawyers");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Visit", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ExecutorId")
.HasColumnType("int");
b.Property<int?>("HearingId")
.HasColumnType("int");
b.Property<DateTime>("VisitDate")
.HasColumnType("datetime2");
b.HasKey("Id");
b.HasIndex("ExecutorId");
b.HasIndex("HearingId");
b.ToTable("Visits");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.VisitClient", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<int>("VisitId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("VisitId");
b.ToTable("VisitClients");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Case", b =>
{
b.HasOne("LawCompanyDatabaseImplement.Models.Executor", null)
.WithMany("Cases")
.HasForeignKey("ExecutorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.CaseClient", b =>
{
b.HasOne("LawCompanyDatabaseImplement.Models.Case", "Case")
.WithMany("Clients")
.HasForeignKey("CaseId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LawCompanyDatabaseImplement.Models.Client", "Client")
.WithMany("CaseClients")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Case");
b.Navigation("Client");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Client", b =>
{
b.HasOne("LawCompanyDatabaseImplement.Models.Executor", null)
.WithMany("Clients")
.HasForeignKey("ExecutorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Consultation", b =>
{
b.HasOne("LawCompanyDatabaseImplement.Models.Case", "Case")
.WithMany()
.HasForeignKey("CaseId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LawCompanyDatabaseImplement.Models.Guarantor", null)
.WithMany("Consultations")
.HasForeignKey("GuarantorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Case");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.ConsultationLawyer", b =>
{
b.HasOne("LawCompanyDatabaseImplement.Models.Consultation", "Consultation")
.WithMany("Lawyers")
.HasForeignKey("ConsultationId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LawCompanyDatabaseImplement.Models.Lawyer", "Lawyer")
.WithMany("ConsultationLawyers")
.HasForeignKey("LawyerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Consultation");
b.Navigation("Lawyer");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Hearing", b =>
{
b.HasOne("LawCompanyDatabaseImplement.Models.Guarantor", null)
.WithMany("Hearings")
.HasForeignKey("GuarantorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.HearingLawyer", b =>
{
b.HasOne("LawCompanyDatabaseImplement.Models.Hearing", "Hearing")
.WithMany("Lawyers")
.HasForeignKey("HearingId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LawCompanyDatabaseImplement.Models.Lawyer", "Lawyer")
.WithMany("HearingLawyers")
.HasForeignKey("LawyerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Hearing");
b.Navigation("Lawyer");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Lawyer", b =>
{
b.HasOne("LawCompanyDatabaseImplement.Models.Guarantor", null)
.WithMany("Lawyers")
.HasForeignKey("GuarantorId");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Visit", b =>
{
b.HasOne("LawCompanyDatabaseImplement.Models.Executor", null)
.WithMany("Visits")
.HasForeignKey("ExecutorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LawCompanyDatabaseImplement.Models.Hearing", "Hearing")
.WithMany()
.HasForeignKey("HearingId");
b.Navigation("Hearing");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.VisitClient", b =>
{
b.HasOne("LawCompanyDatabaseImplement.Models.Client", "Client")
.WithMany("ClientVisits")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LawCompanyDatabaseImplement.Models.Visit", "Visit")
.WithMany("Clients")
.HasForeignKey("VisitId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
b.Navigation("Visit");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Case", b =>
{
b.Navigation("Clients");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Client", b =>
{
b.Navigation("CaseClients");
b.Navigation("ClientVisits");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Consultation", b =>
{
b.Navigation("Lawyers");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Executor", b =>
{
b.Navigation("Cases");
b.Navigation("Clients");
b.Navigation("Visits");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Guarantor", b =>
{
b.Navigation("Consultations");
b.Navigation("Hearings");
b.Navigation("Lawyers");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Hearing", b =>
{
b.Navigation("Lawyers");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Lawyer", b =>
{
b.Navigation("ConsultationLawyers");
b.Navigation("HearingLawyers");
});
modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Visit", b =>
{
b.Navigation("Clients");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace LawCompanyDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class test3 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "CaseType",
table: "Cases");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "CaseType",
table: "Cases",
type: "nvarchar(max)",
nullable: false,
defaultValue: "");
}
}
}

View File

@ -30,10 +30,6 @@ namespace LawCompanyDatabaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("CaseType")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
@ -301,7 +297,7 @@ namespace LawCompanyDatabaseImplement.Migrations
b.Property<int>("ExecutorId")
.HasColumnType("int");
b.Property<int>("HearingId")
b.Property<int?>("HearingId")
.HasColumnType("int");
b.Property<DateTime>("VisitDate")
@ -457,9 +453,7 @@ namespace LawCompanyDatabaseImplement.Migrations
b.HasOne("LawCompanyDatabaseImplement.Models.Hearing", "Hearing")
.WithMany()
.HasForeignKey("HearingId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
.HasForeignKey("HearingId");
b.Navigation("Hearing");
});

View File

@ -13,8 +13,6 @@ namespace LawCompanyDatabaseImplement.Models
[Required]
public string Name { get; private set; } = String.Empty;
[Required]
public string CaseType { get; private set; } = String.Empty;
[Required]
public DateTime DateCreate { get; private set; }
public DateTime? DateImplement { get; private set; }
[Required]
@ -29,9 +27,7 @@ namespace LawCompanyDatabaseImplement.Models
{
if (_caseClients == null)
{
using var context = new LawCompanyDatabase();
_caseClients = Clients
.ToDictionary(x => x.ClientId, x => (context.Clients.FirstOrDefault(y => y.Id == x.ClientId) as IClientModel));
_caseClients = Clients.ToDictionary(x => x.ClientId, x => (x.Client as IClientModel));
}
return _caseClients;
@ -41,10 +37,6 @@ namespace LawCompanyDatabaseImplement.Models
public virtual List<CaseClient> Clients { get; set; } = new();
public static Case Create(LawCompanyDatabase context, CaseBindingModel model)
{
if (model == null)
{
return null;
}
return new Case()
{
Id = model.Id,
@ -59,54 +51,57 @@ namespace LawCompanyDatabaseImplement.Models
}).ToList()
};
}
public void Update(CaseBindingModel? model)
public void Update(CaseBindingModel model)
{
using var context = new LawCompanyDatabase();
if (model == null)
if (model.Status == CaseStatus.ЗакрытиеДела)
{
return;
DateImplement = DateTime.Now;
}
if (model.Status == CaseStatus.ЗакрытиеДела) DateImplement = DateTime.Now;
Name = model.Name;
Status = model.Status;
if (model.DateImplement.HasValue) DateImplement = model.DateImplement;
if (model.DateImplement.HasValue)
{
DateImplement = model.DateImplement;
}
}
public CaseViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
CaseType = CaseType,
DateCreate = DateCreate,
DateImplement = DateImplement,
ExecutorId = ExecutorId,
Status = Status,
CaseClients = CaseClients,
};
public void UpdateClients(LawCompanyDatabase context, CaseBindingModel model)
{
var caseClients = context.CaseClients.Where(rec =>
rec.CaseId == model.Id).ToList();
var caseClients = context.CaseClients.Where(rec => rec.CaseId == model.Id).ToList();
if (caseClients != null && caseClients.Count > 0)
{ // удалили те, которых нет в модели
context.CaseClients.RemoveRange(caseClients.Where(rec
=> !model.CaseClients.ContainsKey(rec.ClientId)));
context.CaseClients.RemoveRange(caseClients.Where(rec => !model.CaseClients.ContainsKey(rec.ClientId)));
context.SaveChanges();
foreach (var updateLunch in caseClients)
{
model.CaseClients.Remove(updateLunch.ClientId);
}
context.SaveChanges();
}
var _case = context.Cases.First(x => x.Id == Id);
foreach (var pc in model.CaseClients)
{
if (!CaseClients.ContainsKey(pc.Key))
context.CaseClients.Add(new CaseClient
{
context.CaseClients.Add(new CaseClient
{
Case = _case,
Client = context.Clients.First(x => x.Id == pc.Key),
});
}
Case = _case,
Client = context.Clients.First(x => x.Id == pc.Key),
});
context.SaveChanges();
}
_caseClients = null;

View File

@ -20,6 +20,7 @@ namespace LawCompanyDatabaseImplement.Models
[ForeignKey("ClientId")]
public virtual List<VisitClient> ClientVisits { get; set; } = new();
public int ExecutorId { get; set; }
public virtual Executor Executor { get; set; }
public static Client? Create(ClientBindingModel? model)
{

View File

@ -13,12 +13,13 @@ namespace LawCompanyDatabaseImplement.Models
public DateTime VisitDate { get; private set; }
//связь один-к-одному
public int HearingId { get; private set; }
public int? HearingId { get; private set; }
public Hearing Hearing { get; set; } = null!;
//---
public int ExecutorId { get; set; }
private Dictionary<int, IClientModel>? _visitClients = null;
[NotMapped]
public Dictionary<int, IClientModel> VisitClients
{
@ -27,82 +28,69 @@ namespace LawCompanyDatabaseImplement.Models
if (_visitClients == null)
{
using var context = new LawCompanyDatabase();
_visitClients = Clients
.ToDictionary(x => x.ClientId, x => (context.Clients
.FirstOrDefault(y => y.Id == x.ClientId) as IClientModel));
_visitClients = Clients.ToDictionary(x => x.ClientId, x => (x.Client as IClientModel));
}
return _visitClients;
}
}
[ForeignKey("VisitId")]
public virtual List<VisitClient> Clients { get; set; } = new();
public static Visit? Create(LawCompanyDatabase context, VisitBindingModel? model)
public static Visit Create(LawCompanyDatabase context, VisitBindingModel model)
{
if (model == null)
{
return null;
}
var visits = context.Visits.Where(x => x.HearingId == model.HearingId).ToList();
if (visits.Count > 0)
{
return null;
}
return new Visit()
{
Id = model.Id,
VisitDate = model.VisitDate,
HearingId = model.HearingId,
ExecutorId = model.ExecutorId,
Hearing = context.Hearings.First(x => x.Id == model.HearingId),
Clients = model.VisitClients.Select(x => new VisitClient
{
Client = context.Clients.First(y => y.Id == x.Key)
}).ToList()
};
}
public void Update(VisitBindingModel? model)
public void Update(VisitBindingModel model)
{
using var context = new LawCompanyDatabase();
if (model == null)
{
return;
}
VisitDate = model.VisitDate;
HearingId = model.HearingId;
}
public VisitViewModel GetViewModel => new()
{
Id = Id,
VisitDate = VisitDate,
HearingId = HearingId,
VisitClients = VisitClients,
ExecutorId = ExecutorId,
};
public void UpdateClients(LawCompanyDatabase context,
VisitBindingModel model)
public void UpdateClients(LawCompanyDatabase context, VisitBindingModel model)
{
var visitClients = context.VisitClients.Where(rec =>
rec.VisitId == model.Id).ToList();
var visitClients = context.VisitClients.Where(rec => rec.VisitId == model.Id).ToList();
if (visitClients != null && visitClients.Count > 0)
{ // удалили те, которых нет в модели
context.VisitClients.RemoveRange(visitClients.Where(rec
=> !model.VisitClients.ContainsKey(rec.ClientId)));
context.VisitClients.RemoveRange(visitClients.Where(rec => !model.VisitClients.ContainsKey(rec.ClientId)));
context.SaveChanges();
foreach (var updateLunch in visitClients)
{
model.VisitClients.Remove(updateLunch.ClientId);
}
context.SaveChanges();
}
var _visit = context.Visits.First(x => x.Id == Id);
foreach (var pc in model.VisitClients)
{
if (!VisitClients.ContainsKey(pc.Key))
context.VisitClients.Add(new VisitClient
{
context.VisitClients.Add(new VisitClient
{
Visit = _visit,
Client = context.Clients.First(x => x.Id == pc.Key),
});
}
Visit = _visit,
Client = context.Clients.First(x => x.Id == pc.Key),
});
context.SaveChanges();
}
_visitClients = null;