This commit is contained in:
Yunusov_Niyaz 2024-03-24 21:23:30 +04:00
parent fc20462d0a
commit 818f6791d9
6 changed files with 13 additions and 10 deletions

View File

@ -20,8 +20,4 @@
<ProjectReference Include="..\CarRepairShopDataModels\CarRepairShopDataModels.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Migrations\" />
</ItemGroup>
</Project>

View File

@ -3,6 +3,7 @@ using CarRepairShopContracts.SearchModels;
using CarRepairShopContracts.StoragesContracts;
using CarRepairShopContracts.ViewModels;
using CarRepairShopDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace CarRepairShopDatabaseImplement.Implements
{
@ -11,7 +12,7 @@ namespace CarRepairShopDatabaseImplement.Implements
public List<OrderViewModel> GetFullList()
{
using var context = new RepairsShopDatabase();
return context.Orders
return context.Orders.Include(x => x.Repair)
.Select(x => x.GetViewModel)
.ToList();
}

View File

@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace CarRepairShopDatabaseImplement.Migrations
{
[DbContext(typeof(RepairsShopDatabase))]
[Migration("20240312202857_InitialCreate")]
[Migration("20240324163100_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
@ -126,11 +126,13 @@ namespace CarRepairShopDatabaseImplement.Migrations
modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Order", b =>
{
b.HasOne("CarRepairShopDatabaseImplement.Models.Repair", null)
b.HasOne("CarRepairShopDatabaseImplement.Models.Repair", "Repair")
.WithMany("Orders")
.HasForeignKey("RepairId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Repair");
});
modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.RepairComponent", b =>

View File

@ -1,13 +1,17 @@
// <auto-generated />
using System;
using CarRepairShopDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace CarRepairShopDatabaseImplement.Migrations
{
[DbContext(typeof(RepairsShopDatabase))]
partial class CarRepairShopDatabaseModelSnapshot : ModelSnapshot
partial class RepairsShopDatabaseModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
@ -124,6 +128,7 @@ namespace CarRepairShopDatabaseImplement.Migrations
.HasForeignKey("RepairId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Repair");
});

View File

@ -21,7 +21,7 @@ namespace CarRepairShopDatabaseImplement.Models
public int RepairId { get; private set; }
public virtual Repair Repair { get; set; } = new();
public static Order? Create(RepairsShopDatabase context, OrderBindingModel model)
public static Order? Create(OrderBindingModel model)
{
return new Order()
{
@ -32,7 +32,6 @@ namespace CarRepairShopDatabaseImplement.Models
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
RepairId = model.RepairId,
Repair = context.Repairs.FirstOrDefault(x => x.Id == model.RepairId)
};
}