ThirdLaba
This commit is contained in:
parent
860812d1e9
commit
e0da3a3c8a
@ -3,17 +3,19 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.3.32825.248
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryDataModels", "FishFactoryDataModels\FishFactoryDataModels.csproj", "{4FAEE923-3CA2-4AFE-9C2C-050BAEE36A29}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryDataModels", "FishFactoryDataModels\FishFactoryDataModels.csproj", "{37D4B025-75B2-4B69-9E3A-72897F6DF370}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryContracts", "FishFactoryContracts\FishFactoryContracts.csproj", "{3B62D774-0DEB-450B-B299-BF6F4A7087BD}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryContracts", "FishFactoryContracts\FishFactoryContracts.csproj", "{BC8980F9-E399-46CB-A8DA-CE512D4563B3}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryBusinessLogic", "FishFactoryBusinessLogic\FishFactoryBusinessLogic.csproj", "{4D20FEFE-07A7-40F9-8E2E-A94811F92601}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryBusinessLogic", "FishFactoryBusinessLogic\FishFactoryBusinessLogic.csproj", "{15CC37A7-66F1-4CD8-AC4D-5006B6F2684C}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryListImplement", "FishFactoryListImplement\FishFactoryListImplement.csproj", "{ED796052-9415-4436-837E-C82D78B10BEB}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryListImplement", "FishFactoryListImplement\FishFactoryListImplement.csproj", "{FCFDA778-33D7-42BF-B09C-7C20A2C87672}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryFileImplement", "FishFactoryFileImplement\FishFactoryFileImplement.csproj", "{E898CFA7-2232-4B1C-B36A-9FBC6D841DF4}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryFileImplement", "FishFactoryFileImplement\FishFactoryFileImplement.csproj", "{B842D6FF-1528-4AED-9047-6772D4BEB2EF}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryView", "FishFactoryView\FishFactoryView.csproj", "{F5DB1B1C-105F-41D8-9416-6334CD96E838}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryDatabaseImplement", "FishFactoryDatabaseImplement\FishFactoryDatabaseImplement.csproj", "{F5654037-2B5B-4772-B667-B3A085CA9CE5}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryView", "FishFactoryView\FishFactoryView.csproj", "{5A1CA46A-03B0-4641-B89E-18BBA0A26360}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -21,30 +23,34 @@ Global
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{4FAEE923-3CA2-4AFE-9C2C-050BAEE36A29}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4FAEE923-3CA2-4AFE-9C2C-050BAEE36A29}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4FAEE923-3CA2-4AFE-9C2C-050BAEE36A29}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4FAEE923-3CA2-4AFE-9C2C-050BAEE36A29}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{3B62D774-0DEB-450B-B299-BF6F4A7087BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{3B62D774-0DEB-450B-B299-BF6F4A7087BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3B62D774-0DEB-450B-B299-BF6F4A7087BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3B62D774-0DEB-450B-B299-BF6F4A7087BD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{4D20FEFE-07A7-40F9-8E2E-A94811F92601}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4D20FEFE-07A7-40F9-8E2E-A94811F92601}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4D20FEFE-07A7-40F9-8E2E-A94811F92601}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4D20FEFE-07A7-40F9-8E2E-A94811F92601}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{ED796052-9415-4436-837E-C82D78B10BEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{ED796052-9415-4436-837E-C82D78B10BEB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{ED796052-9415-4436-837E-C82D78B10BEB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{ED796052-9415-4436-837E-C82D78B10BEB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E898CFA7-2232-4B1C-B36A-9FBC6D841DF4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E898CFA7-2232-4B1C-B36A-9FBC6D841DF4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E898CFA7-2232-4B1C-B36A-9FBC6D841DF4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E898CFA7-2232-4B1C-B36A-9FBC6D841DF4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F5DB1B1C-105F-41D8-9416-6334CD96E838}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F5DB1B1C-105F-41D8-9416-6334CD96E838}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F5DB1B1C-105F-41D8-9416-6334CD96E838}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F5DB1B1C-105F-41D8-9416-6334CD96E838}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{37D4B025-75B2-4B69-9E3A-72897F6DF370}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{37D4B025-75B2-4B69-9E3A-72897F6DF370}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{37D4B025-75B2-4B69-9E3A-72897F6DF370}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{37D4B025-75B2-4B69-9E3A-72897F6DF370}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{BC8980F9-E399-46CB-A8DA-CE512D4563B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BC8980F9-E399-46CB-A8DA-CE512D4563B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BC8980F9-E399-46CB-A8DA-CE512D4563B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BC8980F9-E399-46CB-A8DA-CE512D4563B3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{15CC37A7-66F1-4CD8-AC4D-5006B6F2684C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{15CC37A7-66F1-4CD8-AC4D-5006B6F2684C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{15CC37A7-66F1-4CD8-AC4D-5006B6F2684C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{15CC37A7-66F1-4CD8-AC4D-5006B6F2684C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{FCFDA778-33D7-42BF-B09C-7C20A2C87672}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FCFDA778-33D7-42BF-B09C-7C20A2C87672}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FCFDA778-33D7-42BF-B09C-7C20A2C87672}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FCFDA778-33D7-42BF-B09C-7C20A2C87672}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B842D6FF-1528-4AED-9047-6772D4BEB2EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B842D6FF-1528-4AED-9047-6772D4BEB2EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B842D6FF-1528-4AED-9047-6772D4BEB2EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B842D6FF-1528-4AED-9047-6772D4BEB2EF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F5654037-2B5B-4772-B667-B3A085CA9CE5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F5654037-2B5B-4772-B667-B3A085CA9CE5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F5654037-2B5B-4772-B667-B3A085CA9CE5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F5654037-2B5B-4772-B667-B3A085CA9CE5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5A1CA46A-03B0-4641-B89E-18BBA0A26360}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5A1CA46A-03B0-4641-B89E-18BBA0A26360}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5A1CA46A-03B0-4641-B89E-18BBA0A26360}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5A1CA46A-03B0-4641-B89E-18BBA0A26360}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -7,6 +7,10 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.1" />
|
||||
|
@ -6,6 +6,13 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<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="..\FishFactoryDataModels\FishFactoryDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
@ -6,4 +6,11 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -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=DESKTOP-OM38GNQ;Initial Catalog=FishFactoryDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
||||
public virtual DbSet<Ingredient> Ingredients { set; get; }
|
||||
|
||||
public virtual DbSet<Canned> CannedList { set; get; }
|
||||
|
||||
public virtual DbSet<CannedIngredient> CannedIngredients { 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.Ingredients)
|
||||
.ThenInclude(x => x.Ingredient)
|
||||
.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.Ingredients)
|
||||
.ThenInclude(x => x.Ingredient)
|
||||
.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.Ingredients)
|
||||
.ThenInclude(x => x.Ingredient)
|
||||
.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.UpdateIngredients(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.Ingredients)
|
||||
.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 IngredientStorage : IIngredientStorage
|
||||
{
|
||||
public List<IngredientViewModel> GetFullList()
|
||||
{
|
||||
using var context = new FishFactoryDatabase();
|
||||
return context.Ingredients
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<IngredientViewModel> GetFilteredList(IngredientSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.IngredientName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new FishFactoryDatabase();
|
||||
return context.Ingredients
|
||||
.Where(x => x.IngredientName.Contains(model.IngredientName))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public IngredientViewModel? GetElement(IngredientSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.IngredientName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new FishFactoryDatabase();
|
||||
return context.Ingredients
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.IngredientName) && x.IngredientName == model.IngredientName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public IngredientViewModel? Insert(IngredientBindingModel model)
|
||||
{
|
||||
var newIngredient = Ingredient.Create(model);
|
||||
if (newIngredient == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new FishFactoryDatabase();
|
||||
context.Ingredients.Add(newIngredient);
|
||||
context.SaveChanges();
|
||||
return newIngredient.GetViewModel;
|
||||
}
|
||||
|
||||
public IngredientViewModel? Update(IngredientBindingModel model)
|
||||
{
|
||||
using var context = new FishFactoryDatabase();
|
||||
var ingredient = context.Ingredients.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (ingredient == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
ingredient.Update(model);
|
||||
context.SaveChanges();
|
||||
return ingredient.GetViewModel;
|
||||
}
|
||||
|
||||
public IngredientViewModel? Delete(IngredientBindingModel model)
|
||||
{
|
||||
using var context = new FishFactoryDatabase();
|
||||
var element = context.Ingredients.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Ingredients.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/20230315130506_InitialCreate.Designer.cs
generated
Normal file
171
FishFactory/FishFactoryDatabaseImplement/Migrations/20230315130506_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("20230315130506_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.CannedIngredient", 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<int>("IngredientId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CannedId");
|
||||
|
||||
b.HasIndex("IngredientId");
|
||||
|
||||
b.ToTable("CannedIngredients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Ingredient", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<string>("IngredientName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Ingredients");
|
||||
});
|
||||
|
||||
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.CannedIngredient", b =>
|
||||
{
|
||||
b.HasOne("FishFactoryDatabaseImplement.Models.Canned", "Canned")
|
||||
.WithMany("Ingredients")
|
||||
.HasForeignKey("CannedId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FishFactoryDatabaseImplement.Models.Ingredient", "Ingredient")
|
||||
.WithMany("SushiIngredients")
|
||||
.HasForeignKey("IngredientId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Canned");
|
||||
|
||||
b.Navigation("Ingredient");
|
||||
});
|
||||
|
||||
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("Ingredients");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Ingredient", b =>
|
||||
{
|
||||
b.Navigation("SushiIngredients");
|
||||
});
|
||||
#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: "Ingredients",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
IngredientName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Cost = table.Column<double>(type: "float", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Ingredients", 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: "CannedIngredients",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
CannedId = table.Column<int>(type: "int", nullable: false),
|
||||
IngredientId = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_CannedIngredients", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_CannedIngredients_CannedList_CannedId",
|
||||
column: x => x.CannedId,
|
||||
principalTable: "CannedList",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_CannedIngredients_Ingredients_IngredientId",
|
||||
column: x => x.IngredientId,
|
||||
principalTable: "Ingredients",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_CannedIngredients_CannedId",
|
||||
table: "CannedIngredients",
|
||||
column: "CannedId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_CannedIngredients_IngredientId",
|
||||
table: "CannedIngredients",
|
||||
column: "IngredientId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_CannedId",
|
||||
table: "Orders",
|
||||
column: "CannedId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "CannedIngredients");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Orders");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Ingredients");
|
||||
|
||||
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.CannedIngredient", 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<int>("IngredientId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CannedId");
|
||||
|
||||
b.HasIndex("IngredientId");
|
||||
|
||||
b.ToTable("CannedIngredients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Ingredient", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<string>("IngredientName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Ingredients");
|
||||
});
|
||||
|
||||
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.CannedIngredient", b =>
|
||||
{
|
||||
b.HasOne("FishFactoryDatabaseImplement.Models.Canned", "Canned")
|
||||
.WithMany("Ingredients")
|
||||
.HasForeignKey("CannedId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FishFactoryDatabaseImplement.Models.Ingredient", "Ingredient")
|
||||
.WithMany("SushiIngredients")
|
||||
.HasForeignKey("IngredientId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Canned");
|
||||
|
||||
b.Navigation("Ingredient");
|
||||
});
|
||||
|
||||
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("Ingredients");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Ingredient", b =>
|
||||
{
|
||||
b.Navigation("SushiIngredients");
|
||||
});
|
||||
#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, (IIngredientModel, int)>? _cannedIngredients = null;
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IIngredientModel, int)> CannedIngredients
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_cannedIngredients == null)
|
||||
{
|
||||
_cannedIngredients = Ingredients
|
||||
.ToDictionary(recPC => recPC.IngredientId, recPC => (recPC.Ingredient as IIngredientModel, recPC.Count));
|
||||
}
|
||||
return _cannedIngredients;
|
||||
}
|
||||
}
|
||||
|
||||
[ForeignKey("CannedId")]
|
||||
public virtual List<CannedIngredient> Ingredients { 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,
|
||||
Ingredients = model.CannedIngredients.Select(x => new CannedIngredient
|
||||
{
|
||||
Ingredient = context.Ingredients.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,
|
||||
CannedIngredients = CannedIngredients
|
||||
};
|
||||
|
||||
public void UpdateIngredients(FishFactoryDatabase context, CannedBindingModel model)
|
||||
{
|
||||
var cannedIngredients = context.CannedIngredients.Where(rec => rec.CannedId == model.Id).ToList();
|
||||
if (cannedIngredients != null && cannedIngredients.Count > 0)
|
||||
{ // удалили те, которых нет в модели
|
||||
context.CannedIngredients.RemoveRange(cannedIngredients.Where(rec => !model.CannedIngredients.ContainsKey(rec.IngredientId)));
|
||||
context.SaveChanges();
|
||||
// обновили количество у существующих записей
|
||||
foreach (var updateIngredient in cannedIngredients)
|
||||
{
|
||||
updateIngredient.Count = model.CannedIngredients[updateIngredient.IngredientId].Item2;
|
||||
model.CannedIngredients.Remove(updateIngredient.IngredientId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var canned = context.CannedList.First(x => x.Id == Id);
|
||||
foreach (var cd in model.CannedIngredients)
|
||||
{
|
||||
context.CannedIngredients.Add(new CannedIngredient
|
||||
{
|
||||
Canned = canned,
|
||||
Ingredient = context.Ingredients.First(x => x.Id == cd.Key),
|
||||
Count = cd.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_cannedIngredients = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace FishFactoryDatabaseImplement.Models
|
||||
{
|
||||
public class CannedIngredient
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public int CannedId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int IngredientId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
|
||||
public virtual Ingredient Ingredient { get; set; } = new();
|
||||
|
||||
public virtual Canned Canned { get; set; } = new();
|
||||
}
|
||||
}
|
@ -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 Ingredient : IIngredientModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
public string IngredientName { get; private set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public double Cost { get; set; }
|
||||
|
||||
[ForeignKey("IngredientId")]
|
||||
public virtual List<CannedIngredient> SushiIngredients { get; set; } = new();
|
||||
|
||||
public static Ingredient? Create(IngredientBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Ingredient()
|
||||
{
|
||||
Id = model.Id,
|
||||
IngredientName = model.IngredientName,
|
||||
Cost = model.Cost
|
||||
};
|
||||
}
|
||||
|
||||
public static Ingredient Create(IngredientViewModel model)
|
||||
{
|
||||
return new Ingredient
|
||||
{
|
||||
Id = model.Id,
|
||||
IngredientName = model.IngredientName,
|
||||
Cost = model.Cost
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(IngredientBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
IngredientName = model.IngredientName;
|
||||
Cost = model.Cost;
|
||||
}
|
||||
|
||||
public IngredientViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
IngredientName = IngredientName,
|
||||
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,
|
||||
};
|
||||
}
|
||||
}
|
@ -6,6 +6,13 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<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" />
|
||||
|
@ -7,6 +7,10 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.1" />
|
||||
|
@ -9,6 +9,14 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<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.EntityFrameworkCore.Tools" Version="7.0.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.1" />
|
||||
@ -16,6 +24,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FishFactoryBusinessLogic\FishFactoryBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\FishFactoryDatabaseImplement\FishFactoryDatabaseImplement.csproj" />
|
||||
<ProjectReference Include="..\FishFactoryFileImplement\FishFactoryFileImplement.csproj" />
|
||||
<ProjectReference Include="..\FishFactoryListImplement\FishFactoryListImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
@ -4,7 +4,7 @@ using NLog.Extensions.Logging;
|
||||
using FishFactoryBusinessLogic.BusinessLogics;
|
||||
using FishFactoryContracts.BusinessLogicsContracts;
|
||||
using FishFactoryContracts.StoragesContracts;
|
||||
using FishFactoryFileImplement.Implements;
|
||||
using FishFactoryDatabaseImplement.Implements;
|
||||
using FishFactoryView;
|
||||
|
||||
namespace FishFactoryView
|
||||
|
Loading…
Reference in New Issue
Block a user