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" /> <ProjectReference Include="..\CarRepairShopDataModels\CarRepairShopDataModels.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Migrations\" />
</ItemGroup>
</Project> </Project>

View File

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

View File

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

View File

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

View File

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