4. Создание моделей и базы данных
This commit is contained in:
parent
e10647bca8
commit
def5df21d0
@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirmContracts", "LawFirm
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirmBusinessLogic", "LawFirmBusinessLogic\LawFirmBusinessLogic.csproj", "{08E0AB8D-1F53-4757-BA64-D76A2EB866C0}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirmBusinessLogic", "LawFirmBusinessLogic\LawFirmBusinessLogic.csproj", "{08E0AB8D-1F53-4757-BA64-D76A2EB866C0}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirmDatabase", "LawFirmDatabase\LawFirmDatabase.csproj", "{A05000F4-BF89-4515-A8C7-FB5D962E3802}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -27,6 +29,10 @@ Global
|
|||||||
{08E0AB8D-1F53-4757-BA64-D76A2EB866C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{08E0AB8D-1F53-4757-BA64-D76A2EB866C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{08E0AB8D-1F53-4757-BA64-D76A2EB866C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{08E0AB8D-1F53-4757-BA64-D76A2EB866C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{08E0AB8D-1F53-4757-BA64-D76A2EB866C0}.Release|Any CPU.Build.0 = Release|Any CPU
|
{08E0AB8D-1F53-4757-BA64-D76A2EB866C0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{A05000F4-BF89-4515-A8C7-FB5D962E3802}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{A05000F4-BF89-4515-A8C7-FB5D962E3802}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{A05000F4-BF89-4515-A8C7-FB5D962E3802}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{A05000F4-BF89-4515-A8C7-FB5D962E3802}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -23,4 +23,10 @@
|
|||||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.3" />
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\LawFirmBusinessLogic\LawFirmBusinessLogic.csproj" />
|
||||||
|
<ProjectReference Include="..\LawFirmContracts\LawFirmContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\LawFirmDatabase\LawFirmDatabase.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
@ -1,3 +1,5 @@
|
|||||||
|
using LawFirmDatabase;
|
||||||
|
|
||||||
namespace LawFirmView
|
namespace LawFirmView
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
|
@ -6,6 +6,21 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.4" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||||
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\LawFirmContracts\LawFirmContracts.csproj" />
|
<ProjectReference Include="..\LawFirmContracts\LawFirmContracts.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
34
LawFirm/LawFirmDatabase/LawFirmDBContext.cs
Normal file
34
LawFirm/LawFirmDatabase/LawFirmDBContext.cs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using LawFirmDatabase.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace LawFirmDatabase
|
||||||
|
{
|
||||||
|
public class LawFirmDBContext : DbContext
|
||||||
|
{
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
|
{
|
||||||
|
if (optionsBuilder.IsConfigured == false)
|
||||||
|
{
|
||||||
|
optionsBuilder.UseSqlServer
|
||||||
|
(
|
||||||
|
@"Data Source=KITOSYA;
|
||||||
|
Initial Catalog=AircraftPlantDataBaseFull;
|
||||||
|
Integrated Security=True;
|
||||||
|
MultipleActiveResultSets=True;;
|
||||||
|
TrustServerCertificate=True"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
base.OnConfiguring(optionsBuilder);
|
||||||
|
}
|
||||||
|
public virtual DbSet<Customer> Customers { get; set; }
|
||||||
|
public virtual DbSet<Item> Items { get; set; }
|
||||||
|
public virtual DbSet<Case> Cases { get; set; }
|
||||||
|
public virtual DbSet<Payment> Payments { get; set; }
|
||||||
|
public virtual DbSet<Service> Services { get; set; }
|
||||||
|
}
|
||||||
|
}
|
28
LawFirm/LawFirmDatabase/LawFirmDatabase.csproj
Normal file
28
LawFirm/LawFirmDatabase/LawFirmDatabase.csproj
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.4" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||||
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\LawFirmContracts\LawFirmContracts.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
228
LawFirm/LawFirmDatabase/Migrations/20230408032638_InitMigration.Designer.cs
generated
Normal file
228
LawFirm/LawFirmDatabase/Migrations/20230408032638_InitMigration.Designer.cs
generated
Normal file
@ -0,0 +1,228 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using LawFirmDatabase;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace LawFirmDatabase.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(LawFirmDBContext))]
|
||||||
|
[Migration("20230408032638_InitMigration")]
|
||||||
|
partial class InitMigration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "7.0.4")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||||
|
|
||||||
|
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Case", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("CustomerId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("CustomerId");
|
||||||
|
|
||||||
|
b.ToTable("Cases");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Customer", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Login")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Password")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Surname")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Customers");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Item", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<int>("PaymentId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<decimal>("Price")
|
||||||
|
.HasColumnType("decimal (10,2)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("PaymentId");
|
||||||
|
|
||||||
|
b.ToTable("Items");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Payment", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("CaseId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<decimal>("Sum")
|
||||||
|
.HasColumnType("decimal (10,2)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("CaseId");
|
||||||
|
|
||||||
|
b.ToTable("Payments");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Service", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("CaseId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("ItemId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<decimal>("Price")
|
||||||
|
.HasColumnType("decimal (10,2)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("CaseId");
|
||||||
|
|
||||||
|
b.HasIndex("ItemId");
|
||||||
|
|
||||||
|
b.ToTable("Services");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Case", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("LawFirmDatabase.Models.Customer", "Customer")
|
||||||
|
.WithMany("Cases")
|
||||||
|
.HasForeignKey("CustomerId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Customer");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Item", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("LawFirmDatabase.Models.Payment", "Payments")
|
||||||
|
.WithMany("Items")
|
||||||
|
.HasForeignKey("PaymentId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Payments");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Payment", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("LawFirmDatabase.Models.Case", "Cases")
|
||||||
|
.WithMany("Payments")
|
||||||
|
.HasForeignKey("CaseId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Cases");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Service", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("LawFirmDatabase.Models.Case", "Cases")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("CaseId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("LawFirmDatabase.Models.Item", "Items")
|
||||||
|
.WithMany("Services")
|
||||||
|
.HasForeignKey("ItemId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Cases");
|
||||||
|
|
||||||
|
b.Navigation("Items");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Case", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Payments");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Customer", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Cases");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Item", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Services");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Payment", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Items");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,163 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace LawFirmDatabase.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class InitMigration : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Customers",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
Login = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
Password = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
Surname = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Customers", 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),
|
||||||
|
CustomerId = table.Column<int>(type: "int", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Cases", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Cases_Customers_CustomerId",
|
||||||
|
column: x => x.CustomerId,
|
||||||
|
principalTable: "Customers",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Payments",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
Sum = table.Column<decimal>(type: "decimal (10,2)", nullable: false),
|
||||||
|
CaseId = table.Column<int>(type: "int", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Payments", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Payments_Cases_CaseId",
|
||||||
|
column: x => x.CaseId,
|
||||||
|
principalTable: "Cases",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Items",
|
||||||
|
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),
|
||||||
|
Price = table.Column<decimal>(type: "decimal (10,2)", nullable: false),
|
||||||
|
PaymentId = table.Column<int>(type: "int", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Items", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Items_Payments_PaymentId",
|
||||||
|
column: x => x.PaymentId,
|
||||||
|
principalTable: "Payments",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Services",
|
||||||
|
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),
|
||||||
|
Price = table.Column<decimal>(type: "decimal (10,2)", nullable: false),
|
||||||
|
ItemId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
CaseId = table.Column<int>(type: "int", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Services", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Services_Cases_CaseId",
|
||||||
|
column: x => x.CaseId,
|
||||||
|
principalTable: "Cases",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Services_Items_ItemId",
|
||||||
|
column: x => x.ItemId,
|
||||||
|
principalTable: "Items",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Cases_CustomerId",
|
||||||
|
table: "Cases",
|
||||||
|
column: "CustomerId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Items_PaymentId",
|
||||||
|
table: "Items",
|
||||||
|
column: "PaymentId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Payments_CaseId",
|
||||||
|
table: "Payments",
|
||||||
|
column: "CaseId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Services_CaseId",
|
||||||
|
table: "Services",
|
||||||
|
column: "CaseId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Services_ItemId",
|
||||||
|
table: "Services",
|
||||||
|
column: "ItemId");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Services");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Items");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Payments");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Cases");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Customers");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,225 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using LawFirmDatabase;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace LawFirmDatabase.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(LawFirmDBContext))]
|
||||||
|
partial class LawFirmDBContextModelSnapshot : ModelSnapshot
|
||||||
|
{
|
||||||
|
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "7.0.4")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||||
|
|
||||||
|
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Case", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("CustomerId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("CustomerId");
|
||||||
|
|
||||||
|
b.ToTable("Cases");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Customer", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Login")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Password")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Surname")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Customers");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Item", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<int>("PaymentId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<decimal>("Price")
|
||||||
|
.HasColumnType("decimal (10,2)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("PaymentId");
|
||||||
|
|
||||||
|
b.ToTable("Items");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Payment", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("CaseId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<decimal>("Sum")
|
||||||
|
.HasColumnType("decimal (10,2)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("CaseId");
|
||||||
|
|
||||||
|
b.ToTable("Payments");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Service", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("CaseId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("ItemId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<decimal>("Price")
|
||||||
|
.HasColumnType("decimal (10,2)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("CaseId");
|
||||||
|
|
||||||
|
b.HasIndex("ItemId");
|
||||||
|
|
||||||
|
b.ToTable("Services");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Case", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("LawFirmDatabase.Models.Customer", "Customer")
|
||||||
|
.WithMany("Cases")
|
||||||
|
.HasForeignKey("CustomerId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Customer");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Item", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("LawFirmDatabase.Models.Payment", "Payments")
|
||||||
|
.WithMany("Items")
|
||||||
|
.HasForeignKey("PaymentId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Payments");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Payment", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("LawFirmDatabase.Models.Case", "Cases")
|
||||||
|
.WithMany("Payments")
|
||||||
|
.HasForeignKey("CaseId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Cases");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Service", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("LawFirmDatabase.Models.Case", "Cases")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("CaseId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("LawFirmDatabase.Models.Item", "Items")
|
||||||
|
.WithMany("Services")
|
||||||
|
.HasForeignKey("ItemId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Cases");
|
||||||
|
|
||||||
|
b.Navigation("Items");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Case", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Payments");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Customer", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Cases");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Item", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Services");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Payment", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Items");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
63
LawFirm/LawFirmDatabase/Models/Case.cs
Normal file
63
LawFirm/LawFirmDatabase/Models/Case.cs
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using LawFirmContracts;
|
||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.Models;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using Azure;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
|
||||||
|
namespace LawFirmDatabase.Models
|
||||||
|
{
|
||||||
|
public class Case : ICaseModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
[Required]
|
||||||
|
public string Name { get; private set; } = string.Empty;
|
||||||
|
[NotMapped]
|
||||||
|
public DateTime DateCreated { get; private set; }
|
||||||
|
[Required]
|
||||||
|
public int CustomerId { get; private set; }
|
||||||
|
[ForeignKey("CaseId")]
|
||||||
|
public virtual List<Payment> Payments { get; set; } = new();
|
||||||
|
public virtual Customer Customer { get; set; } = new();
|
||||||
|
public static Case? Create(LawFirmDBContext context, ICaseModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
DateCreated = model.DateCreated,
|
||||||
|
Customer = context.Customers.First(x => x.Id == model.CustomerId)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(LawFirmDBContext context, ICaseModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Id = model.Id;
|
||||||
|
DateCreated = model.DateCreated;
|
||||||
|
Customer = context.Customers.First(x => x.Id == model.CustomerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CaseViewModel? GetViewModel() => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
Name = Name,
|
||||||
|
DateCreated = DateCreated,
|
||||||
|
CustomerId = CustomerId
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
66
LawFirm/LawFirmDatabase/Models/Customer.cs
Normal file
66
LawFirm/LawFirmDatabase/Models/Customer.cs
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using LawFirmContracts;
|
||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.Models;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
|
||||||
|
namespace LawFirmDatabase.Models
|
||||||
|
{
|
||||||
|
public class Customer : ICustomerModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
[Required]
|
||||||
|
public string Login { get; private set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public string Password { get; private set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public string Name { get; private set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public string Surname { get; private set; } = string.Empty;
|
||||||
|
[ForeignKey("CustomerId")]
|
||||||
|
public virtual List<Case> Cases { get; set; } = new();
|
||||||
|
public static Customer? Create(ICustomerModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
Login = model.Login,
|
||||||
|
Password = model.Password,
|
||||||
|
Name = model.Name,
|
||||||
|
Surname = model.Surname,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(ICustomerModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Login = model.Login;
|
||||||
|
Password = model.Password;
|
||||||
|
Name = model.Name;
|
||||||
|
Surname = model.Surname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomerViewModel? GetViewModel() => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
Login = Login,
|
||||||
|
Password = Password,
|
||||||
|
Name = Name,
|
||||||
|
Surname = Surname,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
55
LawFirm/LawFirmDatabase/Models/Item.cs
Normal file
55
LawFirm/LawFirmDatabase/Models/Item.cs
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.Models;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||||
|
using System;
|
||||||
|
using LawFirmContracts;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace LawFirmDatabase.Models
|
||||||
|
{
|
||||||
|
public class Item : IItemModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
[Required]
|
||||||
|
public string Name { get; private set; } = string.Empty;
|
||||||
|
[Required, Column(TypeName = "decimal (10,2)")]
|
||||||
|
public decimal Price { get; private set; }
|
||||||
|
[Required]
|
||||||
|
public int PaymentId { get; private set; }
|
||||||
|
[ForeignKey("ItemId")]
|
||||||
|
public virtual List<Service> Services { get; set; } = new();
|
||||||
|
public virtual Payment Payments { get; set; } = new();
|
||||||
|
public static Item? Create(LawFirmDBContext context, ItemBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Name = model.Name,
|
||||||
|
Price = model.Price,
|
||||||
|
Payments = context.Payments.First(x => x.Id == model.PaymentId)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(LawFirmDBContext context, ItemBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Name = model.Name;
|
||||||
|
Price = model.Price;
|
||||||
|
Payments = context.Payments.First(x => x.Id == model.PaymentId);
|
||||||
|
}
|
||||||
|
public ItemViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
Name = Name,
|
||||||
|
Price = Price,
|
||||||
|
PaymentId = PaymentId,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
64
LawFirm/LawFirmDatabase/Models/Payment.cs
Normal file
64
LawFirm/LawFirmDatabase/Models/Payment.cs
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using LawFirmContracts;
|
||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.Models;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
|
||||||
|
namespace LawFirmDatabase.Models
|
||||||
|
{
|
||||||
|
public class Payment : IPaymentModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
[NotMapped]
|
||||||
|
public DateTime DatePayment { get; private set; } = DateTime.Now;
|
||||||
|
[Required, Column(TypeName = "decimal (10,2)")]
|
||||||
|
public decimal Sum { get; private set; }
|
||||||
|
[Required]
|
||||||
|
public int CaseId { get; private set; }
|
||||||
|
[ForeignKey("PaymentId")]
|
||||||
|
public virtual List<Item> Items { get; set; } = new();
|
||||||
|
public virtual Case Cases { get; set; } = new();
|
||||||
|
|
||||||
|
public static Payment? Create(LawFirmDBContext context, IPaymentModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
Sum = model.Sum,
|
||||||
|
DatePayment = model.DatePayment,
|
||||||
|
Cases = context.Cases.First(x => x.Id == model.CaseId)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(LawFirmDBContext context, IPaymentModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Id = model.Id;
|
||||||
|
Sum = model.Sum;
|
||||||
|
DatePayment = model.DatePayment;
|
||||||
|
Cases = context.Cases.First(x => x.Id == model.CaseId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PaymentViewModel? GetViewModel() => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
Sum = Sum,
|
||||||
|
DatePayment = DatePayment,
|
||||||
|
CaseId = CaseId,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
65
LawFirm/LawFirmDatabase/Models/Service.cs
Normal file
65
LawFirm/LawFirmDatabase/Models/Service.cs
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using LawFirmContracts;
|
||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.Models;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace LawFirmDatabase.Models
|
||||||
|
{
|
||||||
|
public class Service : IServiceModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
[Required]
|
||||||
|
public string Name { get; private set; } = string.Empty;
|
||||||
|
[Required, Column(TypeName = "decimal (10,2)")]
|
||||||
|
public decimal Price { get; private set; }
|
||||||
|
[Required]
|
||||||
|
public int ItemId { get; private set; }
|
||||||
|
public int CaseId { get; private set; }
|
||||||
|
public virtual Item Items { get; set; } = new();
|
||||||
|
public virtual Case Cases { get; set; } = new();
|
||||||
|
|
||||||
|
public static Service? Create(LawFirmDBContext context, IServiceModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
Name = model.Name,
|
||||||
|
Price = model.Price,
|
||||||
|
Items = context.Items.First(x => x.Id == model.ItemId),
|
||||||
|
Cases = context.Cases.First(x => x.Id == model.CaseId)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(LawFirmDBContext context, IServiceModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Id = model.Id;
|
||||||
|
Name = model.Name;
|
||||||
|
Price = model.Price;
|
||||||
|
Items = context.Items.First(x => x.Id == model.ItemId);
|
||||||
|
Cases = context.Cases.First(x => x.Id == model.CaseId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServiceViewModel? GetViewModel() => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
Name = Name,
|
||||||
|
Price = Price,
|
||||||
|
ItemId = ItemId,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user