ааа
This commit is contained in:
parent
e4abf1b41a
commit
be264cb02b
@ -1,7 +1,7 @@
|
||||
using RenovationWorkBusinessLogic.BusinessLogics;
|
||||
using RenovationWorkContracts.BusinessLogicsContracts;
|
||||
using RenovationWorkContracts.StoragesContracts;
|
||||
using RenovationWorkFileImplement.Implements;
|
||||
using RenovationWorkDatabaseImplement.Implements;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog.Extensions.Logging;
|
||||
|
@ -9,6 +9,10 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="NLog" Version="5.2.8" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
|
||||
</ItemGroup>
|
||||
@ -16,6 +20,7 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\RenovationWorkBusinessLogic\RenovationWorkBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\RenovationWorkContracts\RenovationWorkContracts.csproj" />
|
||||
<ProjectReference Include="..\RenovationWorkDatabaseImplement\RenovationWorkDatabaseImplement.csproj" />
|
||||
<ProjectReference Include="..\RenovationWorkFileImplement\RenovationWorkFileImplement.csproj" />
|
||||
<ProjectReference Include="..\RenovationWorkListImplement\RenovationWorkListImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
@ -0,0 +1,81 @@
|
||||
using RenovationWorkContracts.BindingModels;
|
||||
using RenovationWorkContracts.SearchModels;
|
||||
using RenovationWorkContracts.StoragesContracts;
|
||||
using RenovationWorkContracts.ViewModels;
|
||||
using RenovationWorkDatabaseImplement;
|
||||
using RenovationWorkDatabaseImplement.Models;
|
||||
|
||||
namespace RenovationWorkDatabaseImplement.Implements
|
||||
{
|
||||
public class ComponentStorage : IComponentStorage
|
||||
{
|
||||
public List<ComponentViewModel> GetFullList()
|
||||
{
|
||||
using var context = new RenovationWorkDatabase();
|
||||
return context.Components
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ComponentName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new RenovationWorkDatabase();
|
||||
return context.Components
|
||||
.Where(x => x.ComponentName.Contains(model.ComponentName))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new RenovationWorkDatabase();
|
||||
return context.Components
|
||||
.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName ==
|
||||
model.ComponentName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
public ComponentViewModel? Insert(ComponentBindingModel model)
|
||||
{
|
||||
var newComponent = Component.Create(model);
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new RenovationWorkDatabase();
|
||||
context.Components.Add(newComponent);
|
||||
context.SaveChanges();
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
public ComponentViewModel? Update(ComponentBindingModel model)
|
||||
{
|
||||
using var context = new RenovationWorkDatabase();
|
||||
var component = context.Components.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
context.SaveChanges();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
public ComponentViewModel? Delete(ComponentBindingModel model)
|
||||
{
|
||||
using var context = new RenovationWorkDatabase();
|
||||
var element = context.Components.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Components.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
using RenovationWorkContracts.BindingModels;
|
||||
using RenovationWorkContracts.SearchModels;
|
||||
using RenovationWorkContracts.StoragesContracts;
|
||||
using RenovationWorkContracts.ViewModels;
|
||||
using RenovationWorkDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace RenovationWorkDatabaseImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
using var Context = new RenovationWorkDatabase();
|
||||
|
||||
return Context.Orders
|
||||
.Include(x => x.Repair)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel Model)
|
||||
{
|
||||
if (!Model.Id.HasValue)
|
||||
return new();
|
||||
|
||||
using var Context = new RenovationWorkDatabase();
|
||||
|
||||
return Context.Orders
|
||||
.Include(x => x.Repair)
|
||||
.Where(x => x.Id == Model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel Model)
|
||||
{
|
||||
if (!Model.Id.HasValue)
|
||||
return new();
|
||||
|
||||
using var Context = new RenovationWorkDatabase();
|
||||
|
||||
return Context.Orders
|
||||
.Include(x => x.Repair)
|
||||
.FirstOrDefault(x => x.Id == Model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel Model)
|
||||
{
|
||||
using var Context = new RenovationWorkDatabase();
|
||||
|
||||
if (Model == null)
|
||||
return null;
|
||||
|
||||
var NewOrder = Order.Create(Context, Model);
|
||||
if (NewOrder == null)
|
||||
return null;
|
||||
|
||||
Context.Orders.Add(NewOrder);
|
||||
Context.SaveChanges();
|
||||
|
||||
return NewOrder.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel Model)
|
||||
{
|
||||
using var Context = new RenovationWorkDatabase();
|
||||
|
||||
var Order = Context.Orders.FirstOrDefault(x => x.Id == Model.Id);
|
||||
if (Order == null)
|
||||
return null;
|
||||
|
||||
Order.Update(Model);
|
||||
Context.SaveChanges();
|
||||
|
||||
return Order.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Delete(OrderBindingModel Model)
|
||||
{
|
||||
using var Context = new RenovationWorkDatabase();
|
||||
var Order = Context.Orders.FirstOrDefault(rec => rec.Id == Model.Id);
|
||||
|
||||
if (Order == null)
|
||||
return null;
|
||||
|
||||
Context.Orders.Remove(Order);
|
||||
Context.SaveChanges();
|
||||
|
||||
return Order.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
using RenovationWorkContracts.BindingModels;
|
||||
using RenovationWorkContracts.SearchModels;
|
||||
using RenovationWorkContracts.StoragesContracts;
|
||||
using RenovationWorkContracts.ViewModels;
|
||||
using RenovationWorkDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
namespace RenovationWorkDatabaseImplement.Implements
|
||||
{
|
||||
public class RepairStorage : IRepairStorage
|
||||
{
|
||||
public List<RepairViewModel> GetFullList()
|
||||
{
|
||||
using var context = new RenovationWorkDatabase();
|
||||
return context.Repairs
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<RepairViewModel> GetFilteredList(RepairSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.RepairName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new RenovationWorkDatabase();
|
||||
return context.Repairs
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.Where(x => x.RepairName.Contains(model.RepairName))
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public RepairViewModel? GetElement(RepairSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.RepairName) &&
|
||||
!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new RenovationWorkDatabase();
|
||||
return context.Repairs
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.RepairName) &&
|
||||
x.RepairName == model.RepairName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
public RepairViewModel? Insert(RepairBindingModel model)
|
||||
{
|
||||
using var context = new RenovationWorkDatabase();
|
||||
var newRepair = Repair.Create(context, model);
|
||||
if (newRepair == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Repairs.Add(newRepair);
|
||||
context.SaveChanges();
|
||||
return newRepair.GetViewModel;
|
||||
}
|
||||
public RepairViewModel? Update(RepairBindingModel model)
|
||||
{
|
||||
using var context = new RenovationWorkDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var repair = context.Repairs.FirstOrDefault(rec =>
|
||||
rec.Id == model.Id);
|
||||
if (repair == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
repair.Update(model);
|
||||
context.SaveChanges();
|
||||
repair.UpdateComponents(context, model);
|
||||
transaction.Commit();
|
||||
return repair.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public RepairViewModel? Delete(RepairBindingModel model)
|
||||
{
|
||||
using var context = new RenovationWorkDatabase();
|
||||
var element = context.Repairs
|
||||
.Include(x => x.Components)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Repairs.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
171
RenovationWork/RenovationWorkDatabaseImplement/Migrations/20240405063901_InitialCreate.Designer.cs
generated
Normal file
171
RenovationWork/RenovationWorkDatabaseImplement/Migrations/20240405063901_InitialCreate.Designer.cs
generated
Normal file
@ -0,0 +1,171 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using RenovationWorkDatabaseImplement;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace RenovationWorkDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(RenovationWorkDatabase))]
|
||||
[Migration("20240405063901_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "8.0.3")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<int>("RepairId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("RepairId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.Repair", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("RepairName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Repairs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.RepairComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("RepairId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.HasIndex("RepairId");
|
||||
|
||||
b.ToTable("RepairComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("RenovationWorkDatabaseImplement.Models.Repair", "Repair")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("RepairId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Repair");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.RepairComponent", b =>
|
||||
{
|
||||
b.HasOne("RenovationWorkDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("RepairComponent")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("RenovationWorkDatabaseImplement.Models.Repair", "Repair")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("RepairId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Repair");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("RepairComponent");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.Repair", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,126 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace RenovationWorkDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Components",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
ComponentName = table.Column<string>(type: "text", nullable: false),
|
||||
Cost = table.Column<double>(type: "double precision", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Components", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Repairs",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
RepairName = table.Column<string>(type: "text", nullable: false),
|
||||
Price = table.Column<double>(type: "double precision", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Repairs", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Orders",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
RepairId = table.Column<int>(type: "integer", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false),
|
||||
Sum = table.Column<double>(type: "double precision", nullable: false),
|
||||
Status = table.Column<int>(type: "integer", nullable: false),
|
||||
DateCreate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
|
||||
DateImplement = table.Column<DateTime>(type: "timestamp without time zone", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Orders", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Orders_Repairs_RepairId",
|
||||
column: x => x.RepairId,
|
||||
principalTable: "Repairs",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "RepairComponents",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
RepairId = table.Column<int>(type: "integer", nullable: false),
|
||||
ComponentId = table.Column<int>(type: "integer", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_RepairComponents", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_RepairComponents_Components_ComponentId",
|
||||
column: x => x.ComponentId,
|
||||
principalTable: "Components",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_RepairComponents_Repairs_RepairId",
|
||||
column: x => x.RepairId,
|
||||
principalTable: "Repairs",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_RepairId",
|
||||
table: "Orders",
|
||||
column: "RepairId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_RepairComponents_ComponentId",
|
||||
table: "RepairComponents",
|
||||
column: "ComponentId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_RepairComponents_RepairId",
|
||||
table: "RepairComponents",
|
||||
column: "RepairId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Orders");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "RepairComponents");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Components");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Repairs");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,168 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using RenovationWorkDatabaseImplement;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace RenovationWorkDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(RenovationWorkDatabase))]
|
||||
partial class RenovationWorkDatabaseModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "8.0.3")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<int>("RepairId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("RepairId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.Repair", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("RepairName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Repairs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.RepairComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("RepairId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.HasIndex("RepairId");
|
||||
|
||||
b.ToTable("RepairComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("RenovationWorkDatabaseImplement.Models.Repair", "Repair")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("RepairId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Repair");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.RepairComponent", b =>
|
||||
{
|
||||
b.HasOne("RenovationWorkDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("RepairComponent")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("RenovationWorkDatabaseImplement.Models.Repair", "Repair")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("RepairId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Repair");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("RepairComponent");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.Repair", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -20,7 +20,7 @@ namespace RenovationWorkDatabaseImplement.Models
|
||||
[Required]
|
||||
public double Cost { get; set; }
|
||||
[ForeignKey("ComponentId")]
|
||||
public virtual List<ProductComponent> ProductComponents { get; set; } = new();
|
||||
public virtual List<RepairComponent> RepairComponent { get; set; } = new();
|
||||
public static Component? Create(ComponentBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
|
@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -14,56 +16,62 @@ namespace RenovationWorkDatabaseImplement.Models
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
public int RepairId { get; private set; }
|
||||
|
||||
public virtual Repair Repair { get; set; } = new();
|
||||
|
||||
[Required]
|
||||
public int Count { get; private set; }
|
||||
|
||||
[Required]
|
||||
public double Sum { get; private set; }
|
||||
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
[Required]
|
||||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
[Required]
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
|
||||
public DateTime? DateImplement { get; set; }
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
public static Order Create(RenovationWorkDatabase context, OrderBindingModel Model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Order()
|
||||
{
|
||||
Id = model.Id,
|
||||
RepairId = model.RepairId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement
|
||||
Id = Model.Id,
|
||||
RepairId = Model.RepairId,
|
||||
Count = Model.Count,
|
||||
Sum = Model.Sum,
|
||||
Status = Model.Status,
|
||||
DateCreate = Model.DateCreate,
|
||||
DateImplement = Model.DateImplement,
|
||||
};
|
||||
}
|
||||
public void Update(OrderBindingModel? model)
|
||||
|
||||
public void Update(OrderBindingModel Model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
if (Model == null)
|
||||
return;
|
||||
}
|
||||
Status = model.Status;
|
||||
if (model.DateImplement != null)
|
||||
{
|
||||
DateImplement = model.DateImplement;
|
||||
}
|
||||
|
||||
Id = Model.Id;
|
||||
RepairId = Model.RepairId;
|
||||
Sum = Model.Sum;
|
||||
Status = Model.Status;
|
||||
DateCreate = Model.DateCreate;
|
||||
DateImplement = Model.DateImplement;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
RepairId = RepairId,
|
||||
RepairName = Repair.RepairName,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement
|
||||
DateImplement = DateImplement,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,47 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using RenovationWorkContracts.BindingModels;
|
||||
using RenovationWorkContracts.BindingModels;
|
||||
using RenovationWorkContracts.ViewModels;
|
||||
using RenovationWorkDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace RenovationWorkDatabaseImplement.Models
|
||||
{
|
||||
public class Repair : IRepairModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string RepairName { get; private set; } = string.Empty;
|
||||
public double Price { get; private set; }
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string RepairName { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public double Price { get; set; }
|
||||
private Dictionary<int, (IComponentModel, int)>? _repairComponents = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IComponentModel, int)> RepairComponents
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = new Dictionary<int, (IComponentModel, int)>();
|
||||
public static Repair? Create(RepairBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
get
|
||||
{
|
||||
return null;
|
||||
if (_repairComponents == null)
|
||||
{
|
||||
_repairComponents = Components.ToDictionary(recDC => recDC.ComponentId, recDC => (recDC.Component as IComponentModel, recDC.Count));
|
||||
}
|
||||
return _repairComponents;
|
||||
}
|
||||
}
|
||||
[ForeignKey("RepairId")]
|
||||
public virtual List<RepairComponent> Components { get; set; } = new();
|
||||
[ForeignKey("RepairId")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
public static Repair Create(RenovationWorkDatabase context, RepairBindingModel model)
|
||||
{
|
||||
return new Repair()
|
||||
{
|
||||
Id = model.Id,
|
||||
RepairName = model.RepairName,
|
||||
Price = model.Price,
|
||||
RepairComponents = model.RepairComponents
|
||||
Components = model.RepairComponents.Select(x => new RepairComponent
|
||||
{
|
||||
Component = context.Components.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
public void Update(RepairBindingModel? model)
|
||||
public void Update(RepairBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
RepairName = model.RepairName;
|
||||
Price = model.Price;
|
||||
RepairComponents = model.RepairComponents;
|
||||
}
|
||||
public RepairViewModel GetViewModel => new()
|
||||
{
|
||||
@ -50,5 +56,32 @@ namespace RenovationWorkDatabaseImplement.Models
|
||||
Price = Price,
|
||||
RepairComponents = RepairComponents
|
||||
};
|
||||
public void UpdateComponents(RenovationWorkDatabase context, RepairBindingModel model)
|
||||
{
|
||||
var repairComponents = context.RepairComponents.Where(rec => rec.RepairId == model.Id).ToList();
|
||||
if (repairComponents != null && repairComponents.Count > 0)
|
||||
{
|
||||
context.RepairComponents.RemoveRange(repairComponents.Where(rec => !model.RepairComponents.ContainsKey(rec.ComponentId)));
|
||||
context.SaveChanges();
|
||||
foreach (var updateComponent in repairComponents)
|
||||
{
|
||||
updateComponent.Count = model.RepairComponents[updateComponent.ComponentId].Item2;
|
||||
model.RepairComponents.Remove(updateComponent.ComponentId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var repair = context.Repairs.First(x => x.Id == Id);
|
||||
foreach (var pc in model.RepairComponents)
|
||||
{
|
||||
context.RepairComponents.Add(new RepairComponent
|
||||
{
|
||||
Repair = repair,
|
||||
Component = context.Components.First(x => x.Id == pc.Key),
|
||||
Count = pc.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_repairComponents = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RenovationWorkDatabaseImplement.Models
|
||||
{
|
||||
public class RepairComponent
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int RepairId { get; set; }
|
||||
[Required]
|
||||
public int ComponentId { get; set; }
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
public virtual Component Component { get; set; } = new();
|
||||
public virtual Repair Repair { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
using RenovationWorkDatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RenovationWorkDatabaseImplement
|
||||
{
|
||||
public class RenovationWorkDatabase: DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseNpgsql(@"Host=localhost;Port=5432;Database=RenovationWorkDatabaseFull;Username=postgres;Password=postgres");
|
||||
}
|
||||
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
|
||||
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
||||
AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);
|
||||
}
|
||||
public virtual DbSet<Component> Components { set; get; }
|
||||
public virtual DbSet<Repair> Repairs { set; get; }
|
||||
public virtual DbSet<RepairComponent> RepairComponents { set; get; }
|
||||
public virtual DbSet<Order> Orders { set; get; }
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
@ -11,12 +11,12 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.17" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.17" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.17">
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.3" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user