lab3
This commit is contained in:
parent
b871905a0e
commit
689da20999
@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryListImplement",
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FishFactoryFileImplement", "FishFactoryFileImplement\FishFactoryFileImplement.csproj", "{EB4AEC72-72EC-437B-A760-603FA90301B5}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FishFactoryFileImplement", "FishFactoryFileImplement\FishFactoryFileImplement.csproj", "{EB4AEC72-72EC-437B-A760-603FA90301B5}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FishFactoryDatabaseImplement", "FishFactoryDatabaseImplement\FishFactoryDatabaseImplement.csproj", "{9BADDBDE-37C7-4E3F-8B4F-F663E3B17F65}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -45,6 +47,10 @@ Global
|
|||||||
{EB4AEC72-72EC-437B-A760-603FA90301B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{EB4AEC72-72EC-437B-A760-603FA90301B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{EB4AEC72-72EC-437B-A760-603FA90301B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{EB4AEC72-72EC-437B-A760-603FA90301B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{EB4AEC72-72EC-437B-A760-603FA90301B5}.Release|Any CPU.Build.0 = Release|Any CPU
|
{EB4AEC72-72EC-437B-A760-603FA90301B5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{9BADDBDE-37C7-4E3F-8B4F-F663E3B17F65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{9BADDBDE-37C7-4E3F-8B4F-F663E3B17F65}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{9BADDBDE-37C7-4E3F-8B4F-F663E3B17F65}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{9BADDBDE-37C7-4E3F-8B4F-F663E3B17F65}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using FishFactoryDatabaseImplement.Models;
|
||||||
|
|
||||||
|
namespace FishFactoryDatabaseImplement
|
||||||
|
{
|
||||||
|
public class FishFactoryDatabase : DbContext
|
||||||
|
{
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
|
{
|
||||||
|
if (optionsBuilder.IsConfigured == false)
|
||||||
|
{
|
||||||
|
optionsBuilder.UseSqlServer(@"Data Source=WIN-PC\SQLEXPRESS;Initial Catalog=FishFactoryDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||||
|
}
|
||||||
|
base.OnConfiguring(optionsBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual DbSet<Component> Components { set; get; }
|
||||||
|
|
||||||
|
public virtual DbSet<Canned> CannedList { set; get; }
|
||||||
|
|
||||||
|
public virtual DbSet<CannedComponent> CannedComponents { set; get; }
|
||||||
|
|
||||||
|
public virtual DbSet<Order> Orders { set; get; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.3" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.3" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.3">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\FishFactoryContracts\FishFactoryContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\FishFactoryDataModels\FishFactoryDataModels.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -0,0 +1,107 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using FishFactoryContracts.BindingModels;
|
||||||
|
using FishFactoryContracts.SearchModels;
|
||||||
|
using FishFactoryContracts.StoragesContracts;
|
||||||
|
using FishFactoryContracts.ViewModels;
|
||||||
|
using FishFactoryDatabaseImplement.Models;
|
||||||
|
|
||||||
|
namespace FishFactoryDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class CannedStorage : ICannedStorage
|
||||||
|
{
|
||||||
|
public List<CannedViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new FishFactoryDatabase();
|
||||||
|
return context.CannedList
|
||||||
|
.Include(x => x.Components)
|
||||||
|
.ThenInclude(x => x.Component)
|
||||||
|
.ToList()
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CannedViewModel> GetFilteredList(CannedSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.CannedName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new FishFactoryDatabase();
|
||||||
|
return context.CannedList
|
||||||
|
.Include(x => x.Components)
|
||||||
|
.ThenInclude(x => x.Component)
|
||||||
|
.Where(x => x.CannedName.Contains(model.CannedName))
|
||||||
|
.ToList()
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public CannedViewModel? GetElement(CannedSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.CannedName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new FishFactoryDatabase();
|
||||||
|
return context.CannedList
|
||||||
|
.Include(x => x.Components)
|
||||||
|
.ThenInclude(x => x.Component)
|
||||||
|
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.CannedName) && x.CannedName == model.CannedName) ||
|
||||||
|
(model.Id.HasValue && x.Id == model.Id))
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CannedViewModel? Insert(CannedBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new FishFactoryDatabase();
|
||||||
|
var newCanned = Canned.Create(context, model);
|
||||||
|
if (newCanned == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
context.CannedList.Add(newCanned);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newCanned.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CannedViewModel? Update(CannedBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new FishFactoryDatabase();
|
||||||
|
using var transaction = context.Database.BeginTransaction();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var Canned = context.CannedList.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (Canned == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Canned.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
Canned.UpdateComponents(context, model);
|
||||||
|
transaction.Commit();
|
||||||
|
return Canned.GetViewModel;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CannedViewModel? Delete(CannedBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new FishFactoryDatabase();
|
||||||
|
var element = context.CannedList
|
||||||
|
.Include(x => x.Components)
|
||||||
|
.Include(x => x.Orders)
|
||||||
|
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.CannedList.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,83 @@
|
|||||||
|
using FishFactoryContracts.BindingModels;
|
||||||
|
using FishFactoryContracts.SearchModels;
|
||||||
|
using FishFactoryContracts.StoragesContracts;
|
||||||
|
using FishFactoryContracts.ViewModels;
|
||||||
|
using FishFactoryDatabaseImplement.Models;
|
||||||
|
|
||||||
|
namespace FishFactoryDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class ComponentStorage : IComponentStorage
|
||||||
|
{
|
||||||
|
public List<ComponentViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new FishFactoryDatabase();
|
||||||
|
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 FishFactoryDatabase();
|
||||||
|
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 FishFactoryDatabase();
|
||||||
|
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 FishFactoryDatabase();
|
||||||
|
context.Components.Add(newComponent);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newComponent.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ComponentViewModel? Update(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new FishFactoryDatabase();
|
||||||
|
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 FishFactoryDatabase();
|
||||||
|
var element = context.Components.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Components.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,93 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using FishFactoryContracts.BindingModels;
|
||||||
|
using FishFactoryContracts.SearchModels;
|
||||||
|
using FishFactoryContracts.StoragesContracts;
|
||||||
|
using FishFactoryContracts.ViewModels;
|
||||||
|
using FishFactoryDatabaseImplement.Models;
|
||||||
|
|
||||||
|
namespace FishFactoryDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class OrderStorage : IOrderStorage
|
||||||
|
{
|
||||||
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new FishFactoryDatabase();
|
||||||
|
var element = context.Orders
|
||||||
|
.Include(x => x.Canned)
|
||||||
|
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Orders.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new FishFactoryDatabase();
|
||||||
|
return context.Orders
|
||||||
|
.Include(x => x.Canned)
|
||||||
|
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new FishFactoryDatabase();
|
||||||
|
return context.Orders
|
||||||
|
.Include(x => x.Canned)
|
||||||
|
.Where(x => x.Id == model.Id)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public List<OrderViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new FishFactoryDatabase();
|
||||||
|
return context.Orders
|
||||||
|
.Include(x => x.Canned)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
var newOrder = Order.Create(model);
|
||||||
|
if (newOrder == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new FishFactoryDatabase();
|
||||||
|
context.Orders.Add(newOrder);
|
||||||
|
context.SaveChanges();
|
||||||
|
return context.Orders
|
||||||
|
.Include(x => x.Canned)
|
||||||
|
.FirstOrDefault(x => x.Id == newOrder.Id)
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new FishFactoryDatabase();
|
||||||
|
var order = context.Orders
|
||||||
|
.Include(x => x.Canned)
|
||||||
|
.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (order == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
order.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return order.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
171
FishFactory/FishFactoryDatabaseImplement/Migrations/20240330161357_InitialCreate.Designer.cs
generated
Normal file
171
FishFactory/FishFactoryDatabaseImplement/Migrations/20240330161357_InitialCreate.Designer.cs
generated
Normal file
@ -0,0 +1,171 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using FishFactoryDatabaseImplement;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace FishFactoryDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(FishFactoryDatabase))]
|
||||||
|
[Migration("20240330161357_InitialCreate")]
|
||||||
|
partial class InitialCreate
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
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("FishFactoryDatabaseImplement.Models.Canned", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("CannedName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<double>("Price")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("CannedList");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.CannedComponent", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("CannedId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("ComponentId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("CannedId");
|
||||||
|
|
||||||
|
b.HasIndex("ComponentId");
|
||||||
|
|
||||||
|
b.ToTable("CannedComponents");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Component", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("ComponentName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<double>("Cost")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Components");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("CannedId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreate")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("DateImplement")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<int>("Status")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<double>("Sum")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("CannedId");
|
||||||
|
|
||||||
|
b.ToTable("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.CannedComponent", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FishFactoryDatabaseImplement.Models.Canned", "Canned")
|
||||||
|
.WithMany("Components")
|
||||||
|
.HasForeignKey("CannedId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("FishFactoryDatabaseImplement.Models.Component", "Component")
|
||||||
|
.WithMany("CannedComponents")
|
||||||
|
.HasForeignKey("ComponentId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Canned");
|
||||||
|
|
||||||
|
b.Navigation("Component");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FishFactoryDatabaseImplement.Models.Canned", "Canned")
|
||||||
|
.WithMany("Orders")
|
||||||
|
.HasForeignKey("CannedId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Canned");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Canned", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Components");
|
||||||
|
|
||||||
|
b.Navigation("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Component", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("CannedComponents");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,125 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace FishFactoryDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class InitialCreate : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "CannedList",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
CannedName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
Price = table.Column<double>(type: "float", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_CannedList", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Components",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
ComponentName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
Cost = table.Column<double>(type: "float", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Components", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Orders",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
CannedId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
Count = table.Column<int>(type: "int", nullable: false),
|
||||||
|
Sum = table.Column<double>(type: "float", nullable: false),
|
||||||
|
Status = table.Column<int>(type: "int", nullable: false),
|
||||||
|
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||||
|
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Orders", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Orders_CannedList_CannedId",
|
||||||
|
column: x => x.CannedId,
|
||||||
|
principalTable: "CannedList",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "CannedComponents",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
CannedId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
ComponentId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
Count = table.Column<int>(type: "int", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_CannedComponents", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_CannedComponents_CannedList_CannedId",
|
||||||
|
column: x => x.CannedId,
|
||||||
|
principalTable: "CannedList",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_CannedComponents_Components_ComponentId",
|
||||||
|
column: x => x.ComponentId,
|
||||||
|
principalTable: "Components",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_CannedComponents_CannedId",
|
||||||
|
table: "CannedComponents",
|
||||||
|
column: "CannedId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_CannedComponents_ComponentId",
|
||||||
|
table: "CannedComponents",
|
||||||
|
column: "ComponentId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Orders_CannedId",
|
||||||
|
table: "Orders",
|
||||||
|
column: "CannedId");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "CannedComponents");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Orders");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Components");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "CannedList");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,168 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using FishFactoryDatabaseImplement;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace FishFactoryDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(FishFactoryDatabase))]
|
||||||
|
partial class FishFactoryDatabaseModelSnapshot : 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("FishFactoryDatabaseImplement.Models.Canned", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("CannedName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<double>("Price")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("CannedList");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.CannedComponent", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("CannedId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("ComponentId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("CannedId");
|
||||||
|
|
||||||
|
b.HasIndex("ComponentId");
|
||||||
|
|
||||||
|
b.ToTable("CannedComponents");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Component", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("ComponentName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<double>("Cost")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Components");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("CannedId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreate")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("DateImplement")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<int>("Status")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<double>("Sum")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("CannedId");
|
||||||
|
|
||||||
|
b.ToTable("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.CannedComponent", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FishFactoryDatabaseImplement.Models.Canned", "Canned")
|
||||||
|
.WithMany("Components")
|
||||||
|
.HasForeignKey("CannedId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("FishFactoryDatabaseImplement.Models.Component", "Component")
|
||||||
|
.WithMany("CannedComponents")
|
||||||
|
.HasForeignKey("ComponentId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Canned");
|
||||||
|
|
||||||
|
b.Navigation("Component");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FishFactoryDatabaseImplement.Models.Canned", "Canned")
|
||||||
|
.WithMany("Orders")
|
||||||
|
.HasForeignKey("CannedId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Canned");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Canned", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Components");
|
||||||
|
|
||||||
|
b.Navigation("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Component", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("CannedComponents");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
99
FishFactory/FishFactoryDatabaseImplement/Models/Canned.cs
Normal file
99
FishFactory/FishFactoryDatabaseImplement/Models/Canned.cs
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
using FishFactoryContracts.BindingModels;
|
||||||
|
using FishFactoryContracts.ViewModels;
|
||||||
|
using FishFactoryDataModels.Models;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace FishFactoryDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Canned : ICannedModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string CannedName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public double Price { get; set; }
|
||||||
|
|
||||||
|
private Dictionary<int, (IComponentModel, int)>? _cannedComponents = null;
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
public Dictionary<int, (IComponentModel, int)> CannedComponents
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_cannedComponents == null)
|
||||||
|
{
|
||||||
|
_cannedComponents = Components
|
||||||
|
.ToDictionary(recPC => recPC.ComponentId, recPC => (recPC.Component as IComponentModel, recPC.Count));
|
||||||
|
}
|
||||||
|
return _cannedComponents;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[ForeignKey("CannedId")]
|
||||||
|
public virtual List<CannedComponent> Components { get; set; } = new();
|
||||||
|
|
||||||
|
[ForeignKey("CannedId")]
|
||||||
|
public virtual List<Order> Orders { get; set; } = new();
|
||||||
|
|
||||||
|
public static Canned Create(FishFactoryDatabase context, CannedBindingModel model)
|
||||||
|
{
|
||||||
|
return new Canned()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
CannedName = model.CannedName,
|
||||||
|
Price = model.Price,
|
||||||
|
Components = model.CannedComponents.Select(x => new CannedComponent
|
||||||
|
{
|
||||||
|
Component = context.Components.First(y => y.Id == x.Key),
|
||||||
|
Count = x.Value.Item2
|
||||||
|
}).ToList()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(CannedBindingModel model)
|
||||||
|
{
|
||||||
|
CannedName = model.CannedName;
|
||||||
|
Price = model.Price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CannedViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
CannedName = CannedName,
|
||||||
|
Price = Price,
|
||||||
|
CannedComponents = CannedComponents
|
||||||
|
};
|
||||||
|
|
||||||
|
public void UpdateComponents(FishFactoryDatabase context, CannedBindingModel model)
|
||||||
|
{
|
||||||
|
var cannedComponents = context.CannedComponents.Where(rec => rec.CannedId == model.Id).ToList();
|
||||||
|
if (cannedComponents != null && cannedComponents.Count > 0)
|
||||||
|
{ // удалили те, которых нет в модели
|
||||||
|
context.CannedComponents.RemoveRange(cannedComponents.Where(rec => !model.CannedComponents.ContainsKey(rec.ComponentId)));
|
||||||
|
context.SaveChanges();
|
||||||
|
// обновили количество у существующих записей
|
||||||
|
foreach (var updateComponent in cannedComponents)
|
||||||
|
{
|
||||||
|
updateComponent.Count = model.CannedComponents[updateComponent.ComponentId].Item2;
|
||||||
|
model.CannedComponents.Remove(updateComponent.ComponentId);
|
||||||
|
}
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
var canned = context.CannedList.First(x => x.Id == Id);
|
||||||
|
foreach (var cd in model.CannedComponents)
|
||||||
|
{
|
||||||
|
context.CannedComponents.Add(new CannedComponent
|
||||||
|
{
|
||||||
|
Canned = canned,
|
||||||
|
Component = context.Components.First(x => x.Id == cd.Key),
|
||||||
|
Count = cd.Value.Item2
|
||||||
|
});
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
_cannedComponents = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace FishFactoryDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class CannedComponent
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int CannedId { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int ComponentId { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int Count { get; set; }
|
||||||
|
|
||||||
|
public virtual Component Component { get; set; } = new();
|
||||||
|
|
||||||
|
public virtual Canned Canned { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
63
FishFactory/FishFactoryDatabaseImplement/Models/Component.cs
Normal file
63
FishFactory/FishFactoryDatabaseImplement/Models/Component.cs
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
using FishFactoryContracts.BindingModels;
|
||||||
|
using FishFactoryContracts.ViewModels;
|
||||||
|
using FishFactoryDataModels.Models;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace FishFactoryDatabaseImplement.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<CannedComponent> CannedComponents { 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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
64
FishFactory/FishFactoryDatabaseImplement/Models/Order.cs
Normal file
64
FishFactory/FishFactoryDatabaseImplement/Models/Order.cs
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
using FishFactoryContracts.BindingModels;
|
||||||
|
using FishFactoryContracts.ViewModels;
|
||||||
|
using FishFactoryDataModels.Models;
|
||||||
|
using FishFactoryDataModels.Enums;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace FishFactoryDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Order : IOrderModel
|
||||||
|
{
|
||||||
|
[Required]
|
||||||
|
public int CannedId { get; set; }
|
||||||
|
[Required]
|
||||||
|
public int Count { get; set; }
|
||||||
|
[Required]
|
||||||
|
public double Sum { get; set; }
|
||||||
|
[Required]
|
||||||
|
public OrderStatus Status { get; set; }
|
||||||
|
[Required]
|
||||||
|
public DateTime DateCreate { get; set; }
|
||||||
|
public DateTime? DateImplement { get; set; }
|
||||||
|
public int Id { get; set; }
|
||||||
|
public Canned Canned { get; set; }
|
||||||
|
public static Order? Create(OrderBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Order()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
CannedId = model.CannedId,
|
||||||
|
Count = model.Count,
|
||||||
|
Sum = model.Sum,
|
||||||
|
Status = model.Status,
|
||||||
|
DateCreate = model.DateCreate,
|
||||||
|
DateImplement = model.DateImplement,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(OrderBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Status = model.Status;
|
||||||
|
DateImplement = model.DateImplement;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
CannedId = CannedId,
|
||||||
|
Count = Count,
|
||||||
|
Sum = Sum,
|
||||||
|
DateCreate = DateCreate,
|
||||||
|
DateImplement = DateImplement,
|
||||||
|
Id = Id,
|
||||||
|
Status = Status,
|
||||||
|
CannedName = Canned.CannedName,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -9,6 +9,10 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.3">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
|
||||||
@ -18,6 +22,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\FishFactoryBusinessLogic\FishFactoryBusinessLogic.csproj" />
|
<ProjectReference Include="..\FishFactoryBusinessLogic\FishFactoryBusinessLogic.csproj" />
|
||||||
<ProjectReference Include="..\FishFactoryContracts\FishFactoryContracts.csproj" />
|
<ProjectReference Include="..\FishFactoryContracts\FishFactoryContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\FishFactoryDatabaseImplement\FishFactoryDatabaseImplement.csproj" />
|
||||||
<ProjectReference Include="..\FishFactoryFileImplement\FishFactoryFileImplement.csproj" />
|
<ProjectReference Include="..\FishFactoryFileImplement\FishFactoryFileImplement.csproj" />
|
||||||
<ProjectReference Include="..\FishFactoryListImplement\FishFactoryListImplement.csproj" />
|
<ProjectReference Include="..\FishFactoryListImplement\FishFactoryListImplement.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -4,7 +4,7 @@ using NLog.Extensions.Logging;
|
|||||||
using FishFactoryBusinessLogic.BusinessLogics;
|
using FishFactoryBusinessLogic.BusinessLogics;
|
||||||
using FishFactoryContracts.BusinessLogicsContracts;
|
using FishFactoryContracts.BusinessLogicsContracts;
|
||||||
using FishFactoryContracts.StoragesContracts;
|
using FishFactoryContracts.StoragesContracts;
|
||||||
using FishFactoryFileImplement.Implements;
|
using FishFactoryDatabaseImplement.Implements;
|
||||||
using FishFactoryView;
|
using FishFactoryView;
|
||||||
|
|
||||||
namespace FishFactoryView
|
namespace FishFactoryView
|
||||||
|
Loading…
Reference in New Issue
Block a user