ISEbd-22_Andrikhov_A.S. Lab work 3 BASE #3

Closed
asoc1al wants to merge 1 commits from lab3 into lab2
20 changed files with 1091 additions and 25 deletions
Showing only changes of commit 0bdd8aa43c - Show all commits

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

View File

@ -0,0 +1,30 @@
using AutoWorkshopDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using Npgsql.EntityFrameworkCore.PostgreSQL;
namespace AutoWorkshopDatabaseImplement
{
public class AutoWorkshopDatabase : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder OptionsBuilder)
{
if (OptionsBuilder.IsConfigured == false)
{
OptionsBuilder.UseNpgsql(@"Host=localhost;Database=AutoWorkshop;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; }
}
}

View File

@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.17" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.17">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="netcore-psql-util" Version="1.2.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AutoWorkshopContracts\AutoWorkshopContracts.csproj" />
<ProjectReference Include="..\AutoWorkshopDataModels\AutoWorkshopDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,82 @@
using AutoWorkshopContracts.BindingModels;
using AutoWorkshopContracts.SearchModels;
using AutoWorkshopContracts.StoragesContracts;
using AutoWorkshopContracts.ViewModels;
using AutoWorkshopDatabaseImplement.Models;
namespace AutoWorkshopDatabaseImplement.Implements
{
public class ComponentStorage : IComponentStorage
{
public List<ComponentViewModel> GetFullList()
{
using var Context = new AutoWorkshopDatabase();
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 AutoWorkshopDatabase();
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 AutoWorkshopDatabase();
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 AutoWorkshopDatabase();
Context.Components.Add(NewComponent);
Context.SaveChanges();
return NewComponent.GetViewModel;
}
public ComponentViewModel? Update(ComponentBindingModel Model)
{
using var Context = new AutoWorkshopDatabase();
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 AutoWorkshopDatabase();
var Component = Context.Components.FirstOrDefault(rec => rec.Id == Model.Id);
if (Component == null)
return null;
Context.Components.Remove(Component);
Context.SaveChanges();
return Component.GetViewModel;
}
}
}

View File

@ -0,0 +1,94 @@
using AutoWorkshopContracts.BindingModels;
using AutoWorkshopContracts.SearchModels;
using AutoWorkshopContracts.StoragesContracts;
using AutoWorkshopContracts.ViewModels;
using AutoWorkshopDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace AutoWorkshopDatabaseImplement.Implements
{
public class OrderStorage : IOrderStorage
{
public List<OrderViewModel> GetFullList()
{
using var Context = new AutoWorkshopDatabase();
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 AutoWorkshopDatabase();
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 null;
using var Context = new AutoWorkshopDatabase();
return Context.Orders
.Include(x => x.Repair)
.FirstOrDefault(x => Model.Id.HasValue && x.Id == Model.Id)?
.GetViewModel;
}
public OrderViewModel? Insert(OrderBindingModel Model)
{
if (Model == null)
return null;
var NewOrder = Order.Create(Model);
if (NewOrder == null)
return null;
using var Context = new AutoWorkshopDatabase();
Context.Orders.Add(NewOrder);
Context.SaveChanges();
return Context.Orders.Include(x => x.Repair).FirstOrDefault(x => x.Id == NewOrder.Id)?.GetViewModel;
}
public OrderViewModel? Update(OrderBindingModel Model)
{
using var Context = new AutoWorkshopDatabase();
var Order = Context.Orders.FirstOrDefault(x => x.Id == Model.Id);
if (Order == null)
return null;
Order.Update(Model);
Context.SaveChanges();
return Context.Orders.Include(x => x.Repair).FirstOrDefault(x => x.Id == Model.Id)?.GetViewModel;
}
public OrderViewModel? Delete(OrderBindingModel Model)
{
using var Context = new AutoWorkshopDatabase();
var Order = Context.Orders.FirstOrDefault(rec => rec.Id == Model.Id);
if (Order == null)
return null;
Context.Orders.Remove(Order);
Context.SaveChanges();
return Order.GetViewModel;
}
}
}

View File

@ -0,0 +1,109 @@
using AutoWorkshopContracts.BindingModels;
using AutoWorkshopContracts.SearchModels;
using AutoWorkshopContracts.StoragesContracts;
using AutoWorkshopContracts.ViewModels;
using AutoWorkshopDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace AutoWorkshopDatabaseImplement.Implements
{
public class RepairStorage : IRepairStorage
{
public List<RepairViewModel> GetFullList()
{
using var Context = new AutoWorkshopDatabase();
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 AutoWorkshopDatabase();
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 AutoWorkshopDatabase();
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 AutoWorkshopDatabase();
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 AutoWorkshopDatabase();
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 AutoWorkshopDatabase();
var Repair = Context.Repairs
.Include(x => x.Components)
.FirstOrDefault(rec => rec.Id == Model.Id);
if (Repair == null)
return null;
Context.Repairs.Remove(Repair);
Context.SaveChanges();
return Repair.GetViewModel;
}
}
}

View File

@ -0,0 +1,171 @@
// <auto-generated />
using System;
using AutoWorkshopDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace AutoWorkshopDatabaseImplement.Migrations
{
[DbContext(typeof(AutoWorkshopDatabase))]
[Migration("20240504064327_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.17")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("AutoWorkshopDatabaseImplement.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("AutoWorkshopDatabaseImplement.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("AutoWorkshopDatabaseImplement.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("AutoWorkshopDatabaseImplement.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("AutoWorkshopDatabaseImplement.Models.Order", b =>
{
b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair")
.WithMany("Orders")
.HasForeignKey("RepairId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Repair");
});
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.RepairComponent", b =>
{
b.HasOne("AutoWorkshopDatabaseImplement.Models.Component", "Component")
.WithMany("RepairComponents")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair")
.WithMany("Components")
.HasForeignKey("RepairId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Repair");
});
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Component", b =>
{
b.Navigation("RepairComponents");
});
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Repair", b =>
{
b.Navigation("Components");
b.Navigation("Orders");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,126 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace AutoWorkshopDatabaseImplement.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");
}
}
}

View File

@ -0,0 +1,168 @@
// <auto-generated />
using System;
using AutoWorkshopDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace AutoWorkshopDatabaseImplement.Migrations
{
[DbContext(typeof(AutoWorkshopDatabase))]
partial class AutoWorkshopDatabaseModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.17")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("AutoWorkshopDatabaseImplement.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("AutoWorkshopDatabaseImplement.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("AutoWorkshopDatabaseImplement.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("AutoWorkshopDatabaseImplement.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("AutoWorkshopDatabaseImplement.Models.Order", b =>
{
b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair")
.WithMany("Orders")
.HasForeignKey("RepairId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Repair");
});
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.RepairComponent", b =>
{
b.HasOne("AutoWorkshopDatabaseImplement.Models.Component", "Component")
.WithMany("RepairComponents")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair")
.WithMany("Components")
.HasForeignKey("RepairId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Repair");
});
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Component", b =>
{
b.Navigation("RepairComponents");
});
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Repair", b =>
{
b.Navigation("Components");
b.Navigation("Orders");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,61 @@
using AutoWorkshopContracts.BindingModels;
using AutoWorkshopContracts.ViewModels;
using AutoWorkshopDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace AutoWorkshopDatabaseImplement.Models
{
public class Component : IComponentModel
{
public int Id { get; private set; }
[Required]
public string ComponentName { get; private set; } = string.Empty;
[Required]
public double Cost { get; set; }
[ForeignKey("ComponentId")]
public virtual List<RepairComponent> RepairComponents { get; set; } = new();
public static Component? Create(ComponentBindingModel Model)
{
if (Model == null)
return null;
return new Component()
{
Id = Model.Id,
ComponentName = Model.ComponentName,
Cost = Model.Cost
};
}
public static Component Create(ComponentViewModel Model)
{
return new Component
{
Id = Model.Id,
ComponentName = Model.ComponentName,
Cost = Model.Cost
};
}
public void Update(ComponentBindingModel Model)
{
if (Model == null)
return;
ComponentName = Model.ComponentName;
Cost = Model.Cost;
}
public ComponentViewModel GetViewModel => new()
{
Id = Id,
ComponentName = ComponentName,
Cost = Cost
};
}
}

View File

@ -0,0 +1,70 @@
using AutoWorkshopContracts.BindingModels;
using AutoWorkshopContracts.ViewModels;
using AutoWorkshopDataModels.Enums;
using AutoWorkshopDataModels.Models;
using System.ComponentModel.DataAnnotations;
namespace AutoWorkshopDatabaseImplement.Models
{
public class Order : IOrderModel
{
public int Id { get; private set; }
[Required]
public int RepairId { get; private set; }
public virtual Repair Repair { get; set; }
[Required]
public int Count { get; private set; }
[Required]
public double Sum { get; private set; }
[Required]
public OrderStatus Status { get; private set; } = OrderStatus.Undefined;
[Required]
public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime? DateImplement { get; private set; }
public static Order? Create(OrderBindingModel Model)
{
if (Model is 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,
};
}
public void Update(OrderBindingModel Model)
{
if (Model is null)
return;
Status = Model.Status;
DateImplement = Model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
RepairId = RepairId,
RepairName = Repair.RepairName,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
};
}
}

View File

@ -0,0 +1,106 @@
using AutoWorkshopContracts.BindingModels;
using AutoWorkshopContracts.ViewModels;
using AutoWorkshopDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace AutoWorkshopDatabaseImplement.Models
{
public class Repair : IRepairModel
{
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
{
if (_repairComponents == null)
{
_repairComponents = Components.ToDictionary(RepComp => RepComp.ComponentId, RepComp =>
(RepComp.Component as IComponentModel, RepComp.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(AutoWorkshopDatabase Context, RepairBindingModel Model)
{
return new Repair()
{
Id = Model.Id,
RepairName = Model.RepairName,
Price = Model.Price,
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)
{
RepairName = Model.RepairName;
Price = Model.Price;
}
public RepairViewModel GetViewModel => new()
{
Id = Id,
RepairName = RepairName,
Price = Price,
RepairComponents = RepairComponents
};
public void UpdateComponents(AutoWorkshopDatabase 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 ComponentToUpdate in RepairComponents)
{
ComponentToUpdate.Count = Model.RepairComponents[ComponentToUpdate.ComponentId].Item2;
Model.RepairComponents.Remove(ComponentToUpdate.ComponentId);
}
Context.SaveChanges();
}
var Repair = Context.Repairs.First(x => x.Id == Id);
foreach (var RepairComponent in Model.RepairComponents)
{
Context.RepairComponents.Add(new RepairComponent
{
Repair = Repair,
Component = Context.Components.First(x => x.Id == RepairComponent.Key),
Count = RepairComponent.Value.Item2
});
Context.SaveChanges();
}
_repairComponents = null;
}
}
}

View File

@ -0,0 +1,22 @@
using System.ComponentModel.DataAnnotations;
namespace AutoWorkshopDatabaseImplement.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();
}
}

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

View File

@ -10,8 +10,11 @@
<ItemGroup>
<ProjectReference Include="..\AutoWorkshopBusinessLogic\AutoWorkshopBusinessLogic.csproj" />
<ProjectReference Include="..\AutoWorkshopFileImplement\AutoWorkshopFileImplement.csproj" />
<ProjectReference Include="..\AutoWorkshopImplement\AutoWorkshopListImplement.csproj" />
<ProjectReference Include="..\AutoWorkshopDatabaseImplement\AutoWorkshopDatabaseImplement.csproj" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.17">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="NLog" Version="5.2.8" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />

View File

@ -49,7 +49,7 @@
MenuStrip.Location = new Point(0, 0);
MenuStrip.Name = "MenuStrip";
MenuStrip.Padding = new Padding(5, 2, 0, 2);
MenuStrip.Size = new Size(947, 24);
MenuStrip.Size = new Size(1134, 24);
MenuStrip.TabIndex = 0;
MenuStrip.Text = "TopMenuStrip";
//
@ -81,15 +81,15 @@
DataGridView.Margin = new Padding(3, 2, 3, 2);
DataGridView.Name = "DataGridView";
DataGridView.RowHeadersWidth = 51;
DataGridView.Size = new Size(770, 305);
DataGridView.Size = new Size(881, 305);
DataGridView.TabIndex = 1;
//
// CreateOrderButton
//
CreateOrderButton.Location = new Point(786, 23);
CreateOrderButton.Location = new Point(897, 23);
CreateOrderButton.Margin = new Padding(3, 2, 3, 2);
CreateOrderButton.Name = "CreateOrderButton";
CreateOrderButton.Size = new Size(157, 30);
CreateOrderButton.Size = new Size(227, 30);
CreateOrderButton.TabIndex = 2;
CreateOrderButton.Text = "Создать заказ";
CreateOrderButton.UseVisualStyleBackColor = true;
@ -97,10 +97,10 @@
//
// TakeInWorkButton
//
TakeInWorkButton.Location = new Point(786, 57);
TakeInWorkButton.Location = new Point(897, 57);
TakeInWorkButton.Margin = new Padding(3, 2, 3, 2);
TakeInWorkButton.Name = "TakeInWorkButton";
TakeInWorkButton.Size = new Size(157, 30);
TakeInWorkButton.Size = new Size(227, 30);
TakeInWorkButton.TabIndex = 3;
TakeInWorkButton.Text = "Отдать заказ в работу";
TakeInWorkButton.UseVisualStyleBackColor = true;
@ -108,10 +108,10 @@
//
// ReadyButton
//
ReadyButton.Location = new Point(786, 91);
ReadyButton.Location = new Point(897, 91);
ReadyButton.Margin = new Padding(3, 2, 3, 2);
ReadyButton.Name = "ReadyButton";
ReadyButton.Size = new Size(157, 30);
ReadyButton.Size = new Size(227, 30);
ReadyButton.TabIndex = 4;
ReadyButton.Text = "Заказ готов";
ReadyButton.UseVisualStyleBackColor = true;
@ -119,10 +119,10 @@
//
// IssuedButton
//
IssuedButton.Location = new Point(786, 125);
IssuedButton.Location = new Point(897, 125);
IssuedButton.Margin = new Padding(3, 2, 3, 2);
IssuedButton.Name = "IssuedButton";
IssuedButton.Size = new Size(157, 30);
IssuedButton.Size = new Size(227, 30);
IssuedButton.TabIndex = 5;
IssuedButton.Text = "Заказ выдан";
IssuedButton.UseVisualStyleBackColor = true;
@ -130,10 +130,10 @@
//
// RefreshButton
//
RefreshButton.Location = new Point(786, 159);
RefreshButton.Location = new Point(897, 159);
RefreshButton.Margin = new Padding(3, 2, 3, 2);
RefreshButton.Name = "RefreshButton";
RefreshButton.Size = new Size(157, 30);
RefreshButton.Size = new Size(227, 30);
RefreshButton.TabIndex = 6;
RefreshButton.Text = "Обновить";
RefreshButton.UseVisualStyleBackColor = true;
@ -143,7 +143,7 @@
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(947, 338);
ClientSize = new Size(1134, 338);
Controls.Add(RefreshButton);
Controls.Add(IssuedButton);
Controls.Add(ReadyButton);

View File

@ -1,7 +1,7 @@
using AutoWorkshopBusinessLogic.BusinessLogics;
using AutoWorkshopContracts.BusinessLogicContracts;
using AutoWorkshopContracts.StoragesContracts;
using AutoWorkshopFileImplement.Implements;
using AutoWorkshopDatabaseImplement.Implements;
using AutoWorkshopView.Forms;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;