Лабораторная работа №3 Филиппов Д. С. ПИбд-22 #4
@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BarListImplement", "BarList
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BarFileImplement", "BarFileImplement\BarFileImplement\BarFileImplement.csproj", "{7B4E6858-4E4D-4D64-B9D4-536F8EC52412}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BarDatabaseImplement", "BarDatabaseImplement\BarDatabaseImplement\BarDatabaseImplement.csproj", "{DBBB5E6B-D6D6-4910-B97F-7568D24D66B1}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -45,6 +47,10 @@ Global
|
||||
{7B4E6858-4E4D-4D64-B9D4-536F8EC52412}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7B4E6858-4E4D-4D64-B9D4-536F8EC52412}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7B4E6858-4E4D-4D64-B9D4-536F8EC52412}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{DBBB5E6B-D6D6-4910-B97F-7568D24D66B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{DBBB5E6B-D6D6-4910-B97F-7568D24D66B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DBBB5E6B-D6D6-4910-B97F-7568D24D66B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DBBB5E6B-D6D6-4910-B97F-7568D24D66B1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -16,14 +16,9 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BarBusinessLogic\BarBusinessLogic\BarBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\BarDatabaseImplement\BarDatabaseImplement\BarDatabaseImplement.csproj" />
|
||||
<ProjectReference Include="..\BarFileImplement\BarFileImplement\BarFileImplement.csproj" />
|
||||
<ProjectReference Include="..\BarListImplement\BarListImplement\BarListImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="nlog.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
16
Bar/Bar/FormMain.Designer.cs
generated
16
Bar/Bar/FormMain.Designer.cs
generated
@ -44,7 +44,7 @@
|
||||
//
|
||||
// CreateOrderButton
|
||||
//
|
||||
this.CreateOrderButton.Location = new System.Drawing.Point(1075, 90);
|
||||
this.CreateOrderButton.Location = new System.Drawing.Point(1073, 93);
|
||||
this.CreateOrderButton.Name = "CreateOrderButton";
|
||||
this.CreateOrderButton.Size = new System.Drawing.Size(194, 40);
|
||||
this.CreateOrderButton.TabIndex = 9;
|
||||
@ -54,7 +54,7 @@
|
||||
//
|
||||
// TakeInWorkButton
|
||||
//
|
||||
this.TakeInWorkButton.Location = new System.Drawing.Point(1075, 145);
|
||||
this.TakeInWorkButton.Location = new System.Drawing.Point(1073, 148);
|
||||
this.TakeInWorkButton.Name = "TakeInWorkButton";
|
||||
this.TakeInWorkButton.Size = new System.Drawing.Size(194, 40);
|
||||
this.TakeInWorkButton.TabIndex = 10;
|
||||
@ -64,7 +64,7 @@
|
||||
//
|
||||
// ReadyButton
|
||||
//
|
||||
this.ReadyButton.Location = new System.Drawing.Point(1075, 204);
|
||||
this.ReadyButton.Location = new System.Drawing.Point(1073, 207);
|
||||
this.ReadyButton.Name = "ReadyButton";
|
||||
this.ReadyButton.Size = new System.Drawing.Size(194, 40);
|
||||
this.ReadyButton.TabIndex = 11;
|
||||
@ -74,7 +74,7 @@
|
||||
//
|
||||
// IssuedButton
|
||||
//
|
||||
this.IssuedButton.Location = new System.Drawing.Point(1075, 261);
|
||||
this.IssuedButton.Location = new System.Drawing.Point(1073, 264);
|
||||
this.IssuedButton.Name = "IssuedButton";
|
||||
this.IssuedButton.Size = new System.Drawing.Size(194, 40);
|
||||
this.IssuedButton.TabIndex = 12;
|
||||
@ -84,7 +84,7 @@
|
||||
//
|
||||
// RefreshButton
|
||||
//
|
||||
this.RefreshButton.Location = new System.Drawing.Point(1075, 322);
|
||||
this.RefreshButton.Location = new System.Drawing.Point(1073, 325);
|
||||
this.RefreshButton.Name = "RefreshButton";
|
||||
this.RefreshButton.Size = new System.Drawing.Size(194, 40);
|
||||
this.RefreshButton.TabIndex = 13;
|
||||
@ -99,7 +99,7 @@
|
||||
this.DataGridView.Name = "DataGridView";
|
||||
this.DataGridView.RowHeadersWidth = 51;
|
||||
this.DataGridView.RowTemplate.Height = 29;
|
||||
this.DataGridView.Size = new System.Drawing.Size(1042, 362);
|
||||
this.DataGridView.Size = new System.Drawing.Size(1029, 362);
|
||||
this.DataGridView.TabIndex = 14;
|
||||
//
|
||||
// menuStrip1
|
||||
@ -109,7 +109,7 @@
|
||||
this.ToolStripMenu});
|
||||
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
|
||||
this.menuStrip1.Name = "menuStrip1";
|
||||
this.menuStrip1.Size = new System.Drawing.Size(1283, 28);
|
||||
this.menuStrip1.Size = new System.Drawing.Size(1279, 28);
|
||||
this.menuStrip1.TabIndex = 15;
|
||||
this.menuStrip1.Text = "menuStrip1";
|
||||
//
|
||||
@ -140,7 +140,7 @@
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1283, 450);
|
||||
this.ClientSize = new System.Drawing.Size(1279, 450);
|
||||
this.Controls.Add(this.menuStrip1);
|
||||
this.Controls.Add(this.DataGridView);
|
||||
this.Controls.Add(this.RefreshButton);
|
||||
|
@ -1,7 +1,7 @@
|
||||
using BarBusinessLogic.BusinessLogics;
|
||||
using BarContracts.BusinessLogicContracts;
|
||||
using BarContracts.StoragesContracts;
|
||||
using BarFileImplement.Implements;
|
||||
using BarDatabaseImplement.Implements;
|
||||
using BarView.Forms;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
25
Bar/BarDatabaseImplement/BarDatabaseImplement.sln
Normal file
25
Bar/BarDatabaseImplement/BarDatabaseImplement.sln
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.1.32210.238
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BarDatabaseImplement", "BarDatabaseImplement\BarDatabaseImplement.csproj", "{281C0312-6550-4A44-8AD4-087DF7F562F1}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{281C0312-6550-4A44-8AD4-087DF7F562F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{281C0312-6550-4A44-8AD4-087DF7F562F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{281C0312-6550-4A44-8AD4-087DF7F562F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{281C0312-6550-4A44-8AD4-087DF7F562F1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {B1D89B1D-502D-4E12-98AF-F34B3DE21208}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
29
Bar/BarDatabaseImplement/BarDatabaseImplement/BarDatabase.cs
Normal file
29
Bar/BarDatabaseImplement/BarDatabaseImplement/BarDatabase.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using BarDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BarDatabaseImplement
|
||||
{
|
||||
public class BarDatabase : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder OptionsBuilder)
|
||||
{
|
||||
if (OptionsBuilder.IsConfigured == false)
|
||||
{
|
||||
OptionsBuilder.UseNpgsql(@"Host=localhost;Database=Bar;Username=postgres;Password=postgres");
|
||||
}
|
||||
|
||||
base.OnConfiguring(OptionsBuilder);
|
||||
|
||||
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
||||
AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);
|
||||
}
|
||||
|
||||
public virtual DbSet<Component> Components { set; get; }
|
||||
|
||||
public virtual DbSet<Cocktail> Cocktails { set; get; }
|
||||
|
||||
public virtual DbSet<CocktailComponent> CocktailComponents { set; get; }
|
||||
|
||||
public virtual DbSet<Order> Orders { set; get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\BarContracts\BarContracts\BarContracts.csproj" />
|
||||
<ProjectReference Include="..\..\BarDataModels\BarDataModels\BarDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,109 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.SearchModels;
|
||||
using BarContracts.StoragesContracts;
|
||||
using BarContracts.ViewModels;
|
||||
using BarDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BarDatabaseImplement.Implements
|
||||
{
|
||||
public class CocktailStorage : ICocktailStorage
|
||||
{
|
||||
public List<CocktailViewModel> GetFullList()
|
||||
{
|
||||
using var Context = new BarDatabase();
|
||||
return Context.Cocktails
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<CocktailViewModel> GetFilteredList(CocktailSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.CocktailName))
|
||||
return new();
|
||||
|
||||
using var Context = new BarDatabase();
|
||||
|
||||
return Context.Cocktails
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.Where(x => x.CocktailName.Contains(Model.CocktailName))
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public CocktailViewModel? GetElement(CocktailSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.CocktailName) && !Model.Id.HasValue)
|
||||
return null;
|
||||
|
||||
using var Context = new BarDatabase();
|
||||
|
||||
return Context.Cocktails
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(Model.CocktailName) && x.CocktailName == Model.CocktailName) ||
|
||||
(Model.Id.HasValue && x.Id == Model.Id))?
|
||||
.GetViewModel;
|
||||
}
|
||||
|
||||
public CocktailViewModel? Insert(CocktailBindingModel Model)
|
||||
{
|
||||
using var Context = new BarDatabase();
|
||||
|
||||
var NewCocktail = Cocktail.Create(Context, Model);
|
||||
if (NewCocktail == null)
|
||||
return null;
|
||||
|
||||
Context.Cocktails.Add(NewCocktail);
|
||||
Context.SaveChanges();
|
||||
|
||||
return NewCocktail.GetViewModel;
|
||||
}
|
||||
|
||||
public CocktailViewModel? Update(CocktailBindingModel Model)
|
||||
{
|
||||
using var Context = new BarDatabase();
|
||||
|
||||
using var Transaction = Context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var Cocktail = Context.Cocktails.FirstOrDefault(rec => rec.Id == Model.Id);
|
||||
|
||||
if (Cocktail == null)
|
||||
return null;
|
||||
|
||||
Cocktail.Update(Model);
|
||||
Context.SaveChanges();
|
||||
Cocktail.UpdateComponents(Context, Model);
|
||||
|
||||
Transaction.Commit();
|
||||
return Cocktail.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
Transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public CocktailViewModel? Delete(CocktailBindingModel Model)
|
||||
{
|
||||
using var Context = new BarDatabase();
|
||||
|
||||
var Cocktail = Context.Cocktails
|
||||
.Include(x => x.Components)
|
||||
.FirstOrDefault(rec => rec.Id == Model.Id);
|
||||
|
||||
if (Cocktail == null)
|
||||
return null;
|
||||
|
||||
Context.Cocktails.Remove(Cocktail);
|
||||
Context.SaveChanges();
|
||||
return Cocktail.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.SearchModels;
|
||||
using BarContracts.StoragesContracts;
|
||||
using BarContracts.ViewModels;
|
||||
using BarDatabaseImplement.Models;
|
||||
|
||||
namespace BarDatabaseImplement.Implements
|
||||
{
|
||||
public class ComponentStorage : IComponentStorage
|
||||
{
|
||||
public List<ComponentViewModel> GetFullList()
|
||||
{
|
||||
using var Context = new BarDatabase();
|
||||
return Context.Components.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.ComponentName))
|
||||
return new();
|
||||
|
||||
using var Context = new BarDatabase();
|
||||
return Context.Components
|
||||
.Where(x => x.ComponentName.Contains(Model.ComponentName))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ComponentViewModel? GetElement(ComponentSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.ComponentName) && !Model.Id.HasValue)
|
||||
return null;
|
||||
|
||||
using var Context = new BarDatabase();
|
||||
return Context.Components
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(Model.ComponentName) && x.ComponentName == Model.ComponentName) ||
|
||||
(Model.Id.HasValue && x.Id == Model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Insert(ComponentBindingModel Model)
|
||||
{
|
||||
var NewComponent = Component.Create(Model);
|
||||
|
||||
if (NewComponent == null)
|
||||
return null;
|
||||
|
||||
using var Context = new BarDatabase();
|
||||
Context.Components.Add(NewComponent);
|
||||
Context.SaveChanges();
|
||||
|
||||
return NewComponent.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Update(ComponentBindingModel Model)
|
||||
{
|
||||
using var Context = new BarDatabase();
|
||||
|
||||
var Component = Context.Components.FirstOrDefault(x => x.Id == Model.Id);
|
||||
|
||||
if (Component == null)
|
||||
return null;
|
||||
|
||||
Component.Update(Model);
|
||||
Context.SaveChanges();
|
||||
|
||||
return Component.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Delete(ComponentBindingModel Model)
|
||||
{
|
||||
using var Context = new BarDatabase();
|
||||
var Component = Context.Components.FirstOrDefault(rec => rec.Id == Model.Id);
|
||||
|
||||
if (Component == null)
|
||||
return null;
|
||||
|
||||
Context.Components.Remove(Component);
|
||||
Context.SaveChanges();
|
||||
return Component.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.SearchModels;
|
||||
using BarContracts.StoragesContracts;
|
||||
using BarContracts.ViewModels;
|
||||
using BarDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BarDatabaseImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
using var Context = new BarDatabase();
|
||||
|
||||
return Context.Orders
|
||||
.Include(x => x.Cocktail)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel Model)
|
||||
{
|
||||
if (!Model.Id.HasValue)
|
||||
return new();
|
||||
|
||||
using var Context = new BarDatabase();
|
||||
|
||||
return Context.Orders
|
||||
.Include(x => x.Cocktail)
|
||||
.Where(x => x.Id == Model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel Model)
|
||||
{
|
||||
if (!Model.Id.HasValue)
|
||||
return null;
|
||||
|
||||
using var Context = new BarDatabase();
|
||||
|
||||
return Context.Orders
|
||||
.Include(x => x.Cocktail)
|
||||
.FirstOrDefault(x => Model.Id.HasValue && x.Id == Model.Id)?
|
||||
.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel Model)
|
||||
{
|
||||
if (Model == null)
|
||||
return null;
|
||||
|
||||
var NewOrder = Order.Create(Model);
|
||||
if (NewOrder == null)
|
||||
return null;
|
||||
|
||||
using var Context = new BarDatabase();
|
||||
|
||||
Context.Orders.Add(NewOrder);
|
||||
Context.SaveChanges();
|
||||
|
||||
return Context.Orders.Include(x => x.Cocktail).FirstOrDefault(x => x.Id == NewOrder.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel Model)
|
||||
{
|
||||
using var Context = new BarDatabase();
|
||||
|
||||
var Order = Context.Orders.FirstOrDefault(x => x.Id == Model.Id);
|
||||
if (Order == null)
|
||||
return null;
|
||||
|
||||
Order.Update(Model);
|
||||
Context.SaveChanges();
|
||||
|
||||
return Context.Orders.Include(x => x.Cocktail).FirstOrDefault(x => x.Id == Model.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Delete(OrderBindingModel Model)
|
||||
{
|
||||
using var Context = new BarDatabase();
|
||||
var Order = Context.Orders.FirstOrDefault(rec => rec.Id == Model.Id);
|
||||
|
||||
if (Order == null)
|
||||
return null;
|
||||
|
||||
Context.Orders.Remove(Order);
|
||||
Context.SaveChanges();
|
||||
|
||||
return Order.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
171
Bar/BarDatabaseImplement/BarDatabaseImplement/Migrations/20240502084440_InitialCreate.Designer.cs
generated
Normal file
171
Bar/BarDatabaseImplement/BarDatabaseImplement/Migrations/20240502084440_InitialCreate.Designer.cs
generated
Normal file
@ -0,0 +1,171 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using BarDatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace BarDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(BarDatabase))]
|
||||
[Migration("20240502084440_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.0")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("BarDatabaseImplement.Models.Cocktail", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("CocktailName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Cocktails");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BarDatabaseImplement.Models.CocktailComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("CocktailId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CocktailId");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.ToTable("CocktailComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BarDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BarDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("CocktailId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CocktailId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BarDatabaseImplement.Models.CocktailComponent", b =>
|
||||
{
|
||||
b.HasOne("BarDatabaseImplement.Models.Cocktail", "Cocktail")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("CocktailId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("BarDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("CocktailComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Cocktail");
|
||||
|
||||
b.Navigation("Component");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BarDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("BarDatabaseImplement.Models.Cocktail", "Cocktail")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("CocktailId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Cocktail");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BarDatabaseImplement.Models.Cocktail", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BarDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("CocktailComponents");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,126 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace BarDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Cocktails",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
CocktailName = table.Column<string>(type: "text", nullable: false),
|
||||
Price = table.Column<double>(type: "double precision", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Cocktails", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Components",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
ComponentName = table.Column<string>(type: "text", nullable: false),
|
||||
Cost = table.Column<double>(type: "double precision", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Components", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Orders",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
CocktailId = table.Column<int>(type: "integer", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false),
|
||||
Sum = table.Column<double>(type: "double precision", nullable: false),
|
||||
Status = table.Column<int>(type: "integer", nullable: false),
|
||||
DateCreate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
|
||||
DateImplement = table.Column<DateTime>(type: "timestamp without time zone", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Orders", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Orders_Cocktails_CocktailId",
|
||||
column: x => x.CocktailId,
|
||||
principalTable: "Cocktails",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "CocktailComponents",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
CocktailId = table.Column<int>(type: "integer", nullable: false),
|
||||
ComponentId = table.Column<int>(type: "integer", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_CocktailComponents", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_CocktailComponents_Cocktails_CocktailId",
|
||||
column: x => x.CocktailId,
|
||||
principalTable: "Cocktails",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_CocktailComponents_Components_ComponentId",
|
||||
column: x => x.ComponentId,
|
||||
principalTable: "Components",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_CocktailComponents_CocktailId",
|
||||
table: "CocktailComponents",
|
||||
column: "CocktailId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_CocktailComponents_ComponentId",
|
||||
table: "CocktailComponents",
|
||||
column: "ComponentId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_CocktailId",
|
||||
table: "Orders",
|
||||
column: "CocktailId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "CocktailComponents");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Orders");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Components");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Cocktails");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,168 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using BarDatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace BarDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(BarDatabase))]
|
||||
partial class BarDatabaseModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.0")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("BarDatabaseImplement.Models.Cocktail", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("CocktailName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Cocktails");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BarDatabaseImplement.Models.CocktailComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("CocktailId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CocktailId");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.ToTable("CocktailComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BarDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BarDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("CocktailId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CocktailId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BarDatabaseImplement.Models.CocktailComponent", b =>
|
||||
{
|
||||
b.HasOne("BarDatabaseImplement.Models.Cocktail", "Cocktail")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("CocktailId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("BarDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("CocktailComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Cocktail");
|
||||
|
||||
b.Navigation("Component");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BarDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("BarDatabaseImplement.Models.Cocktail", "Cocktail")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("CocktailId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Cocktail");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BarDatabaseImplement.Models.Cocktail", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BarDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("CocktailComponents");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
112
Bar/BarDatabaseImplement/BarDatabaseImplement/Models/Cocktail.cs
Normal file
112
Bar/BarDatabaseImplement/BarDatabaseImplement/Models/Cocktail.cs
Normal file
@ -0,0 +1,112 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.ViewModels;
|
||||
using BarDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace BarDatabaseImplement.Models
|
||||
{
|
||||
public class Cocktail : ICocktailModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string CocktailName { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public double Price { get; set; }
|
||||
|
||||
private Dictionary<int, (IComponentModel, int)>? _cocktailComponents = null;
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IComponentModel, int)> CocktailComponents
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_cocktailComponents == null)
|
||||
{
|
||||
_cocktailComponents = Components.ToDictionary(RepComp => RepComp.ComponentId, RepComp =>
|
||||
(RepComp.Component as IComponentModel, RepComp.Count));
|
||||
}
|
||||
|
||||
return _cocktailComponents;
|
||||
}
|
||||
}
|
||||
|
||||
[ForeignKey("CocktailId")]
|
||||
public virtual List<CocktailComponent> Components { get; set; } = new();
|
||||
|
||||
[ForeignKey("CocktailId")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
|
||||
public static Cocktail Create(BarDatabase Context, CocktailBindingModel Model)
|
||||
{
|
||||
return new Cocktail()
|
||||
{
|
||||
Id = Model.Id,
|
||||
CocktailName = Model.CocktailName,
|
||||
Price = Model.Price,
|
||||
Components = Model.CocktailComponents.Select(x => new CocktailComponent
|
||||
{
|
||||
Component = Context.Components.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(CocktailBindingModel Model)
|
||||
{
|
||||
CocktailName = Model.CocktailName;
|
||||
Price = Model.Price;
|
||||
}
|
||||
|
||||
public CocktailViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
CocktailName = CocktailName,
|
||||
Price = Price,
|
||||
CocktailComponents = CocktailComponents
|
||||
};
|
||||
|
||||
public void UpdateComponents(BarDatabase Context, CocktailBindingModel Model)
|
||||
{
|
||||
var CocktailComponents = Context.CocktailComponents.Where(rec => rec.CocktailId == Model.Id).ToList();
|
||||
|
||||
if (CocktailComponents != null && CocktailComponents.Count > 0)
|
||||
{
|
||||
Context.CocktailComponents.RemoveRange(CocktailComponents.Where(rec => !Model.CocktailComponents.ContainsKey(rec.ComponentId)));
|
||||
Context.SaveChanges();
|
||||
|
||||
try
|
||||
{
|
||||
foreach (var ComponentToUpdate in CocktailComponents)
|
||||
{
|
||||
ComponentToUpdate.Count = Model.CocktailComponents[ComponentToUpdate.ComponentId].Item2;
|
||||
Model.CocktailComponents.Remove(ComponentToUpdate.ComponentId);
|
||||
}
|
||||
}catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Context.SaveChanges();
|
||||
}
|
||||
|
||||
var Cocktail = Context.Cocktails.First(x => x.Id == Id);
|
||||
|
||||
foreach (var CocktailComponent in Model.CocktailComponents)
|
||||
{
|
||||
Context.CocktailComponents.Add(new CocktailComponent
|
||||
{
|
||||
Cocktail = Cocktail,
|
||||
Component = Context.Components.First(x => x.Id == CocktailComponent.Key),
|
||||
Count = CocktailComponent.Value.Item2
|
||||
});
|
||||
|
||||
Context.SaveChanges();
|
||||
}
|
||||
|
||||
_cocktailComponents = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace BarDatabaseImplement.Models
|
||||
{
|
||||
public class CocktailComponent
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public int CocktailId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int ComponentId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
|
||||
public virtual Component Component { get; set; } = new();
|
||||
|
||||
public virtual Cocktail Cocktail { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.ViewModels;
|
||||
using BarDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace BarDatabaseImplement.Models
|
||||
{
|
||||
public class Component : IComponentModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
public string ComponentName { get; private set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public double Cost { get; set; }
|
||||
|
||||
[ForeignKey("ComponentId")]
|
||||
public virtual List<CocktailComponent> CocktailComponents { get; set; } = new();
|
||||
|
||||
public static Component? Create(ComponentBindingModel Model)
|
||||
{
|
||||
if (Model == null)
|
||||
return null;
|
||||
|
||||
return new Component()
|
||||
{
|
||||
Id = Model.Id,
|
||||
ComponentName = Model.ComponentName,
|
||||
Cost = Model.Cost
|
||||
};
|
||||
}
|
||||
|
||||
public static Component Create(ComponentViewModel Model)
|
||||
{
|
||||
return new Component
|
||||
{
|
||||
Id = Model.Id,
|
||||
ComponentName = Model.ComponentName,
|
||||
Cost = Model.Cost
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ComponentBindingModel Model)
|
||||
{
|
||||
if (Model == null)
|
||||
return;
|
||||
|
||||
ComponentName = Model.ComponentName;
|
||||
Cost = Model.Cost;
|
||||
}
|
||||
|
||||
public ComponentViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ComponentName = ComponentName,
|
||||
Cost = Cost
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.ViewModels;
|
||||
using BarDataModels.Enums;
|
||||
using BarDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
namespace BarDatabaseImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
public int CocktailId { get; private set; }
|
||||
|
||||
public virtual Cocktail Cocktail { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; private set; }
|
||||
|
||||
[Required]
|
||||
public double Sum { get; private set; }
|
||||
|
||||
[Required]
|
||||
public OrderStatus Status { get; private set; } = OrderStatus.Undefined;
|
||||
|
||||
[Required]
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel Model)
|
||||
{
|
||||
if (Model is null)
|
||||
return null;
|
||||
|
||||
return new Order()
|
||||
{
|
||||
Id = Model.Id,
|
||||
CocktailId = Model.CocktailId,
|
||||
Count = Model.Count,
|
||||
Sum = Model.Sum,
|
||||
Status = Model.Status,
|
||||
DateCreate = Model.DateCreate,
|
||||
DateImplement = Model.DateImplement,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(OrderBindingModel Model)
|
||||
{
|
||||
if (Model is null)
|
||||
return;
|
||||
|
||||
Status = Model.Status;
|
||||
DateImplement = Model.DateImplement;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
CocktailId = CocktailId,
|
||||
CocktailName = Cocktail.CocktailName,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user