From ac8a0e4602fa75a525e146c9190025a537b918a2 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sun, 26 Feb 2023 20:20:41 +0400 Subject: [PATCH 1/7] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=20?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D1=8B=D0=B9=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA?= =?UTF-8?q?=D1=82,=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D0=B8=20=D0=B2=20?= =?UTF-8?q?=D0=BD=D0=B5=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FurnitureAssembly/FurnitureAssembly.sln | 8 +- .../FurnitureAssembly.csproj | 4 + .../FurnitureAssemblyDatabaseImplement.csproj | 27 +++++ .../Models/Component.cs | 58 +++++++++++ .../Models/Furniture.cs | 98 +++++++++++++++++++ .../Models/FurnitureComponent.cs | 23 +++++ .../Models/Order.cs | 94 ++++++++++++++++++ 7 files changed, 311 insertions(+), 1 deletion(-) create mode 100644 FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabaseImplement.csproj create mode 100644 FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Component.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/FurnitureComponent.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Order.cs diff --git a/FurnitureAssembly/FurnitureAssembly.sln b/FurnitureAssembly/FurnitureAssembly.sln index 51e7896..2b753c4 100644 --- a/FurnitureAssembly/FurnitureAssembly.sln +++ b/FurnitureAssembly/FurnitureAssembly.sln @@ -13,7 +13,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemblyBusinessLo EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemblyListImplement", "FurnitureAssemblyListImplement\FurnitureAssemblyListImplement.csproj", "{6662252C-A676-4376-AA01-0ACC6AE5B217}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FurnitureAssemFileImplement", "FurnitureAssemFileImplement\FurnitureAssemFileImplement.csproj", "{A6822E0E-DBF3-4DEA-A337-C6C64429C0DE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemFileImplement", "FurnitureAssemFileImplement\FurnitureAssemFileImplement.csproj", "{A6822E0E-DBF3-4DEA-A337-C6C64429C0DE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FurnitureAssemblyDatabaseImplement", "FurnitureAssemblyDatabaseImplement\FurnitureAssemblyDatabaseImplement.csproj", "{F4FAEBEF-1E02-44DE-A13B-27A8C3838D98}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -45,6 +47,10 @@ Global {A6822E0E-DBF3-4DEA-A337-C6C64429C0DE}.Debug|Any CPU.Build.0 = Debug|Any CPU {A6822E0E-DBF3-4DEA-A337-C6C64429C0DE}.Release|Any CPU.ActiveCfg = Release|Any CPU {A6822E0E-DBF3-4DEA-A337-C6C64429C0DE}.Release|Any CPU.Build.0 = Release|Any CPU + {F4FAEBEF-1E02-44DE-A13B-27A8C3838D98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F4FAEBEF-1E02-44DE-A13B-27A8C3838D98}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F4FAEBEF-1E02-44DE-A13B-27A8C3838D98}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F4FAEBEF-1E02-44DE-A13B-27A8C3838D98}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/FurnitureAssembly/FurnitureAssembly/FurnitureAssembly.csproj b/FurnitureAssembly/FurnitureAssembly/FurnitureAssembly.csproj index 45d0618..1fab66c 100644 --- a/FurnitureAssembly/FurnitureAssembly/FurnitureAssembly.csproj +++ b/FurnitureAssembly/FurnitureAssembly/FurnitureAssembly.csproj @@ -19,6 +19,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabaseImplement.csproj b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabaseImplement.csproj new file mode 100644 index 0000000..45fec34 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabaseImplement.csproj @@ -0,0 +1,27 @@ + + + + net6.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Component.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Component.cs new file mode 100644 index 0000000..1ec3c8a --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Component.cs @@ -0,0 +1,58 @@ + +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDataModels.Models; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; + +namespace FurnitureAssemblyDatabaseImplement.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 FurnitureComponents { 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 + }; + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs new file mode 100644 index 0000000..9856be4 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs @@ -0,0 +1,98 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyDatabaseImplement.Models +{ + public class Furniture : IFurnitureModel + { + public int Id { get; set; } + [Required] + public string FurnitureName { get; set; } = string.Empty; + [Required] + public double Price { get; set; } + private Dictionary? _furnitureComponents = null; + [NotMapped] + public Dictionary FurnitureComponents + { + get + { + if (_furnitureComponents == null) + { + _furnitureComponents = Components + .ToDictionary(recPC => recPC.ComponentId, recPC => + (recPC.Component as IComponentModel, recPC.Count)); + } + return _furnitureComponents; + } + } + [ForeignKey("FurnitureId")] + public virtual List Components { get; set; } = new(); + [ForeignKey("FurnitureId")] + public virtual List Orders { get; set; } = new(); + public static Furniture Create(FurnitureAssemblyDatabase context, FurnitureBindingModel model) + { + return new Furniture() + { + Id = model.Id, + FurnitureName = model.FurnitureName, + Price = model.Price, + Components = model.FurnitureComponents.Select(x => new FurnitureComponent + { + Component = context.Components.First(y => y.Id == x.Key), + Count = x.Value.Item2 + }).ToList() + }; + } + public void Update(FurnitureBindingModel model) + { + FurnitureName = model.FurnitureName; + Price = model.Price; + } + public FurnitureViewModel GetViewModel => new() + { + Id = Id, + FurnitureName = FurnitureName, + Price = Price, + FurnitureComponents = FurnitureComponents + }; + + public void UpdateComponents(FurnitureAssemblyDatabase context, FurnitureBindingModel model) + { + var furnitureComponents = context.FurnitureComponents.Where(rec => rec.ProductId == model.Id).ToList(); + if (furnitureComponents != null && furnitureComponents.Count > 0) + { // удалили те, которых нет в модели + context.ProductComponents.RemoveRange(furnitureComponents.Where(rec + => !model.FurnitureComponents.ContainsKey(rec.ComponentId))); + context.SaveChanges(); + // обновили количество у существующих записей + foreach (var updateComponent in furnitureComponents) + { + updateComponent.Count = model.FurnitureComponents[updateComponent.ComponentId].Item2; + model.FurnitureComponents.Remove(updateComponent.ComponentId); + } + context.SaveChanges(); + } + var furniture = context.Furnitures.First(x => x.Id == Id); + foreach (var pc in model.FurnitureComponents) + { + context.ProductComponents.Add(new FurnitureComponent + { + Furniture = furniture, + Component = context.Components.First(x => x.Id == pc.Key), + Count = pc.Value.Item2 + }); + context.SaveChanges(); + } + _furnitureComponents = null; + } + + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/FurnitureComponent.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/FurnitureComponent.cs new file mode 100644 index 0000000..fe41e6d --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/FurnitureComponent.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyDatabaseImplement.Models +{ + public class FurnitureComponent + { + public int Id { get; set; } + [Required] + public int ProductId { get; set; } + [Required] + public int ComponentId { get; set; } + + [Required] + public int Count { get; set; } + public virtual Component Component { get; set; } = new(); + public virtual Furniture Furniture { get; set; } = new(); + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Order.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Order.cs new file mode 100644 index 0000000..eae01c2 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Order.cs @@ -0,0 +1,94 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDataModels.Enums; +using FurnitureAssemblyDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyDatabaseImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + [Required] + public int FurnitureId { get; private set; } + public string FurnitureName { get; private set; } = string.Empty; + [Required] + public int Count { get; private set; } + [Required] + public double Sum { get; private set; } + [Required] + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + [Required] + public DateTime DateCreate { get; private set; } = DateTime.Now; + + public DateTime? DateImplement { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + FurnitureId = model.FurnitureId, + FurnitureName = model.FurnitureName, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + + public static Order Create(OrderViewModel model) + { + return new Order + { + Id = model.Id, + FurnitureId = model.FurnitureId, + FurnitureName = model.FurnitureName, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + + public void Update(OrderBindingModel model) + { + if (model == null) + { + return; + } + FurnitureId = model.FurnitureId; + FurnitureName = model.FurnitureName; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + FurnitureId = FurnitureId, + FurnitureName = FurnitureName, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + + } +} -- 2.25.1 From 9cc2836618c43436a45b250b4510385a219f3d01 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sun, 26 Feb 2023 22:01:55 +0400 Subject: [PATCH 2/7] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D0=B8?= =?UTF-8?q?=20=D0=B8=D0=B7=D0=B4=D0=B5=D0=BB=D0=B8=D1=8F,=20=D1=81=D0=BE?= =?UTF-8?q?=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81?= =?UTF-8?q?=D1=81=D0=B0=20=D1=81=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8=D1=86?= =?UTF-8?q?=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FurnitureAssemblyDatabase.cs | 26 +++++++++++++++++++ .../FurnitureAssemblyDatabaseImplement.csproj | 4 --- .../Models/Furniture.cs | 4 +-- 3 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabase.cs diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabase.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabase.cs new file mode 100644 index 0000000..a0ce249 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabase.cs @@ -0,0 +1,26 @@ +using FurnitureAssemblyDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyDatabaseImplement +{ + public class FurnitureAssemblyDatabase : DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (optionsBuilder.IsConfigured == false) + { + optionsBuilder.UseSqlServer(@"Data Source=zhu\SQLEXPRESS;Initial Catalog=FurnitureAssemblyDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + } + base.OnConfiguring(optionsBuilder); + } + public virtual DbSet Components { set; get; } + public virtual DbSet Furnitures { set; get; } + public virtual DbSet FurnitureComponents { set; get; } + public virtual DbSet Orders { set; get; } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabaseImplement.csproj b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabaseImplement.csproj index 45fec34..a46e4e9 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabaseImplement.csproj +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabaseImplement.csproj @@ -20,8 +20,4 @@ - - - - diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs index 9856be4..3e7fa61 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs @@ -69,7 +69,7 @@ namespace FurnitureAssemblyDatabaseImplement.Models var furnitureComponents = context.FurnitureComponents.Where(rec => rec.ProductId == model.Id).ToList(); if (furnitureComponents != null && furnitureComponents.Count > 0) { // удалили те, которых нет в модели - context.ProductComponents.RemoveRange(furnitureComponents.Where(rec + context.FurnitureComponents.RemoveRange(furnitureComponents.Where(rec => !model.FurnitureComponents.ContainsKey(rec.ComponentId))); context.SaveChanges(); // обновили количество у существующих записей @@ -83,7 +83,7 @@ namespace FurnitureAssemblyDatabaseImplement.Models var furniture = context.Furnitures.First(x => x.Id == Id); foreach (var pc in model.FurnitureComponents) { - context.ProductComponents.Add(new FurnitureComponent + context.FurnitureComponents.Add(new FurnitureComponent { Furniture = furniture, Component = context.Components.First(x => x.Id == pc.Key), -- 2.25.1 From 829d77a46675e87750b7a4b3093b9bb51c9a1818 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sun, 26 Feb 2023 22:02:14 +0400 Subject: [PATCH 3/7] =?UTF-8?q?=D0=9C=D0=B8=D0=B3=D1=80=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B8=20=D0=B8=20=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D0=B8=20=D1=85=D1=80=D0=B0=D0=BD=D0=B8=D0=BB=D0=B8?= =?UTF-8?q?=D1=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/ComponentStorage.cs | 91 +++++++++ .../Implements/FurnitureStorage.cs | 114 ++++++++++++ .../Implements/OrderStorage.cs | 90 +++++++++ .../20230226173756_InitialCreate.Designer.cs | 176 ++++++++++++++++++ .../20230226173756_InitialCreate.cs | 127 +++++++++++++ .../FurnitureAssemblyDatabaseModelSnapshot.cs | 173 +++++++++++++++++ 6 files changed, 771 insertions(+) create mode 100644 FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/ComponentStorage.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/FurnitureStorage.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/OrderStorage.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20230226173756_InitialCreate.Designer.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20230226173756_InitialCreate.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/ComponentStorage.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..3ca6374 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/ComponentStorage.cs @@ -0,0 +1,91 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.StoragesContracts; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyDatabaseImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + public List GetFullList() + { + using var context = new FurnitureAssemblyDatabase(); + return context.Components + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(ComponentSearchModel + model) + { + if (string.IsNullOrEmpty(model.ComponentName)) + { + return new(); + } + using var context = new FurnitureAssemblyDatabase(); + 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 FurnitureAssemblyDatabase(); + 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 FurnitureAssemblyDatabase(); + context.Components.Add(newComponent); + context.SaveChanges(); + return newComponent.GetViewModel; + } + + public ComponentViewModel? Update(ComponentBindingModel model) + { + using var context = new FurnitureAssemblyDatabase(); + 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 FurnitureAssemblyDatabase(); + var element = context.Components.FirstOrDefault(rec => rec.Id == + model.Id); + if (element != null) + { + context.Components.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/FurnitureStorage.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/FurnitureStorage.cs new file mode 100644 index 0000000..0a4ce41 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/FurnitureStorage.cs @@ -0,0 +1,114 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.StoragesContracts; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyDatabaseImplement.Implements +{ + public class FurnitureStorage : IFurnitureStorage + { + public List GetFullList() + { + using var context = new FurnitureAssemblyDatabase(); + return context.Furnitures + .Include(x => x.Components) + .ThenInclude(x => x.Component) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(FurnitureSearchModel model) + { + if (string.IsNullOrEmpty(model.FurnitureName)) + { + return new(); + } + using var context = new FurnitureAssemblyDatabase(); + return context.Furnitures + .Include(x => x.Components) + .ThenInclude(x => x.Component) + .Where(x => x.FurnitureName.Contains(model.FurnitureName)) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public FurnitureViewModel? GetElement(FurnitureSearchModel model) + { + if (string.IsNullOrEmpty(model.FurnitureName) && + !model.Id.HasValue) + { + return null; + } + using var context = new FurnitureAssemblyDatabase(); + return context.Furnitures + .Include(x => x.Components) + .ThenInclude(x => x.Component) + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.FurnitureName) && + x.FurnitureName == model.FurnitureName) || + (model.Id.HasValue && x.Id == + model.Id)) + ?.GetViewModel; + } + public FurnitureViewModel? Insert(FurnitureBindingModel model) + { + using var context = new FurnitureAssemblyDatabase(); + var newProduct = Furniture.Create(context, model); + if (newProduct == null) + { + return null; + } + context.Furnitures.Add(newProduct); + context.SaveChanges(); + return newProduct.GetViewModel; + } + public FurnitureViewModel? Update(FurnitureBindingModel model) + { + using var context = new FurnitureAssemblyDatabase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var product = context.Furnitures.FirstOrDefault(rec => + rec.Id == model.Id); + if (product == null) + { + return null; + } + product.Update(model); + context.SaveChanges(); + product.UpdateComponents(context, model); + transaction.Commit(); + return product.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + public FurnitureViewModel? Delete(FurnitureBindingModel model) + { + using var context = new FurnitureAssemblyDatabase(); + var element = context.Furnitures.Include(x => x.Components) + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Furnitures.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + + + + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/OrderStorage.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..7995847 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/OrderStorage.cs @@ -0,0 +1,90 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.StoragesContracts; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyDatabaseImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + using var context = new FurnitureAssemblyDatabase(); + return context.Orders.FirstOrDefault(x => + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public List GetFilteredList(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + using var context = new FurnitureAssemblyDatabase(); + return context.Orders + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + using var context = new FurnitureAssemblyDatabase(); + return context.Orders + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + using var context = new FurnitureAssemblyDatabase(); + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + context.Orders.Add(newOrder); + context.SaveChanges(); + return newOrder.GetViewModel; + } + + public OrderViewModel? Update(OrderBindingModel model) + { + using var context = new FurnitureAssemblyDatabase(); + 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 FurnitureAssemblyDatabase(); + var order = context.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order != null) + { + context.Orders.Remove(order); + context.SaveChanges(); + return order.GetViewModel; + } + return null; + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20230226173756_InitialCreate.Designer.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20230226173756_InitialCreate.Designer.cs new file mode 100644 index 0000000..79ea606 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20230226173756_InitialCreate.Designer.cs @@ -0,0 +1,176 @@ +// +using System; +using FurnitureAssemblyDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace FurnitureAssemblyDatabaseImplement.Migrations +{ + [DbContext(typeof(FurnitureAssemblyDatabase))] + [Migration("20230226173756_InitialCreate")] + partial class InitialCreate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Furniture", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("FurnitureName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Furnitures"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.FurnitureComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("FurnitureId") + .HasColumnType("int"); + + b.Property("ProductId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("FurnitureId"); + + b.ToTable("FurnitureComponents"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("FurnitureId") + .HasColumnType("int"); + + b.Property("FurnitureName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("FurnitureId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.FurnitureComponent", b => + { + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Component", "Component") + .WithMany("FurnitureComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", "Furniture") + .WithMany("Components") + .HasForeignKey("FurnitureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Furniture"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Order", b => + { + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", null) + .WithMany("Orders") + .HasForeignKey("FurnitureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Component", b => + { + b.Navigation("FurnitureComponents"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Furniture", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20230226173756_InitialCreate.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20230226173756_InitialCreate.cs new file mode 100644 index 0000000..d491eb2 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20230226173756_InitialCreate.cs @@ -0,0 +1,127 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace FurnitureAssemblyDatabaseImplement.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Components", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ComponentName = table.Column(type: "nvarchar(max)", nullable: false), + Cost = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Components", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Furnitures", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + FurnitureName = table.Column(type: "nvarchar(max)", nullable: false), + Price = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Furnitures", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "FurnitureComponents", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ProductId = table.Column(type: "int", nullable: false), + ComponentId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false), + FurnitureId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_FurnitureComponents", x => x.Id); + table.ForeignKey( + name: "FK_FurnitureComponents_Components_ComponentId", + column: x => x.ComponentId, + principalTable: "Components", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_FurnitureComponents_Furnitures_FurnitureId", + column: x => x.FurnitureId, + principalTable: "Furnitures", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + FurnitureId = table.Column(type: "int", nullable: false), + FurnitureName = table.Column(type: "nvarchar(max)", nullable: false), + Count = table.Column(type: "int", nullable: false), + Sum = table.Column(type: "float", nullable: false), + Status = table.Column(type: "int", nullable: false), + DateCreate = table.Column(type: "datetime2", nullable: false), + DateImplement = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_Furnitures_FurnitureId", + column: x => x.FurnitureId, + principalTable: "Furnitures", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_FurnitureComponents_ComponentId", + table: "FurnitureComponents", + column: "ComponentId"); + + migrationBuilder.CreateIndex( + name: "IX_FurnitureComponents_FurnitureId", + table: "FurnitureComponents", + column: "FurnitureId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_FurnitureId", + table: "Orders", + column: "FurnitureId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "FurnitureComponents"); + + migrationBuilder.DropTable( + name: "Orders"); + + migrationBuilder.DropTable( + name: "Components"); + + migrationBuilder.DropTable( + name: "Furnitures"); + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs new file mode 100644 index 0000000..e36d46b --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs @@ -0,0 +1,173 @@ +// +using System; +using FurnitureAssemblyDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace FurnitureAssemblyDatabaseImplement.Migrations +{ + [DbContext(typeof(FurnitureAssemblyDatabase))] + partial class FurnitureAssemblyDatabaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Furniture", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("FurnitureName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Furnitures"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.FurnitureComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("FurnitureId") + .HasColumnType("int"); + + b.Property("ProductId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("FurnitureId"); + + b.ToTable("FurnitureComponents"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("FurnitureId") + .HasColumnType("int"); + + b.Property("FurnitureName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("FurnitureId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.FurnitureComponent", b => + { + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Component", "Component") + .WithMany("FurnitureComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", "Furniture") + .WithMany("Components") + .HasForeignKey("FurnitureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Furniture"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Order", b => + { + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", null) + .WithMany("Orders") + .HasForeignKey("FurnitureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Component", b => + { + b.Navigation("FurnitureComponents"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Furniture", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} -- 2.25.1 From 80b3b2208b82caff5b9e5954e9a3aa51944d3a88 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sun, 26 Feb 2023 22:02:26 +0400 Subject: [PATCH 4/7] =?UTF-8?q?=D0=9F=D0=BE=D1=81=D0=BB=D0=B5=D0=B4=D0=BD?= =?UTF-8?q?=D0=B8=D0=B9=20(=3F)=20=D1=88=D1=82=D1=80=D0=B8=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FurnitureAssembly/FurnitureAssembly/FurnitureAssembly.csproj | 1 + FurnitureAssembly/FurnitureAssembly/Program.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/FurnitureAssembly/FurnitureAssembly/FurnitureAssembly.csproj b/FurnitureAssembly/FurnitureAssembly/FurnitureAssembly.csproj index 1fab66c..6b9be89 100644 --- a/FurnitureAssembly/FurnitureAssembly/FurnitureAssembly.csproj +++ b/FurnitureAssembly/FurnitureAssembly/FurnitureAssembly.csproj @@ -31,6 +31,7 @@ + diff --git a/FurnitureAssembly/FurnitureAssembly/Program.cs b/FurnitureAssembly/FurnitureAssembly/Program.cs index bac7790..3058944 100644 --- a/FurnitureAssembly/FurnitureAssembly/Program.cs +++ b/FurnitureAssembly/FurnitureAssembly/Program.cs @@ -1,7 +1,7 @@ using FurnitureAssemblyBusinessLogic; using FurnitureAssemblyContracts.BusinessLogicsContarcts; using FurnitureAssemblyContracts.StoragesContracts; -using FurnitureAssemFileImplement.Implements; +using FurnitureAssemblyDatabaseImplement.Implements; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; -- 2.25.1 From 7649b1fa3bccd518d53e1ab1d63ea8b5e0bfb0ac Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sat, 11 Mar 2023 09:37:26 +0400 Subject: [PATCH 5/7] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/OrderStorage.cs | 22 ++- ...20230311052240_SecondMigration.Designer.cs | 174 ++++++++++++++++++ .../20230311052240_SecondMigration.cs | 29 +++ .../FurnitureAssemblyDatabaseModelSnapshot.cs | 8 +- .../Models/Order.cs | 13 +- 5 files changed, 227 insertions(+), 19 deletions(-) create mode 100644 FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20230311052240_SecondMigration.Designer.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20230311052240_SecondMigration.cs diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/OrderStorage.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/OrderStorage.cs index 7995847..d85ac24 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/OrderStorage.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/OrderStorage.cs @@ -3,6 +3,7 @@ using FurnitureAssemblyContracts.SearchModels; using FurnitureAssemblyContracts.StoragesContracts; using FurnitureAssemblyContracts.ViewModels; using FurnitureAssemblyDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; @@ -21,7 +22,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements return new(); } using var context = new FurnitureAssemblyDatabase(); - return context.Orders.FirstOrDefault(x => + return context.Orders.Include(x => x.Furniture).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)) ?.GetViewModel; } @@ -34,6 +35,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements } using var context = new FurnitureAssemblyDatabase(); return context.Orders + .Include(x => x.Furniture) .Where(x => x.Id == model.Id) .Select(x => x.GetViewModel) .ToList(); @@ -43,7 +45,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements { using var context = new FurnitureAssemblyDatabase(); return context.Orders - .ToList() + .Include(x => x.Furniture) .Select(x => x.GetViewModel) .ToList(); } @@ -58,7 +60,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements } context.Orders.Add(newOrder); context.SaveChanges(); - return newOrder.GetViewModel; + return context.Orders.Include(x => x.Furniture).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; } public OrderViewModel? Update(OrderBindingModel model) @@ -71,7 +73,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements } order.Update(model); context.SaveChanges(); - return order.GetViewModel; + return context.Orders.Include(x => x.Furniture).FirstOrDefault(x => x.Id == order.Id)?.GetViewModel; } public OrderViewModel? Delete(OrderBindingModel model) @@ -82,9 +84,19 @@ namespace FurnitureAssemblyDatabaseImplement.Implements { context.Orders.Remove(order); context.SaveChanges(); - return order.GetViewModel; + return context.Orders.Include(x => x.Furniture).FirstOrDefault(x => x.Id == order.Id)?.GetViewModel; } return null; } + + public OrderViewModel GetOrderViewModel(Order order) + { + var viewmodel = order.GetViewModel; + using var context = new FurnitureAssemblyDatabase(); + var furniture = context.Furnitures.FirstOrDefault(x => x.Id == order.FurnitureId); + if (furniture != null) + viewmodel.FurnitureName = furniture.FurnitureName; + return viewmodel; + } } } diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20230311052240_SecondMigration.Designer.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20230311052240_SecondMigration.Designer.cs new file mode 100644 index 0000000..1e60be2 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20230311052240_SecondMigration.Designer.cs @@ -0,0 +1,174 @@ +// +using System; +using FurnitureAssemblyDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace FurnitureAssemblyDatabaseImplement.Migrations +{ + [DbContext(typeof(FurnitureAssemblyDatabase))] + [Migration("20230311052240_SecondMigration")] + partial class SecondMigration + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Furniture", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("FurnitureName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Furnitures"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.FurnitureComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("FurnitureId") + .HasColumnType("int"); + + b.Property("ProductId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("FurnitureId"); + + b.ToTable("FurnitureComponents"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("FurnitureId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("FurnitureId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.FurnitureComponent", b => + { + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Component", "Component") + .WithMany("FurnitureComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", "Furniture") + .WithMany("Components") + .HasForeignKey("FurnitureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Furniture"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Order", b => + { + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", "Furniture") + .WithMany("Orders") + .HasForeignKey("FurnitureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Furniture"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Component", b => + { + b.Navigation("FurnitureComponents"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Furniture", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20230311052240_SecondMigration.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20230311052240_SecondMigration.cs new file mode 100644 index 0000000..ad2f158 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20230311052240_SecondMigration.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace FurnitureAssemblyDatabaseImplement.Migrations +{ + /// + public partial class SecondMigration : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "FurnitureName", + table: "Orders"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "FurnitureName", + table: "Orders", + type: "nvarchar(max)", + nullable: false, + defaultValue: ""); + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs index e36d46b..e24f216 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs @@ -111,10 +111,6 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations b.Property("FurnitureId") .HasColumnType("int"); - b.Property("FurnitureName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - b.Property("Status") .HasColumnType("int"); @@ -149,11 +145,13 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Order", b => { - b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", null) + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", "Furniture") .WithMany("Orders") .HasForeignKey("FurnitureId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + + b.Navigation("Furniture"); }); modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Component", b => diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Order.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Order.cs index eae01c2..d137114 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Order.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Order.cs @@ -18,7 +18,6 @@ namespace FurnitureAssemblyDatabaseImplement.Models public int Id { get; private set; } [Required] public int FurnitureId { get; private set; } - public string FurnitureName { get; private set; } = string.Empty; [Required] public int Count { get; private set; } [Required] @@ -30,6 +29,8 @@ namespace FurnitureAssemblyDatabaseImplement.Models public DateTime? DateImplement { get; private set; } + public virtual Furniture Furniture { get; set; } + public static Order? Create(OrderBindingModel? model) { if (model == null) @@ -40,7 +41,6 @@ namespace FurnitureAssemblyDatabaseImplement.Models { Id = model.Id, FurnitureId = model.FurnitureId, - FurnitureName = model.FurnitureName, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -55,7 +55,6 @@ namespace FurnitureAssemblyDatabaseImplement.Models { Id = model.Id, FurnitureId = model.FurnitureId, - FurnitureName = model.FurnitureName, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -70,19 +69,15 @@ namespace FurnitureAssemblyDatabaseImplement.Models { return; } - FurnitureId = model.FurnitureId; - FurnitureName = model.FurnitureName; - Count = model.Count; - Sum = model.Sum; + Status = model.Status; - DateCreate = model.DateCreate; DateImplement = model.DateImplement; } public OrderViewModel GetViewModel => new() { Id = Id, FurnitureId = FurnitureId, - FurnitureName = FurnitureName, + FurnitureName = Furniture.FurnitureName, Count = Count, Sum = Sum, Status = Status, -- 2.25.1 From ecd0cf786e7b091e1a83dadbb2ed3fb6fda84609 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Thu, 23 Mar 2023 21:21:15 +0400 Subject: [PATCH 6/7] =?UTF-8?q?=D0=9E=D1=88=D0=B8=D0=B1=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=B2=20=D0=91=D0=94.........?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20230323163820_FixMigration.Designer.cs | 171 ++++++++++++++++++ .../Migrations/20230323163820_FixMigration.cs | 29 +++ .../FurnitureAssemblyDatabaseModelSnapshot.cs | 3 - .../Models/Furniture.cs | 2 +- .../Models/FurnitureComponent.cs | 2 +- 5 files changed, 202 insertions(+), 5 deletions(-) create mode 100644 FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20230323163820_FixMigration.Designer.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20230323163820_FixMigration.cs diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20230323163820_FixMigration.Designer.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20230323163820_FixMigration.Designer.cs new file mode 100644 index 0000000..693634d --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20230323163820_FixMigration.Designer.cs @@ -0,0 +1,171 @@ +// +using System; +using FurnitureAssemblyDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace FurnitureAssemblyDatabaseImplement.Migrations +{ + [DbContext(typeof(FurnitureAssemblyDatabase))] + [Migration("20230323163820_FixMigration")] + partial class FixMigration + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Furniture", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("FurnitureName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Furnitures"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.FurnitureComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("FurnitureId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("FurnitureId"); + + b.ToTable("FurnitureComponents"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("FurnitureId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("FurnitureId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.FurnitureComponent", b => + { + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Component", "Component") + .WithMany("FurnitureComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", "Furniture") + .WithMany("Components") + .HasForeignKey("FurnitureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Furniture"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Order", b => + { + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", "Furniture") + .WithMany("Orders") + .HasForeignKey("FurnitureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Furniture"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Component", b => + { + b.Navigation("FurnitureComponents"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Furniture", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20230323163820_FixMigration.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20230323163820_FixMigration.cs new file mode 100644 index 0000000..6da5598 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20230323163820_FixMigration.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace FurnitureAssemblyDatabaseImplement.Migrations +{ + /// + public partial class FixMigration : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "ProductId", + table: "FurnitureComponents"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "ProductId", + table: "FurnitureComponents", + type: "int", + nullable: false, + defaultValue: 0); + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs index e24f216..af45ba4 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs @@ -79,9 +79,6 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations b.Property("FurnitureId") .HasColumnType("int"); - b.Property("ProductId") - .HasColumnType("int"); - b.HasKey("Id"); b.HasIndex("ComponentId"); diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs index 3e7fa61..992dc97 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Furniture.cs @@ -66,7 +66,7 @@ namespace FurnitureAssemblyDatabaseImplement.Models public void UpdateComponents(FurnitureAssemblyDatabase context, FurnitureBindingModel model) { - var furnitureComponents = context.FurnitureComponents.Where(rec => rec.ProductId == model.Id).ToList(); + var furnitureComponents = context.FurnitureComponents.Where(rec => rec.FurnitureId == model.Id).ToList(); if (furnitureComponents != null && furnitureComponents.Count > 0) { // удалили те, которых нет в модели context.FurnitureComponents.RemoveRange(furnitureComponents.Where(rec diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/FurnitureComponent.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/FurnitureComponent.cs index fe41e6d..67081f0 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/FurnitureComponent.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/FurnitureComponent.cs @@ -11,7 +11,7 @@ namespace FurnitureAssemblyDatabaseImplement.Models { public int Id { get; set; } [Required] - public int ProductId { get; set; } + public int FurnitureId { get; set; } [Required] public int ComponentId { get; set; } -- 2.25.1 From 49ad29442557f044bcbf6f4a9adf37f031bec243 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sat, 25 Mar 2023 11:02:32 +0400 Subject: [PATCH 7/7] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/OrderStorage.cs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/OrderStorage.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/OrderStorage.cs index d85ac24..26182d3 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/OrderStorage.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/OrderStorage.cs @@ -88,15 +88,5 @@ namespace FurnitureAssemblyDatabaseImplement.Implements } return null; } - - public OrderViewModel GetOrderViewModel(Order order) - { - var viewmodel = order.GetViewModel; - using var context = new FurnitureAssemblyDatabase(); - var furniture = context.Furnitures.FirstOrDefault(x => x.Id == order.FurnitureId); - if (furniture != null) - viewmodel.FurnitureName = furniture.FurnitureName; - return viewmodel; - } } } -- 2.25.1