Compare commits
5 Commits
9f36212f5a
...
01defeaeaa
Author | SHA1 | Date | |
---|---|---|---|
|
01defeaeaa | ||
|
904ba78dde | ||
|
41e2b23042 | ||
|
f50a1d0d82 | ||
|
9e7702be86 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -398,3 +398,4 @@ FodyWeavers.xsd
|
|||||||
# JetBrains Rider
|
# JetBrains Rider
|
||||||
*.sln.iml
|
*.sln.iml
|
||||||
|
|
||||||
|
/Confectionery/ImplementationExtensions
|
@ -13,7 +13,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryBusinessLogic"
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryListImplement", "ConfectioneryListImplement\ConfectioneryListImplement.csproj", "{85992074-656D-4F79-AB23-60DE4F9ABF30}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryListImplement", "ConfectioneryListImplement\ConfectioneryListImplement.csproj", "{85992074-656D-4F79-AB23-60DE4F9ABF30}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryFileImplement", "ConfectioneryFileImplements\ConfectioneryFileImplement.csproj", "{48A8592F-EF58-4FC4-9C9E-B401836FF21E}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryFileImplement", "ConfectioneryFileImplements\ConfectioneryFileImplement.csproj", "{48A8592F-EF58-4FC4-9C9E-B401836FF21E}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryDataBaseImplement", "ConfectioneryDataBaseImplement\ConfectioneryDataBaseImplement.csproj", "{29FD1CED-C24D-40AD-9734-889C0B192A6A}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -45,6 +47,10 @@ Global
|
|||||||
{48A8592F-EF58-4FC4-9C9E-B401836FF21E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{48A8592F-EF58-4FC4-9C9E-B401836FF21E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{48A8592F-EF58-4FC4-9C9E-B401836FF21E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{48A8592F-EF58-4FC4-9C9E-B401836FF21E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{48A8592F-EF58-4FC4-9C9E-B401836FF21E}.Release|Any CPU.Build.0 = Release|Any CPU
|
{48A8592F-EF58-4FC4-9C9E-B401836FF21E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{29FD1CED-C24D-40AD-9734-889C0B192A6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{29FD1CED-C24D-40AD-9734-889C0B192A6A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{29FD1CED-C24D-40AD-9734-889C0B192A6A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{29FD1CED-C24D-40AD-9734-889C0B192A6A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -19,6 +19,10 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<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.DependencyInjection" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
||||||
@ -30,6 +34,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\ConfectioneryBusinessLogic\ConfectioneryBusinessLogic.csproj" />
|
<ProjectReference Include="..\ConfectioneryBusinessLogic\ConfectioneryBusinessLogic.csproj" />
|
||||||
<ProjectReference Include="..\ConfectioneryContracts\ConfectioneryContracts.csproj" />
|
<ProjectReference Include="..\ConfectioneryContracts\ConfectioneryContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\ConfectioneryDataBaseImplement\ConfectioneryDataBaseImplement.csproj" />
|
||||||
<ProjectReference Include="..\ConfectioneryDataModels\ConfectioneryDataModels.csproj" />
|
<ProjectReference Include="..\ConfectioneryDataModels\ConfectioneryDataModels.csproj" />
|
||||||
<ProjectReference Include="..\ConfectioneryFileImplements\ConfectioneryFileImplement.csproj" />
|
<ProjectReference Include="..\ConfectioneryFileImplements\ConfectioneryFileImplement.csproj" />
|
||||||
<ProjectReference Include="..\ConfectioneryListImplement\ConfectioneryListImplement.csproj" />
|
<ProjectReference Include="..\ConfectioneryListImplement\ConfectioneryListImplement.csproj" />
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
using ConfectioneryBusinessLogic.BusinessLogics;
|
using ConfectioneryBusinessLogic.BusinessLogics;
|
||||||
using ConfectioneryContracts.BusinessLogicsContracts;
|
using ConfectioneryContracts.BusinessLogicsContracts;
|
||||||
using ConfectioneryContracts.StoragesContracts;
|
using ConfectioneryContracts.StoragesContracts;
|
||||||
using ConfectioneryFileImplement.Implements;
|
using ConfectioneryDataBaseImplement.Implements;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using NLog.Extensions.Logging;
|
using NLog.Extensions.Logging;
|
||||||
|
@ -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="..\ConfectioneryContracts\ConfectioneryContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\ConfectioneryDataModels\ConfectioneryDataModels.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -0,0 +1,29 @@
|
|||||||
|
using ConfectioneryDataBaseImplement.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ConfectioneryDataBaseImplement
|
||||||
|
{
|
||||||
|
public class ConfectioneryDatabase : DbContext
|
||||||
|
{
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
|
{
|
||||||
|
if (optionsBuilder.IsConfigured == false)
|
||||||
|
{
|
||||||
|
optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=ConfectioneryDatabaseHardLab;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||||
|
}
|
||||||
|
base.OnConfiguring(optionsBuilder);
|
||||||
|
}
|
||||||
|
public virtual DbSet<Ingredient> Ingredients { set; get; }
|
||||||
|
public virtual DbSet<Pastry> Pastrys { set; get; }
|
||||||
|
public virtual DbSet<PastryIngredient> PastryIngredients { set; get; }
|
||||||
|
public virtual DbSet<Order> Orders { set; get; }
|
||||||
|
public virtual DbSet<Shop> Shops { set; get; }
|
||||||
|
public virtual DbSet<ShopPastry> ShopPastries { set; get; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,85 @@
|
|||||||
|
using ConfectioneryContracts.BindingModels;
|
||||||
|
using ConfectioneryContracts.SearchModels;
|
||||||
|
using ConfectioneryContracts.StoragesContracts;
|
||||||
|
using ConfectioneryContracts.ViewModels;
|
||||||
|
using ConfectioneryDataBaseImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ConfectioneryDataBaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class IngredientStorage : IIngredientStorage
|
||||||
|
{
|
||||||
|
public List<IngredientViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new ConfectioneryDatabase();
|
||||||
|
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 ConfectioneryDatabase();
|
||||||
|
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 ConfectioneryDatabase();
|
||||||
|
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 ConfectioneryDatabase();
|
||||||
|
context.Ingredients.Add(newIngredient);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newIngredient.GetViewModel;
|
||||||
|
}
|
||||||
|
public IngredientViewModel? Update(IngredientBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new ConfectioneryDatabase();
|
||||||
|
var component = context.Ingredients.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (component == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
component.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return component.GetViewModel;
|
||||||
|
}
|
||||||
|
public IngredientViewModel? Delete(IngredientBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new ConfectioneryDatabase();
|
||||||
|
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,90 @@
|
|||||||
|
using ConfectioneryContracts.BindingModels;
|
||||||
|
using ConfectioneryContracts.SearchModels;
|
||||||
|
using ConfectioneryContracts.StoragesContracts;
|
||||||
|
using ConfectioneryContracts.ViewModels;
|
||||||
|
using ConfectioneryDataBaseImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ConfectioneryDataBaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class OrderStorage : IOrderStorage
|
||||||
|
{
|
||||||
|
public List<OrderViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new ConfectioneryDatabase();
|
||||||
|
return context.Orders
|
||||||
|
.Select(x => AccessPastryStorage(x.GetViewModel, context))
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new ConfectioneryDatabase();
|
||||||
|
return context.Orders
|
||||||
|
.Where(x => x.Id == model.Id)
|
||||||
|
.Select(x => AccessPastryStorage(x.GetViewModel, context))
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new ConfectioneryDatabase();
|
||||||
|
return AccessPastryStorage(context.Orders
|
||||||
|
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||||
|
?.GetViewModel, context);
|
||||||
|
}
|
||||||
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
var newOrder = Order.Create(model);
|
||||||
|
if (newOrder == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new ConfectioneryDatabase();
|
||||||
|
context.Orders.Add(newOrder);
|
||||||
|
context.SaveChanges();
|
||||||
|
return AccessPastryStorage(newOrder.GetViewModel, context);
|
||||||
|
}
|
||||||
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new ConfectioneryDatabase();
|
||||||
|
var order = context.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (order == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
order.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return AccessPastryStorage(order.GetViewModel, context);
|
||||||
|
}
|
||||||
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new ConfectioneryDatabase();
|
||||||
|
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Orders.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return AccessPastryStorage(element.GetViewModel, context);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
static OrderViewModel AccessPastryStorage(OrderViewModel model, ConfectioneryDatabase context)
|
||||||
|
{
|
||||||
|
if (model == null) return model;
|
||||||
|
string? pastryName = context.Pastrys.FirstOrDefault(x => x.Id == model.PastryId)?.PastryName;
|
||||||
|
if (pastryName != null) model.PastryName = pastryName;
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,106 @@
|
|||||||
|
using ConfectioneryContracts.BindingModels;
|
||||||
|
using ConfectioneryContracts.SearchModels;
|
||||||
|
using ConfectioneryContracts.StoragesContracts;
|
||||||
|
using ConfectioneryContracts.ViewModels;
|
||||||
|
using ConfectioneryDataBaseImplement.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ConfectioneryDataBaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class PastryStorage : IPastryStorage
|
||||||
|
{
|
||||||
|
public List<PastryViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new ConfectioneryDatabase();
|
||||||
|
return context.Pastrys
|
||||||
|
.Include(x => x.Ingredients)
|
||||||
|
.ThenInclude(x => x.Ingredient)
|
||||||
|
.ToList()
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public List<PastryViewModel> GetFilteredList(PastrySearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.PastryName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new ConfectioneryDatabase();
|
||||||
|
return context.Pastrys
|
||||||
|
.Include(x => x.Ingredients)
|
||||||
|
.ThenInclude(x => x.Ingredient)
|
||||||
|
.Where(x => x.PastryName.Contains(model.PastryName))
|
||||||
|
.ToList()
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public PastryViewModel? GetElement(PastrySearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.PastryName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new ConfectioneryDatabase();
|
||||||
|
return context.Pastrys
|
||||||
|
.Include(x => x.Ingredients)
|
||||||
|
.ThenInclude(x => x.Ingredient)
|
||||||
|
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.PastryName) && x.PastryName == model.PastryName) ||
|
||||||
|
(model.Id.HasValue && x.Id == model.Id))
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
public PastryViewModel? Insert(PastryBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new ConfectioneryDatabase();
|
||||||
|
var newPastry = Pastry.Create(context, model);
|
||||||
|
if (newPastry == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
context.Pastrys.Add(newPastry);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newPastry.GetViewModel;
|
||||||
|
}
|
||||||
|
public PastryViewModel? Update(PastryBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new ConfectioneryDatabase();
|
||||||
|
using var transaction = context.Database.BeginTransaction();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var product = context.Pastrys.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (product == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
product.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
product.UpdateIngredients(context, model);
|
||||||
|
transaction.Commit();
|
||||||
|
return product.GetViewModel;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public PastryViewModel? Delete(PastryBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new ConfectioneryDatabase();
|
||||||
|
var element = context.Pastrys
|
||||||
|
.Include(x => x.Ingredients)
|
||||||
|
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Pastrys.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,190 @@
|
|||||||
|
using ConfectioneryContracts.BindingModels;
|
||||||
|
using ConfectioneryContracts.SearchModels;
|
||||||
|
using ConfectioneryContracts.StoragesContracts;
|
||||||
|
using ConfectioneryContracts.ViewModels;
|
||||||
|
using ConfectioneryDataBaseImplement.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System.Transactions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ConfectioneryDataBaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class ShopStorage : IShopStorage
|
||||||
|
{
|
||||||
|
public List<ShopViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new ConfectioneryDatabase();
|
||||||
|
return context.Shops
|
||||||
|
.Include(x => x.Pastries)
|
||||||
|
.ThenInclude(x => x.Pastry)
|
||||||
|
.ToList()
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ShopName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new ConfectioneryDatabase();
|
||||||
|
return context.Shops
|
||||||
|
.Include(x => x.Pastries)
|
||||||
|
.ThenInclude(x => x.Pastry)
|
||||||
|
.Where(x => x.ShopName.Contains(model.ShopName))
|
||||||
|
.ToList()
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public ShopViewModel? GetElement(ShopSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new ConfectioneryDatabase();
|
||||||
|
return context.Shops
|
||||||
|
.Include(x => x.Pastries)
|
||||||
|
.ThenInclude(x => x.Pastry)
|
||||||
|
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) ||
|
||||||
|
(model.Id.HasValue && x.Id == model.Id))
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
public ShopViewModel? Insert(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new ConfectioneryDatabase();
|
||||||
|
var newShop = Shop.Create(model, context);
|
||||||
|
if (newShop == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
context.Shops.Add(newShop);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newShop.GetViewModel;
|
||||||
|
}
|
||||||
|
public ShopViewModel? Update(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new ConfectioneryDatabase();
|
||||||
|
using var transaction = context.Database.BeginTransaction();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var product = context.Shops.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (product == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
product.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
product.UpdatePastries(context, model);
|
||||||
|
transaction.Commit();
|
||||||
|
return product.GetViewModel;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public ShopViewModel? Delete(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new ConfectioneryDatabase();
|
||||||
|
var element = context.Shops
|
||||||
|
.Include(x => x.Pastries)
|
||||||
|
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Shops.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Supply(int pastryId, int count)
|
||||||
|
{
|
||||||
|
using ConfectioneryDatabase context = new ConfectioneryDatabase();
|
||||||
|
var transaction = context.Database.BeginTransaction();
|
||||||
|
foreach (Shop shop in context.Shops.Include(x => x.Pastries).ThenInclude(x => x.Pastry))
|
||||||
|
{
|
||||||
|
int freeShopSpace = shop.PastryCapacity - shop.ShopPastries.Select(y => y.Value.Item2).Sum();
|
||||||
|
if (freeShopSpace > 0)
|
||||||
|
{
|
||||||
|
if (freeShopSpace >= count)
|
||||||
|
{
|
||||||
|
if (shop.ShopPastries.ContainsKey(pastryId))
|
||||||
|
{
|
||||||
|
var shopPastry = shop.ShopPastries[pastryId];
|
||||||
|
shopPastry.Item2 += count;
|
||||||
|
shop.ShopPastries[pastryId] = shopPastry;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Pastry pastry = context.Pastrys.First(x => x.Id == pastryId);
|
||||||
|
shop.ShopPastries.Add(pastryId, (pastry, count));
|
||||||
|
}
|
||||||
|
shop.RemapPastries(context);
|
||||||
|
count = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int dif = count - freeShopSpace;
|
||||||
|
count -= freeShopSpace;
|
||||||
|
if (shop.ShopPastries.TryGetValue(pastryId, out var pastryCount))
|
||||||
|
{
|
||||||
|
var shopPastry = shop.ShopPastries[pastryId];
|
||||||
|
shopPastry.Item2 = pastryCount.Item2 + freeShopSpace;
|
||||||
|
shop.ShopPastries[pastryId] = shopPastry;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Pastry pastry = context.Pastrys.First(x => x.Id == pastryId);
|
||||||
|
shop.ShopPastries.Add(pastryId, (pastry, freeShopSpace));
|
||||||
|
}
|
||||||
|
shop.RemapPastries(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (count == 0)
|
||||||
|
{
|
||||||
|
transaction.Commit();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
transaction.Rollback();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Sell(int pastryId, int count)
|
||||||
|
{
|
||||||
|
using ConfectioneryDatabase context = new ConfectioneryDatabase();
|
||||||
|
var transaction = context.Database.BeginTransaction();
|
||||||
|
foreach (Shop shop in context.Shops.Include(x => x.Pastries).ThenInclude(x => x.Pastry))
|
||||||
|
{
|
||||||
|
int shopPastryCount = shop.ShopPastries.Select(x => x.Value).Where(x => x.Item1.Id == pastryId).Sum(x => x.Item2);
|
||||||
|
if (count - shopPastryCount >= 0)
|
||||||
|
{
|
||||||
|
count -= shopPastryCount;
|
||||||
|
shop.ShopPastries.Remove(pastryId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var shopPastry = shop.ShopPastries[pastryId];
|
||||||
|
shopPastry.Item2 -= count;
|
||||||
|
count = 0;
|
||||||
|
shop.ShopPastries[pastryId] = shopPastry;
|
||||||
|
}
|
||||||
|
shop.RemapPastries(context);
|
||||||
|
}
|
||||||
|
if (count == 0)
|
||||||
|
{
|
||||||
|
transaction.Commit();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
transaction.Rollback();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
169
Confectionery/ConfectioneryDataBaseImplement/Migrations/20230306053539_InitMigration.Designer.cs
generated
Normal file
169
Confectionery/ConfectioneryDataBaseImplement/Migrations/20230306053539_InitMigration.Designer.cs
generated
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using ConfectioneryDataBaseImplement;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace ConfectioneryDataBaseImplement.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(ConfectioneryDatabase))]
|
||||||
|
[Migration("20230306053539_InitMigration")]
|
||||||
|
partial class InitMigration
|
||||||
|
{
|
||||||
|
/// <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("ConfectioneryDataBaseImplement.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("ConfectioneryDataBaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreate")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("DateImplement")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<int>("PastryId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Status")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<double>("Sum")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("PastryId");
|
||||||
|
|
||||||
|
b.ToTable("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Pastry", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("PastryName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<double>("Price")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Pastrys");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.PastryIngredient", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("IngredientId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("PastryId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("IngredientId");
|
||||||
|
|
||||||
|
b.HasIndex("PastryId");
|
||||||
|
|
||||||
|
b.ToTable("PastryIngredients");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("ConfectioneryDataBaseImplement.Models.Pastry", null)
|
||||||
|
.WithMany("Orders")
|
||||||
|
.HasForeignKey("PastryId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.PastryIngredient", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("ConfectioneryDataBaseImplement.Models.Ingredient", "Ingredient")
|
||||||
|
.WithMany("PastryIgredients")
|
||||||
|
.HasForeignKey("IngredientId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("ConfectioneryDataBaseImplement.Models.Pastry", "Pastry")
|
||||||
|
.WithMany("Ingredients")
|
||||||
|
.HasForeignKey("PastryId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Ingredient");
|
||||||
|
|
||||||
|
b.Navigation("Pastry");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Ingredient", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("PastryIgredients");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Pastry", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Ingredients");
|
||||||
|
|
||||||
|
b.Navigation("Orders");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,125 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace ConfectioneryDataBaseImplement.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class InitMigration : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
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: "Pastrys",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
PastryName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
Price = table.Column<double>(type: "float", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Pastrys", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Orders",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
PastryId = 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_Pastrys_PastryId",
|
||||||
|
column: x => x.PastryId,
|
||||||
|
principalTable: "Pastrys",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "PastryIngredients",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
PastryId = 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_PastryIngredients", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_PastryIngredients_Ingredients_IngredientId",
|
||||||
|
column: x => x.IngredientId,
|
||||||
|
principalTable: "Ingredients",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_PastryIngredients_Pastrys_PastryId",
|
||||||
|
column: x => x.PastryId,
|
||||||
|
principalTable: "Pastrys",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Orders_PastryId",
|
||||||
|
table: "Orders",
|
||||||
|
column: "PastryId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_PastryIngredients_IngredientId",
|
||||||
|
table: "PastryIngredients",
|
||||||
|
column: "IngredientId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_PastryIngredients_PastryId",
|
||||||
|
table: "PastryIngredients",
|
||||||
|
column: "PastryId");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Orders");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "PastryIngredients");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Ingredients");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Pastrys");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
246
Confectionery/ConfectioneryDataBaseImplement/Migrations/20230515043657_HardInitialCreate.Designer.cs
generated
Normal file
246
Confectionery/ConfectioneryDataBaseImplement/Migrations/20230515043657_HardInitialCreate.Designer.cs
generated
Normal file
@ -0,0 +1,246 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using ConfectioneryDataBaseImplement;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace ConfectioneryDataBaseImplement.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(ConfectioneryDatabase))]
|
||||||
|
[Migration("20230515043657_HardInitialCreate")]
|
||||||
|
partial class HardInitialCreate
|
||||||
|
{
|
||||||
|
/// <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("ConfectioneryDataBaseImplement.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("ConfectioneryDataBaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreate")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("DateImplement")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<int>("PastryId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Status")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<double>("Sum")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("PastryId");
|
||||||
|
|
||||||
|
b.ToTable("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Pastry", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("PastryName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<double>("Price")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Pastrys");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.PastryIngredient", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("IngredientId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("PastryId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("IngredientId");
|
||||||
|
|
||||||
|
b.HasIndex("PastryId");
|
||||||
|
|
||||||
|
b.ToTable("PastryIngredients");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Shop", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<DateTime>("OpeningDate")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<int>("PastryCapacity")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<string>("ShopAdress")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("ShopName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Shops");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.ShopPastry", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("PastryId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("ShopId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("PastryId");
|
||||||
|
|
||||||
|
b.HasIndex("ShopId");
|
||||||
|
|
||||||
|
b.ToTable("ShopPastries");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("ConfectioneryDataBaseImplement.Models.Pastry", null)
|
||||||
|
.WithMany("Orders")
|
||||||
|
.HasForeignKey("PastryId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.PastryIngredient", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("ConfectioneryDataBaseImplement.Models.Ingredient", "Ingredient")
|
||||||
|
.WithMany("PastryIgredients")
|
||||||
|
.HasForeignKey("IngredientId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("ConfectioneryDataBaseImplement.Models.Pastry", "Pastry")
|
||||||
|
.WithMany("Ingredients")
|
||||||
|
.HasForeignKey("PastryId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Ingredient");
|
||||||
|
|
||||||
|
b.Navigation("Pastry");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.ShopPastry", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("ConfectioneryDataBaseImplement.Models.Pastry", "Pastry")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("PastryId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("ConfectioneryDataBaseImplement.Models.Shop", "Shop")
|
||||||
|
.WithMany("Pastries")
|
||||||
|
.HasForeignKey("ShopId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Pastry");
|
||||||
|
|
||||||
|
b.Navigation("Shop");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Ingredient", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("PastryIgredients");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Pastry", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Ingredients");
|
||||||
|
|
||||||
|
b.Navigation("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Shop", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Pastries");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,78 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace ConfectioneryDataBaseImplement.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class HardInitialCreate : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Shops",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
ShopName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
ShopAdress = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
OpeningDate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||||
|
PastryCapacity = table.Column<int>(type: "int", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Shops", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "ShopPastries",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
ShopId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
PastryId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
Count = table.Column<int>(type: "int", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_ShopPastries", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_ShopPastries_Pastrys_PastryId",
|
||||||
|
column: x => x.PastryId,
|
||||||
|
principalTable: "Pastrys",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_ShopPastries_Shops_ShopId",
|
||||||
|
column: x => x.ShopId,
|
||||||
|
principalTable: "Shops",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_ShopPastries_PastryId",
|
||||||
|
table: "ShopPastries",
|
||||||
|
column: "PastryId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_ShopPastries_ShopId",
|
||||||
|
table: "ShopPastries",
|
||||||
|
column: "ShopId");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "ShopPastries");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Shops");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,243 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using ConfectioneryDataBaseImplement;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace ConfectioneryDataBaseImplement.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(ConfectioneryDatabase))]
|
||||||
|
partial class ConfectioneryDatabaseModelSnapshot : 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("ConfectioneryDataBaseImplement.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("ConfectioneryDataBaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreate")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("DateImplement")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<int>("PastryId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Status")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<double>("Sum")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("PastryId");
|
||||||
|
|
||||||
|
b.ToTable("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Pastry", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("PastryName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<double>("Price")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Pastrys");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.PastryIngredient", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("IngredientId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("PastryId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("IngredientId");
|
||||||
|
|
||||||
|
b.HasIndex("PastryId");
|
||||||
|
|
||||||
|
b.ToTable("PastryIngredients");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Shop", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<DateTime>("OpeningDate")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<int>("PastryCapacity")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<string>("ShopAdress")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("ShopName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Shops");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.ShopPastry", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("PastryId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("ShopId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("PastryId");
|
||||||
|
|
||||||
|
b.HasIndex("ShopId");
|
||||||
|
|
||||||
|
b.ToTable("ShopPastries");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("ConfectioneryDataBaseImplement.Models.Pastry", null)
|
||||||
|
.WithMany("Orders")
|
||||||
|
.HasForeignKey("PastryId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.PastryIngredient", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("ConfectioneryDataBaseImplement.Models.Ingredient", "Ingredient")
|
||||||
|
.WithMany("PastryIgredients")
|
||||||
|
.HasForeignKey("IngredientId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("ConfectioneryDataBaseImplement.Models.Pastry", "Pastry")
|
||||||
|
.WithMany("Ingredients")
|
||||||
|
.HasForeignKey("PastryId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Ingredient");
|
||||||
|
|
||||||
|
b.Navigation("Pastry");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.ShopPastry", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("ConfectioneryDataBaseImplement.Models.Pastry", "Pastry")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("PastryId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("ConfectioneryDataBaseImplement.Models.Shop", "Shop")
|
||||||
|
.WithMany("Pastries")
|
||||||
|
.HasForeignKey("ShopId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Pastry");
|
||||||
|
|
||||||
|
b.Navigation("Shop");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Ingredient", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("PastryIgredients");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Pastry", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Ingredients");
|
||||||
|
|
||||||
|
b.Navigation("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Shop", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Pastries");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
using ConfectioneryContracts.BindingModels;
|
||||||
|
using ConfectioneryContracts.ViewModels;
|
||||||
|
using ConfectioneryDataModels.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 ConfectioneryDataBaseImplement.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<PastryIngredient> PastryIgredients { 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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
65
Confectionery/ConfectioneryDataBaseImplement/Models/Order.cs
Normal file
65
Confectionery/ConfectioneryDataBaseImplement/Models/Order.cs
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
using ConfectioneryContracts.BindingModels;
|
||||||
|
using ConfectioneryContracts.ViewModels;
|
||||||
|
using ConfectioneryDataModels.Enums;
|
||||||
|
using ConfectioneryDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ConfectioneryDataBaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Order : IOrderModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
[Required]
|
||||||
|
public int PastryId { get; private set; }
|
||||||
|
[Required]
|
||||||
|
public int Count { get; private set; }
|
||||||
|
[Required]
|
||||||
|
public double Sum { get; private set; }
|
||||||
|
[Required]
|
||||||
|
public OrderStatus Status { get; private set; }
|
||||||
|
[Required]
|
||||||
|
public DateTime DateCreate { get; private set; }
|
||||||
|
public DateTime? DateImplement { get; private set; }
|
||||||
|
public static Order? Create(OrderBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Order()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
PastryId = model.PastryId,
|
||||||
|
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;
|
||||||
|
if (model.DateImplement.HasValue) DateImplement = model.DateImplement;
|
||||||
|
}
|
||||||
|
public OrderViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
PastryId = PastryId,
|
||||||
|
Count = Count,
|
||||||
|
Sum = Sum,
|
||||||
|
Status = Status,
|
||||||
|
DateCreate = DateCreate,
|
||||||
|
DateImplement = DateImplement
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,94 @@
|
|||||||
|
using ConfectioneryContracts.BindingModels;
|
||||||
|
using ConfectioneryContracts.ViewModels;
|
||||||
|
using ConfectioneryDataModels.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 ConfectioneryDataBaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Pastry : IPastryModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
[Required]
|
||||||
|
public string PastryName { get; set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public double Price { get; set; }
|
||||||
|
private Dictionary<int, (IIngredientModel, int)>? _pastryIngredients = null;
|
||||||
|
[NotMapped]
|
||||||
|
public Dictionary<int, (IIngredientModel, int)> PastryIngredients
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_pastryIngredients == null)
|
||||||
|
{
|
||||||
|
_pastryIngredients = Ingredients
|
||||||
|
.ToDictionary(recPI => recPI.IngredientId, recPI => (recPI.Ingredient as IIngredientModel, recPI.Count));
|
||||||
|
}
|
||||||
|
return _pastryIngredients;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[ForeignKey("PastryId")]
|
||||||
|
public virtual List<PastryIngredient> Ingredients { get; set; } = new();
|
||||||
|
[ForeignKey("PastryId")]
|
||||||
|
public virtual List<Order> Orders { get; set; } = new();
|
||||||
|
public static Pastry Create(ConfectioneryDatabase context, PastryBindingModel model)
|
||||||
|
{
|
||||||
|
return new Pastry()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
PastryName = model.PastryName,
|
||||||
|
Price = model.Price,
|
||||||
|
Ingredients = model.PastryIngredients.Select(x => new PastryIngredient
|
||||||
|
{
|
||||||
|
Ingredient = context.Ingredients.First(y => y.Id == x.Key),
|
||||||
|
Count = x.Value.Item2
|
||||||
|
}).ToList()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(PastryBindingModel model)
|
||||||
|
{
|
||||||
|
PastryName = model.PastryName;
|
||||||
|
Price = model.Price;
|
||||||
|
}
|
||||||
|
public PastryViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
PastryName = PastryName,
|
||||||
|
Price = Price,
|
||||||
|
PastryIngredients = PastryIngredients
|
||||||
|
};
|
||||||
|
public void UpdateIngredients(ConfectioneryDatabase context, PastryBindingModel model)
|
||||||
|
{
|
||||||
|
var pastryIngredients = context.PastryIngredients.Where(rec => rec.PastryId == model.Id).ToList();
|
||||||
|
if (pastryIngredients != null && pastryIngredients.Count > 0)
|
||||||
|
{
|
||||||
|
// удалили те, которых нет в модели
|
||||||
|
context.PastryIngredients.RemoveRange(pastryIngredients.Where(rec => !model.PastryIngredients.ContainsKey(rec.IngredientId)));
|
||||||
|
context.SaveChanges();
|
||||||
|
// обновили количество у существующих записей
|
||||||
|
foreach (var updateIngredient in pastryIngredients)
|
||||||
|
{
|
||||||
|
updateIngredient.Count = model.PastryIngredients[updateIngredient.IngredientId].Item2;
|
||||||
|
model.PastryIngredients.Remove(updateIngredient.IngredientId);
|
||||||
|
}
|
||||||
|
var pastry = context.Pastrys.First(x => x.Id == Id);
|
||||||
|
foreach (var pc in model.PastryIngredients)
|
||||||
|
{
|
||||||
|
context.PastryIngredients.Add(new PastryIngredient
|
||||||
|
{
|
||||||
|
Pastry = pastry,
|
||||||
|
Ingredient = context.Ingredients.First(x => x.Id == pc.Key),
|
||||||
|
Count = pc.Value.Item2
|
||||||
|
});
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
_pastryIngredients = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ConfectioneryDataBaseImplement.Models
|
||||||
|
{
|
||||||
|
public class PastryIngredient
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
[Required]
|
||||||
|
public int PastryId { get; set; }
|
||||||
|
[Required]
|
||||||
|
public int IngredientId { get; set; }
|
||||||
|
[Required]
|
||||||
|
public int Count { get; set; }
|
||||||
|
public virtual Ingredient Ingredient { get; set; } = new();
|
||||||
|
public virtual Pastry Pastry { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
116
Confectionery/ConfectioneryDataBaseImplement/Models/Shop.cs
Normal file
116
Confectionery/ConfectioneryDataBaseImplement/Models/Shop.cs
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
using ConfectioneryContracts.BindingModels;
|
||||||
|
using ConfectioneryContracts.ViewModels;
|
||||||
|
using ConfectioneryDataModels.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 ConfectioneryDataBaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Shop : IShopModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
[Required]
|
||||||
|
public string ShopName { get; private set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public string ShopAdress { get; private set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public DateTime OpeningDate { get; private set; }
|
||||||
|
[Required]
|
||||||
|
public int PastryCapacity { get; private set; }
|
||||||
|
private Dictionary<int, (IPastryModel, int)>? _shopPastries = null;
|
||||||
|
[NotMapped]
|
||||||
|
public Dictionary<int, (IPastryModel, int)> ShopPastries
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_shopPastries == null)
|
||||||
|
{
|
||||||
|
_shopPastries = Pastries
|
||||||
|
.ToDictionary(recSP => recSP.PastryId, recPI => (recPI.Pastry as IPastryModel, recPI.Count));
|
||||||
|
}
|
||||||
|
return _shopPastries;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[ForeignKey("ShopId")]
|
||||||
|
public virtual List<ShopPastry> Pastries { get; set; } = new();
|
||||||
|
|
||||||
|
public static Shop Create(ShopBindingModel model, ConfectioneryDatabase context)
|
||||||
|
{
|
||||||
|
return new Shop()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ShopAdress = model.ShopAdress,
|
||||||
|
ShopName = model.ShopName,
|
||||||
|
OpeningDate = model.OpeningDate,
|
||||||
|
PastryCapacity = model.PastryCapacity,
|
||||||
|
Pastries = model.ShopPastries.Select(x => new ShopPastry {
|
||||||
|
Pastry = context.Pastrys.First(y => y.Id == x.Key), Count = x.Value.Item2 }).ToList()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(ShopBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ShopName = model.ShopName;
|
||||||
|
ShopAdress = model.ShopAdress;
|
||||||
|
OpeningDate = model.OpeningDate;
|
||||||
|
PastryCapacity = model.PastryCapacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdatePastries(ConfectioneryDatabase context, ShopBindingModel model)
|
||||||
|
{
|
||||||
|
var list = context.ShopPastries.ToList();
|
||||||
|
var shopPastries = context.ShopPastries.Where(rec => rec.ShopId == model.Id).ToList();
|
||||||
|
if (shopPastries != null && shopPastries.Count > 0)
|
||||||
|
{
|
||||||
|
// удалили те, которых нет в модели
|
||||||
|
context.ShopPastries.RemoveRange(shopPastries.Where((ShopPastry rec) => !model.ShopPastries.ContainsKey(rec.PastryId)));
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
shopPastries = context.ShopPastries.Where((ShopPastry rec) => rec.ShopId == model.Id).ToList();
|
||||||
|
// обновили количество у существующих записей
|
||||||
|
foreach (var updateIngredient in shopPastries)
|
||||||
|
{
|
||||||
|
updateIngredient.Count = model.ShopPastries[updateIngredient.PastryId].Item2;
|
||||||
|
model.ShopPastries.Remove(updateIngredient.PastryId);
|
||||||
|
}
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
var shop = context.Shops.First(x => x.Id == Id);
|
||||||
|
foreach (var sp in model.ShopPastries)
|
||||||
|
{
|
||||||
|
context.ShopPastries.Add(new ShopPastry
|
||||||
|
{
|
||||||
|
Shop = shop,
|
||||||
|
Pastry = context.Pastrys.First(x => x.Id == sp.Key),
|
||||||
|
Count = sp.Value.Item2
|
||||||
|
});
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
_shopPastries = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ShopName = ShopName,
|
||||||
|
ShopAdress = ShopAdress,
|
||||||
|
ShopPastries = ShopPastries,
|
||||||
|
OpeningDate = OpeningDate,
|
||||||
|
PastryCapacity = PastryCapacity,
|
||||||
|
};
|
||||||
|
|
||||||
|
public void RemapPastries(ConfectioneryDatabase context)
|
||||||
|
{
|
||||||
|
UpdatePastries(context, new ShopBindingModel { Id = Id, ShopPastries = ShopPastries });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ConfectioneryDataBaseImplement.Models
|
||||||
|
{
|
||||||
|
public class ShopPastry
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
[Required]
|
||||||
|
public int ShopId { get; set; }
|
||||||
|
[Required]
|
||||||
|
public int PastryId { get; set; }
|
||||||
|
[Required]
|
||||||
|
public int Count { get; set; }
|
||||||
|
public virtual Shop Shop { get; set; } = new();
|
||||||
|
public virtual Pastry Pastry { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user