diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ComponentStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ComponentStorage.cs index 619b9ad..41c1342 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ComponentStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ComponentStorage.cs @@ -17,8 +17,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements { using var context = new BlacksmithWorkshopDataBase(); return context.Components - .Select(x => x.GetViewModel) - .ToList(); + .Select(x => x.GetViewModel) + .ToList(); } public List GetFilteredList(ComponentSearchModel model) @@ -29,9 +29,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements } using var context = new BlacksmithWorkshopDataBase(); return context.Components - .Where(x => x.ComponentName.Contains(model.ComponentName)) - .Select(x => x.GetViewModel) - .ToList(); + .Where(x => x.ComponentName.Contains(model.ComponentName)) + .Select(x => x.GetViewModel) + .ToList(); } public ComponentViewModel? GetElement(ComponentSearchModel model) { @@ -41,11 +41,11 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements } using var context = new BlacksmithWorkshopDataBase(); return context.Components - .FirstOrDefault(x => - (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == - model.ComponentName) || - (model.Id.HasValue && x.Id == model.Id)) - ?.GetViewModel; + .FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == + model.ComponentName) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; } public ComponentViewModel? Insert(ComponentBindingModel model) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ManufactureStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ManufactureStorage.cs index 1cffc12..4bd25fa 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ManufactureStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ManufactureStorage.cs @@ -18,11 +18,11 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements { using var context = new BlacksmithWorkshopDataBase(); return context.Manufactures - .Include(x => x.Components) - .ThenInclude(x => x.Component) - .ToList() - .Select(x => x.GetViewModel) - .ToList(); + .Include(x => x.Components) + .ThenInclude(x => x.Component) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); } public List GetFilteredList(ManufactureSearchModel model) { @@ -32,11 +32,11 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements } using var context = new BlacksmithWorkshopDataBase(); return context.Manufactures.Include(x => x.Components) - .ThenInclude(x => x.Component) - .Where(x => x.ManufactureName.Contains(model.ManufactureName)) - .ToList() - .Select(x => x.GetViewModel) - .ToList(); + .ThenInclude(x => x.Component) + .Where(x => x.ManufactureName.Contains(model.ManufactureName)) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); } public ManufactureViewModel? GetElement(ManufactureSearchModel model) { @@ -47,9 +47,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements } using var context = new BlacksmithWorkshopDataBase(); return context.Manufactures - .Include(x => x.Components) - .ThenInclude(x => x.Component) - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ManufactureName) && + .Include(x => x.Components) + .ThenInclude(x => x.Component) + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ManufactureName) && x.ManufactureName == model.ManufactureName) || (model.Id.HasValue && x.Id == model.Id)) @@ -95,8 +95,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements { using var context = new BlacksmithWorkshopDataBase(); var element = context.Manufactures - .Include(x => x.Components) - .FirstOrDefault(rec => rec.Id == model.Id); + .Include(x => x.Components) + .FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Manufactures.Remove(element); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs index d2383c0..f489a4e 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs @@ -3,6 +3,7 @@ using BlacksmithWorkshopContracts.SearchModels; using BlacksmithWorkshopContracts.StoragesContracts; using BlacksmithWorkshopContracts.ViewModels; using BlacksmithWorkshopDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; @@ -17,8 +18,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements { using var context = new BlacksmithWorkshopDataBase(); return context.Orders - .Select(x => x.GetViewModel) - .ToList(); + .Include(x => x.Manufacture) + .Select(x => x.GetViewModel) + .ToList(); } public List GetFilteredList(OrderSearchModel model) { @@ -28,9 +30,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements } using var context = new BlacksmithWorkshopDataBase(); return context.Orders - .Where(x => x.Id == model.Id) - .Select(x => x.GetViewModel) - .ToList(); + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); } public OrderViewModel? GetElement(OrderSearchModel model) { @@ -44,7 +46,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements public OrderViewModel? Insert(OrderBindingModel model) { using var context = new BlacksmithWorkshopDataBase(); - var newOrder = Order.Create(context, model); + var newOrder = Order.Create(model); if (newOrder == null) { return null; diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240313061254_InitialCreate.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.Designer.cs similarity index 97% rename from BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240313061254_InitialCreate.Designer.cs rename to BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.Designer.cs index eafb33a..1629012 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240313061254_InitialCreate.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace BlacksmithWorkshopDatabaseImplement.Migrations { [DbContext(typeof(BlacksmithWorkshopDataBase))] - [Migration("20240313061254_InitialCreate")] + [Migration("20240324164611_InitialCreate")] partial class InitialCreate { /// @@ -145,11 +145,13 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => { - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", null) + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") .WithMany("Orders") .HasForeignKey("ManufactureId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + + b.Navigation("Manufacture"); }); modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240313061254_InitialCreate.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.cs similarity index 100% rename from BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240313061254_InitialCreate.cs rename to BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240324164611_InitialCreate.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs index ca4928d..e3ce109 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs @@ -142,11 +142,13 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => { - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", null) + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") .WithMany("Orders") .HasForeignKey("ManufactureId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + + b.Navigation("Manufacture"); }); modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs index bfa8c1e..8a5b48d 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs @@ -27,7 +27,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Models public int ManufactureId { get; private set; } public virtual Manufacture Manufacture { get; set; } = new(); - public static Order? Create(BlacksmithWorkshopDataBase context, OrderBindingModel model) + public static Order? Create(OrderBindingModel model) { return new Order() { @@ -38,7 +38,6 @@ namespace BlacksmithWorkshopDatabaseImplement.Models DateCreate = model.DateCreate, DateImplement = model.DateImplement, ManufactureId = model.ManufactureId, - Manufacture = context.Manufactures.First(y => y.Id == model.ManufactureId) }; } public void Update(OrderBindingModel? model)