Compare commits

..

3 Commits

44 changed files with 1332 additions and 181 deletions

View File

@ -3,15 +3,17 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.9.34714.143 VisualStudioVersion = 17.9.34714.143
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarView", "SushiBar\SushiBarView.csproj", "{2B4A5A98-6D06-4461-8D41-363CED12B9C2}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarView", "SushiBar\SushiBarView.csproj", "{2B4A5A98-6D06-4461-8D41-363CED12B9C2}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarDataModels", "SushiBarDataModels\SushiBarDataModels.csproj", "{C373ED9F-747E-47D0-9B7C-B65E062CD537}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarDataModels", "SushiBarDataModels\SushiBarDataModels.csproj", "{C373ED9F-747E-47D0-9B7C-B65E062CD537}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarContracts", "SushiBarContracts\SushiBarContracts.csproj", "{1FD289B3-1422-4535-8969-2F320754517B}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarContracts", "SushiBarContracts\SushiBarContracts.csproj", "{1FD289B3-1422-4535-8969-2F320754517B}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarBusinessLogic", "SushiBarBusinessLogic\SushiBarBusinessLogic.csproj", "{9CB0FFA6-FA25-440C-8B6A-B6DF2F0639F5}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarBusinessLogic", "SushiBarBusinessLogic\SushiBarBusinessLogic.csproj", "{9CB0FFA6-FA25-440C-8B6A-B6DF2F0639F5}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarDatabaseImplement", "SushiBarDatabaseImplement\SushiBarDatabaseImplement.csproj", "{E62F051D-30D6-4F1C-B02E-C814B7D03F86}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarDatabaseImplement", "SushiBarDatabaseImplement\SushiBarDatabaseImplement.csproj", "{E62F051D-30D6-4F1C-B02E-C814B7D03F86}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarMongoDB", "SushiBarMongoDB\SushiBarMongoDB.csproj", "{5D2CA124-F7FE-4654-B3F2-D9A09EB079EC}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -39,6 +41,10 @@ Global
{E62F051D-30D6-4F1C-B02E-C814B7D03F86}.Debug|Any CPU.Build.0 = Debug|Any CPU {E62F051D-30D6-4F1C-B02E-C814B7D03F86}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E62F051D-30D6-4F1C-B02E-C814B7D03F86}.Release|Any CPU.ActiveCfg = Release|Any CPU {E62F051D-30D6-4F1C-B02E-C814B7D03F86}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E62F051D-30D6-4F1C-B02E-C814B7D03F86}.Release|Any CPU.Build.0 = Release|Any CPU {E62F051D-30D6-4F1C-B02E-C814B7D03F86}.Release|Any CPU.Build.0 = Release|Any CPU
{5D2CA124-F7FE-4654-B3F2-D9A09EB079EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5D2CA124-F7FE-4654-B3F2-D9A09EB079EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5D2CA124-F7FE-4654-B3F2-D9A09EB079EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5D2CA124-F7FE-4654-B3F2-D9A09EB079EC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -108,7 +108,6 @@ namespace SushiBarView
{ {
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
if (form.MenuModel == null) if (form.MenuModel == null)
{ {
return; return;
@ -177,6 +176,12 @@ namespace SushiBarView
} }
try try
{ {
List<int> ids = new List<int>();
foreach (int id in _taskMenu.Keys)
{
ids.Add(id);
}
var model = new TaskBindingModel var model = new TaskBindingModel
{ {
Id = _id ?? 0, Id = _id ?? 0,
@ -185,18 +190,15 @@ namespace SushiBarView
FullPrice = CalcPrice(), FullPrice = CalcPrice(),
CookId = comboBoxCook.SelectedIndex+1, CookId = comboBoxCook.SelectedIndex+1,
BuyerId = comboBoxBuyer.SelectedIndex+1, BuyerId = comboBoxBuyer.SelectedIndex+1,
PlaceId = comboBoxPlace.SelectedIndex + 1, PlaceId = comboBoxPlace.SelectedIndex+1,
TaskMenus = _taskMenu TaskMenus = _taskMenu,
MenuIds = ids,
}; };
DateTime start = DateTime.Now;
var operationResult = _id.HasValue ? _logicT.Update(model) : _logicT.Create(model); var operationResult = _id.HasValue ? _logicT.Update(model) : _logicT.Create(model);
if (!operationResult) if (!operationResult)
{ {
throw new Exception("Ошибка при сохранении. Доп информация в логах"); throw new Exception("Ошибка при сохранении. Доп информация в логах");
} }
DateTime stop = DateTime.Now;
MessageBox.Show((stop - start).ToString(), "Test", MessageBoxButtons.OK);
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;
Close(); Close();

View File

@ -40,6 +40,7 @@
buttonCreateTask = new Button(); buttonCreateTask = new Button();
dataGridView = new DataGridView(); dataGridView = new DataGridView();
buttonTest = new Button(); buttonTest = new Button();
buttonPsqlToMongo = new Button();
menuStrip1.SuspendLayout(); menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout(); SuspendLayout();
@ -49,8 +50,7 @@
menuStrip1.Items.AddRange(new ToolStripItem[] { объектыToolStripMenuItem }); menuStrip1.Items.AddRange(new ToolStripItem[] { объектыToolStripMenuItem });
menuStrip1.Location = new Point(0, 0); menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1"; menuStrip1.Name = "menuStrip1";
menuStrip1.Padding = new Padding(7, 3, 0, 3); menuStrip1.Size = new Size(1214, 24);
menuStrip1.Size = new Size(1387, 30);
menuStrip1.TabIndex = 0; menuStrip1.TabIndex = 0;
menuStrip1.Text = "menuStrip1"; menuStrip1.Text = "menuStrip1";
// //
@ -58,43 +58,42 @@
// //
объектыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { buyerToolStripMenuItem, cookToolStripMenuItem, menuToolStripMenuItem, placeToolStripMenuItem }); объектыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { buyerToolStripMenuItem, cookToolStripMenuItem, menuToolStripMenuItem, placeToolStripMenuItem });
объектыToolStripMenuItem.Name = "объектыToolStripMenuItem"; объектыToolStripMenuItem.Name = "объектыToolStripMenuItem";
объектыToolStripMenuItem.Size = new Size(82, 24); объектыToolStripMenuItem.Size = new Size(68, 20);
объектыToolStripMenuItem.Text = "Объекты"; объектыToolStripMenuItem.Text = "Объекты";
// //
// buyerToolStripMenuItem // buyerToolStripMenuItem
// //
buyerToolStripMenuItem.Name = "buyerToolStripMenuItem"; buyerToolStripMenuItem.Name = "buyerToolStripMenuItem";
buyerToolStripMenuItem.Size = new Size(159, 24); buyerToolStripMenuItem.Size = new Size(139, 22);
buyerToolStripMenuItem.Text = "Покупатель"; buyerToolStripMenuItem.Text = "Покупатель";
buyerToolStripMenuItem.Click += buyerToolStripMenuItem_Click; buyerToolStripMenuItem.Click += buyerToolStripMenuItem_Click;
// //
// cookToolStripMenuItem // cookToolStripMenuItem
// //
cookToolStripMenuItem.Name = "cookToolStripMenuItem"; cookToolStripMenuItem.Name = "cookToolStripMenuItem";
cookToolStripMenuItem.Size = new Size(159, 24); cookToolStripMenuItem.Size = new Size(139, 22);
cookToolStripMenuItem.Text = "Повар"; cookToolStripMenuItem.Text = "Повар";
cookToolStripMenuItem.Click += cookToolStripMenuItem_Click; cookToolStripMenuItem.Click += cookToolStripMenuItem_Click;
// //
// menuToolStripMenuItem // menuToolStripMenuItem
// //
menuToolStripMenuItem.Name = "menuToolStripMenuItem"; menuToolStripMenuItem.Name = "menuToolStripMenuItem";
menuToolStripMenuItem.Size = new Size(159, 24); menuToolStripMenuItem.Size = new Size(139, 22);
menuToolStripMenuItem.Text = "Меню"; menuToolStripMenuItem.Text = "Меню";
menuToolStripMenuItem.Click += menuToolStripMenuItem_Click; menuToolStripMenuItem.Click += menuToolStripMenuItem_Click;
// //
// placeToolStripMenuItem // placeToolStripMenuItem
// //
placeToolStripMenuItem.Name = "placeToolStripMenuItem"; placeToolStripMenuItem.Name = "placeToolStripMenuItem";
placeToolStripMenuItem.Size = new Size(159, 24); placeToolStripMenuItem.Size = new Size(139, 22);
placeToolStripMenuItem.Text = "Столик"; placeToolStripMenuItem.Text = "Столик";
placeToolStripMenuItem.Click += placeToolStripMenuItem_Click; placeToolStripMenuItem.Click += placeToolStripMenuItem_Click;
// //
// buttonIssuedTask // buttonIssuedTask
// //
buttonIssuedTask.Location = new Point(1106, 275); buttonIssuedTask.Location = new Point(968, 206);
buttonIssuedTask.Margin = new Padding(3, 4, 3, 4);
buttonIssuedTask.Name = "buttonIssuedTask"; buttonIssuedTask.Name = "buttonIssuedTask";
buttonIssuedTask.Size = new Size(226, 37); buttonIssuedTask.Size = new Size(198, 28);
buttonIssuedTask.TabIndex = 11; buttonIssuedTask.TabIndex = 11;
buttonIssuedTask.Text = "Заказ выдан"; buttonIssuedTask.Text = "Заказ выдан";
buttonIssuedTask.UseVisualStyleBackColor = true; buttonIssuedTask.UseVisualStyleBackColor = true;
@ -102,10 +101,9 @@
// //
// buttonTaskReady // buttonTaskReady
// //
buttonTaskReady.Location = new Point(1106, 205); buttonTaskReady.Location = new Point(968, 154);
buttonTaskReady.Margin = new Padding(3, 4, 3, 4);
buttonTaskReady.Name = "buttonTaskReady"; buttonTaskReady.Name = "buttonTaskReady";
buttonTaskReady.Size = new Size(226, 37); buttonTaskReady.Size = new Size(198, 28);
buttonTaskReady.TabIndex = 10; buttonTaskReady.TabIndex = 10;
buttonTaskReady.Text = "Заказ готов"; buttonTaskReady.Text = "Заказ готов";
buttonTaskReady.UseVisualStyleBackColor = true; buttonTaskReady.UseVisualStyleBackColor = true;
@ -113,10 +111,9 @@
// //
// buttonTakeTaskInWork // buttonTakeTaskInWork
// //
buttonTakeTaskInWork.Location = new Point(1106, 133); buttonTakeTaskInWork.Location = new Point(968, 100);
buttonTakeTaskInWork.Margin = new Padding(3, 4, 3, 4);
buttonTakeTaskInWork.Name = "buttonTakeTaskInWork"; buttonTakeTaskInWork.Name = "buttonTakeTaskInWork";
buttonTakeTaskInWork.Size = new Size(226, 37); buttonTakeTaskInWork.Size = new Size(198, 28);
buttonTakeTaskInWork.TabIndex = 9; buttonTakeTaskInWork.TabIndex = 9;
buttonTakeTaskInWork.Text = "Отдать на выполнение"; buttonTakeTaskInWork.Text = "Отдать на выполнение";
buttonTakeTaskInWork.UseVisualStyleBackColor = true; buttonTakeTaskInWork.UseVisualStyleBackColor = true;
@ -124,10 +121,9 @@
// //
// buttonCreateTask // buttonCreateTask
// //
buttonCreateTask.Location = new Point(1106, 61); buttonCreateTask.Location = new Point(968, 46);
buttonCreateTask.Margin = new Padding(3, 4, 3, 4);
buttonCreateTask.Name = "buttonCreateTask"; buttonCreateTask.Name = "buttonCreateTask";
buttonCreateTask.Size = new Size(226, 37); buttonCreateTask.Size = new Size(198, 28);
buttonCreateTask.TabIndex = 8; buttonCreateTask.TabIndex = 8;
buttonCreateTask.Text = "Создать заказ"; buttonCreateTask.Text = "Создать заказ";
buttonCreateTask.UseVisualStyleBackColor = true; buttonCreateTask.UseVisualStyleBackColor = true;
@ -139,31 +135,40 @@
dataGridView.BackgroundColor = Color.White; dataGridView.BackgroundColor = Color.White;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Dock = DockStyle.Left; dataGridView.Dock = DockStyle.Left;
dataGridView.Location = new Point(0, 30); dataGridView.Location = new Point(0, 24);
dataGridView.Margin = new Padding(3, 4, 3, 4);
dataGridView.Name = "dataGridView"; dataGridView.Name = "dataGridView";
dataGridView.ReadOnly = true; dataGridView.ReadOnly = true;
dataGridView.RowHeadersVisible = false; dataGridView.RowHeadersVisible = false;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(1049, 570); dataGridView.Size = new Size(918, 426);
dataGridView.TabIndex = 7; dataGridView.TabIndex = 7;
// //
// buttonTest // buttonTest
// //
buttonTest.Location = new Point(1106, 349); buttonTest.Location = new Point(968, 262);
buttonTest.Margin = new Padding(3, 4, 3, 4);
buttonTest.Name = "buttonTest"; buttonTest.Name = "buttonTest";
buttonTest.Size = new Size(226, 37); buttonTest.Size = new Size(198, 28);
buttonTest.TabIndex = 12; buttonTest.TabIndex = 12;
buttonTest.Text = "ТЕСТ"; buttonTest.Text = "Удалить все данные";
buttonTest.UseVisualStyleBackColor = true; buttonTest.UseVisualStyleBackColor = true;
buttonTest.Click += buttonTest_Click; buttonTest.Click += buttonTest_Click;
// //
// buttonPsqlToMongo
//
buttonPsqlToMongo.Location = new Point(968, 309);
buttonPsqlToMongo.Name = "buttonPsqlToMongo";
buttonPsqlToMongo.Size = new Size(198, 42);
buttonPsqlToMongo.TabIndex = 13;
buttonPsqlToMongo.Text = "Перенести все данные на MongoDB";
buttonPsqlToMongo.UseVisualStyleBackColor = true;
buttonPsqlToMongo.Click += buttonPsqlToMongo_Click;
//
// FormMain // FormMain
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1387, 600); ClientSize = new Size(1214, 450);
Controls.Add(buttonPsqlToMongo);
Controls.Add(buttonTest); Controls.Add(buttonTest);
Controls.Add(buttonIssuedTask); Controls.Add(buttonIssuedTask);
Controls.Add(buttonTaskReady); Controls.Add(buttonTaskReady);
@ -172,7 +177,6 @@
Controls.Add(dataGridView); Controls.Add(dataGridView);
Controls.Add(menuStrip1); Controls.Add(menuStrip1);
MainMenuStrip = menuStrip1; MainMenuStrip = menuStrip1;
Margin = new Padding(3, 4, 3, 4);
Name = "FormMain"; Name = "FormMain";
Text = "Главное окно"; Text = "Главное окно";
Load += FormMain_Load; Load += FormMain_Load;
@ -197,5 +201,6 @@
private Button buttonCreateTask; private Button buttonCreateTask;
private DataGridView dataGridView; private DataGridView dataGridView;
private Button buttonTest; private Button buttonTest;
private Button buttonPsqlToMongo;
} }
} }

View File

@ -1,6 +1,7 @@
using SushiBar; using SushiBar;
using SushiBarContracts.BindingModels; using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicContracts; using SushiBarContracts.BusinessLogicContracts;
using SushiBarMongoDB;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
@ -16,14 +17,21 @@ namespace SushiBarView
public partial class FormMain : Form public partial class FormMain : Form
{ {
private readonly ITaskLogic _logic; private readonly ITaskLogic _TaskLogic;
private readonly ICookLogic _CLogic; private readonly ICookLogic _CookLogic;
private readonly IBuyerLogic _BuyerLogic;
private readonly IMenuLogic _MenuLogic;
private readonly IPlaceLogic _PlaceLogic;
public FormMain(ITaskLogic logic, ICookLogic cLogic)
public FormMain(ITaskLogic logic, ICookLogic cLogic, IBuyerLogic buyerLogic, IMenuLogic menuLogic, IPlaceLogic placeLogic)
{ {
InitializeComponent(); InitializeComponent();
_logic = logic; _TaskLogic = logic;
_CLogic = cLogic; _CookLogic = cLogic;
_BuyerLogic = buyerLogic;
_MenuLogic = menuLogic;
_PlaceLogic = placeLogic;
} }
private void buyerToolStripMenuItem_Click(object sender, EventArgs e) private void buyerToolStripMenuItem_Click(object sender, EventArgs e)
@ -69,12 +77,7 @@ namespace SushiBarView
private void LoadData() private void LoadData()
{ {
DateTime start = DateTime.Now; var _list = _TaskLogic.ReadList(null);
var _list = _logic.ReadList(null);
DateTime stop = DateTime.Now;
MessageBox.Show((stop - start).ToString(), "Test", MessageBoxButtons.OK);
if (_list != null) if (_list != null)
{ {
dataGridView.DataSource = _list; dataGridView.DataSource = _list;
@ -102,7 +105,7 @@ namespace SushiBarView
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
try try
{ {
var operationResult = _logic.TakeTaskInWork(new TaskBindingModel var operationResult = _TaskLogic.TakeTaskInWork(new TaskBindingModel
{ {
Id = id, Id = id,
Status = Enum.Parse<SushiBarDataModels.Enum.TaskStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), Status = Enum.Parse<SushiBarDataModels.Enum.TaskStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
@ -127,7 +130,7 @@ namespace SushiBarView
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
try try
{ {
var operationResult = _logic.FinishTask(new TaskBindingModel var operationResult = _TaskLogic.FinishTask(new TaskBindingModel
{ {
Id = id, Id = id,
Status = Enum.Parse<SushiBarDataModels.Enum.TaskStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), Status = Enum.Parse<SushiBarDataModels.Enum.TaskStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
@ -152,7 +155,7 @@ namespace SushiBarView
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
try try
{ {
var operationResult = _logic.DeliveryTask(new TaskBindingModel var operationResult = _TaskLogic.DeliveryTask(new TaskBindingModel
{ {
Id = id, Id = id,
Status = Enum.Parse<SushiBarDataModels.Enum.TaskStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), Status = Enum.Parse<SushiBarDataModels.Enum.TaskStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
@ -173,21 +176,21 @@ namespace SushiBarView
private void buttonTest_Click(object sender, EventArgs e) private void buttonTest_Click(object sender, EventArgs e)
{ {
TaskBindingModel model = new TaskBindingModel() try
{ {
Id = 1 _BuyerLogic.ClearEntity();
}; _CookLogic.ClearEntity();
_MenuLogic.ClearEntity();
_PlaceLogic.ClearEntity();
_TaskLogic.ClearEntity();
LoadData();
}
catch (Exception) { }
}
DateTime start = DateTime.Now; private void buttonPsqlToMongo_Click(object sender, EventArgs e)
_logic.Delete(model); {
PostgresToMongo.Convert();
DateTime stop = DateTime.Now;
MessageBox.Show((stop - start).ToString(), "Test", MessageBoxButtons.OK);
} }
} }
} }
//public string CookSurname { get; set; } = string.Empty;
//public int Experience { get; set; }
//public string PhoneNumber { get; set; } = string.Empty;
//public string Passport { get; set; } = string.Empty;

View File

@ -4,6 +4,7 @@ using SushiBarBusinessLogic.BusinessLogics;
using SushiBarContracts.BusinessLogicContracts; using SushiBarContracts.BusinessLogicContracts;
using SushiBarContracts.StoragesContracts; using SushiBarContracts.StoragesContracts;
using SushiBarDatabaseImplement.Implements; using SushiBarDatabaseImplement.Implements;
//using SushiBarMongoDB.Implements;
using SushiBarView; using SushiBarView;
namespace SushiBar namespace SushiBar

View File

@ -23,6 +23,7 @@
<ProjectReference Include="..\SushiBarContracts\SushiBarContracts.csproj" /> <ProjectReference Include="..\SushiBarContracts\SushiBarContracts.csproj" />
<ProjectReference Include="..\SushiBarDatabaseImplement\SushiBarDatabaseImplement.csproj" /> <ProjectReference Include="..\SushiBarDatabaseImplement\SushiBarDatabaseImplement.csproj" />
<ProjectReference Include="..\SushiBarDataModels\SushiBarDataModels.csproj" /> <ProjectReference Include="..\SushiBarDataModels\SushiBarDataModels.csproj" />
<ProjectReference Include="..\SushiBarMongoDB\SushiBarMongoDB.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -90,5 +90,10 @@ namespace SushiBarBusinessLogic.BusinessLogics
throw new ArgumentNullException("Нет названия", nameof(model.BuyerName)); throw new ArgumentNullException("Нет названия", nameof(model.BuyerName));
} }
} }
public void ClearEntity()
{
_buyerStorage.ClearEntity();
}
} }
} }

View File

@ -56,6 +56,7 @@ namespace SushiBarBusinessLogic.BusinessLogics
public bool Delete(CookBindingModel model) public bool Delete(CookBindingModel model)
{ {
CheckModel(model, false);
if (_cookStorage.Delete(model) == null) if (_cookStorage.Delete(model) == null)
{ {
return false; return false;
@ -88,5 +89,10 @@ namespace SushiBarBusinessLogic.BusinessLogics
throw new ArgumentNullException("Нет названия", nameof(model.CookName)); throw new ArgumentNullException("Нет названия", nameof(model.CookName));
} }
} }
public void ClearEntity()
{
_cookStorage.ClearEntity();
}
} }
} }

View File

@ -89,5 +89,10 @@ namespace SushiBarBusinessLogic.BusinessLogics
throw new ArgumentNullException("Нет названия", nameof(model.FoodName)); throw new ArgumentNullException("Нет названия", nameof(model.FoodName));
} }
} }
public void ClearEntity()
{
_menuStorage.ClearEntity();
}
} }
} }

View File

@ -89,5 +89,10 @@ namespace SushiBarBusinessLogic.BusinessLogics
throw new ArgumentNullException("Нет названия", nameof(model.PlaceNumber)); throw new ArgumentNullException("Нет названия", nameof(model.PlaceNumber));
} }
} }
public void ClearEntity()
{
_placeStorage.ClearEntity();
}
} }
} }

View File

@ -116,5 +116,10 @@ namespace SushiBarBusinessLogic.BusinessLogics
return; return;
} }
} }
public void ClearEntity()
{
_taskStorage.ClearEntity();
}
} }
} }

View File

@ -23,6 +23,8 @@ namespace SushiBarContracts.BindingModels
public int BuyerId { get; set; } public int BuyerId { get; set; }
public List<int> MenuIds { get; set; } = new List<int>();
public Dictionary<int, (IMenuModel, int)> TaskMenus { get; set; } = new(); public Dictionary<int, (IMenuModel, int)> TaskMenus { get; set; } = new();
} }

View File

@ -17,5 +17,6 @@ namespace SushiBarContracts.BusinessLogicContracts
bool Create(BuyerBindingModel model); bool Create(BuyerBindingModel model);
bool Update(BuyerBindingModel model); bool Update(BuyerBindingModel model);
bool Delete(BuyerBindingModel model); bool Delete(BuyerBindingModel model);
void ClearEntity();
} }
} }

View File

@ -17,5 +17,6 @@ namespace SushiBarContracts.BusinessLogicContracts
bool Create(CookBindingModel model); bool Create(CookBindingModel model);
bool Update(CookBindingModel model); bool Update(CookBindingModel model);
bool Delete(CookBindingModel model); bool Delete(CookBindingModel model);
void ClearEntity();
} }
} }

View File

@ -17,5 +17,6 @@ namespace SushiBarContracts.BusinessLogicContracts
bool Create(MenuBindingModel model); bool Create(MenuBindingModel model);
bool Update(MenuBindingModel model); bool Update(MenuBindingModel model);
bool Delete(MenuBindingModel model); bool Delete(MenuBindingModel model);
void ClearEntity();
} }
} }

View File

@ -17,5 +17,6 @@ namespace SushiBarContracts.BusinessLogicContracts
bool Create(PlaceBindingModel model); bool Create(PlaceBindingModel model);
bool Update(PlaceBindingModel model); bool Update(PlaceBindingModel model);
bool Delete(PlaceBindingModel model); bool Delete(PlaceBindingModel model);
void ClearEntity();
} }
} }

View File

@ -20,5 +20,6 @@ namespace SushiBarContracts.BusinessLogicContracts
bool TakeTaskInWork(TaskBindingModel model); bool TakeTaskInWork(TaskBindingModel model);
bool FinishTask(TaskBindingModel model); bool FinishTask(TaskBindingModel model);
bool DeliveryTask(TaskBindingModel model); bool DeliveryTask(TaskBindingModel model);
void ClearEntity();
} }
} }

View File

@ -18,5 +18,6 @@ namespace SushiBarContracts.StoragesContracts
BuyerViewModel? Insert(BuyerBindingModel model); BuyerViewModel? Insert(BuyerBindingModel model);
BuyerViewModel? Update(BuyerBindingModel model); BuyerViewModel? Update(BuyerBindingModel model);
BuyerViewModel? Delete(BuyerBindingModel model); BuyerViewModel? Delete(BuyerBindingModel model);
void ClearEntity();
} }
} }

View File

@ -18,5 +18,6 @@ namespace SushiBarContracts.StoragesContracts
CookViewModel? Insert(CookBindingModel model); CookViewModel? Insert(CookBindingModel model);
CookViewModel? Update(CookBindingModel model); CookViewModel? Update(CookBindingModel model);
CookViewModel? Delete(CookBindingModel model); CookViewModel? Delete(CookBindingModel model);
void ClearEntity();
} }
} }

View File

@ -18,5 +18,6 @@ namespace SushiBarContracts.StoragesContracts
MenuViewModel? Insert(MenuBindingModel model); MenuViewModel? Insert(MenuBindingModel model);
MenuViewModel? Update(MenuBindingModel model); MenuViewModel? Update(MenuBindingModel model);
MenuViewModel? Delete(MenuBindingModel model); MenuViewModel? Delete(MenuBindingModel model);
void ClearEntity();
} }
} }

View File

@ -18,5 +18,6 @@ namespace SushiBarContracts.StoragesContracts
PlaceViewModel? Insert(PlaceBindingModel model); PlaceViewModel? Insert(PlaceBindingModel model);
PlaceViewModel? Update(PlaceBindingModel model); PlaceViewModel? Update(PlaceBindingModel model);
PlaceViewModel? Delete(PlaceBindingModel model); PlaceViewModel? Delete(PlaceBindingModel model);
void ClearEntity();
} }
} }

View File

@ -18,5 +18,6 @@ namespace SushiBarContracts.StoragesContracts
TaskViewModel? Insert(TaskBindingModel model); TaskViewModel? Insert(TaskBindingModel model);
TaskViewModel? Update(TaskBindingModel model); TaskViewModel? Update(TaskBindingModel model);
TaskViewModel? Delete(TaskBindingModel model); TaskViewModel? Delete(TaskBindingModel model);
void ClearEntity();
} }
} }

View File

@ -1,4 +1,5 @@
using SushiBarContracts.BindingModels; using Microsoft.EntityFrameworkCore;
using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels; using SushiBarContracts.SearchModels;
using SushiBarContracts.StoragesContracts; using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels; using SushiBarContracts.ViewModels;
@ -74,5 +75,13 @@ namespace SushiBarDatabaseImplement.Implements
context.SaveChanges(); context.SaveChanges();
return component.GetViewModel; return component.GetViewModel;
} }
public void ClearEntity()
{
using var context = new SushiBarDatabase();
string deleteAllQuery = "DELETE FROM \"Buyers\"";
context.Database.ExecuteSqlRaw(deleteAllQuery);
}
} }
} }

View File

@ -1,4 +1,5 @@
using SushiBarContracts.BindingModels; using Microsoft.EntityFrameworkCore;
using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels; using SushiBarContracts.SearchModels;
using SushiBarContracts.StoragesContracts; using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels; using SushiBarContracts.ViewModels;
@ -14,6 +15,14 @@ namespace SushiBarDatabaseImplement.Implements
{ {
public class CookStorage : ICookStorage public class CookStorage : ICookStorage
{ {
public void ClearEntity()
{
using var context = new SushiBarDatabase();
string deleteAllQuery = "DELETE FROM \"Cooks\"";
context.Database.ExecuteSqlRaw(deleteAllQuery);
}
public CookViewModel? Delete(CookBindingModel model) public CookViewModel? Delete(CookBindingModel model)
{ {
using var context = new SushiBarDatabase(); using var context = new SushiBarDatabase();

View File

@ -1,4 +1,5 @@
using SushiBarContracts.BindingModels; using Microsoft.EntityFrameworkCore;
using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels; using SushiBarContracts.SearchModels;
using SushiBarContracts.StoragesContracts; using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels; using SushiBarContracts.ViewModels;
@ -14,6 +15,14 @@ namespace SushiBarDatabaseImplement.Implements
{ {
public class MenuStorage : IMenuStorage public class MenuStorage : IMenuStorage
{ {
public void ClearEntity()
{
using var context = new SushiBarDatabase();
string deleteAllQuery = "DELETE FROM \"Menus\"";
context.Database.ExecuteSqlRaw(deleteAllQuery);
}
public MenuViewModel? Delete(MenuBindingModel model) public MenuViewModel? Delete(MenuBindingModel model)
{ {
using var context = new SushiBarDatabase(); using var context = new SushiBarDatabase();

View File

@ -1,4 +1,5 @@
using SushiBarContracts.BindingModels; using Microsoft.EntityFrameworkCore;
using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels; using SushiBarContracts.SearchModels;
using SushiBarContracts.StoragesContracts; using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels; using SushiBarContracts.ViewModels;
@ -14,6 +15,14 @@ namespace SushiBarDatabaseImplement.Implements
{ {
public class PlaceStorage : IPlaceStorage public class PlaceStorage : IPlaceStorage
{ {
public void ClearEntity()
{
using var context = new SushiBarDatabase();
string deleteAllQuery = "DELETE FROM \"Places\"";
context.Database.ExecuteSqlRaw(deleteAllQuery);
}
public PlaceViewModel? Delete(PlaceBindingModel model) public PlaceViewModel? Delete(PlaceBindingModel model)
{ {
using var context = new SushiBarDatabase(); using var context = new SushiBarDatabase();

View File

@ -13,6 +13,14 @@ namespace SushiBarDatabaseImplement.Implements
{ {
public class TaskStorage : ITaskStorage public class TaskStorage : ITaskStorage
{ {
public void ClearEntity()
{
using var context = new SushiBarDatabase();
string deleteAllQuery = "DELETE FROM \"Tasks\"";
context.Database.ExecuteSqlRaw(deleteAllQuery);
}
public TaskViewModel? Delete(TaskBindingModel model) public TaskViewModel? Delete(TaskBindingModel model)
{ {
using var context = new SushiBarDatabase(); using var context = new SushiBarDatabase();

View File

@ -2,9 +2,9 @@
using System; using System;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using SushiBarDatabaseImplement; using SushiBarDatabaseImplement;
#nullable disable #nullable disable
@ -12,8 +12,8 @@ using SushiBarDatabaseImplement;
namespace SushiBarDatabaseImplement.Migrations namespace SushiBarDatabaseImplement.Migrations
{ {
[DbContext(typeof(SushiBarDatabase))] [DbContext(typeof(SushiBarDatabase))]
[Migration("20240326181255_InitialCreate")] [Migration("20240507174252_InitMigration")]
partial class InitialCreate partial class InitMigration
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -21,24 +21,24 @@ namespace SushiBarDatabaseImplement.Migrations
#pragma warning disable 612, 618 #pragma warning disable 612, 618
modelBuilder modelBuilder
.HasAnnotation("ProductVersion", "8.0.3") .HasAnnotation("ProductVersion", "8.0.3")
.HasAnnotation("Relational:MaxIdentifierLength", 128); .HasAnnotation("Relational:MaxIdentifierLength", 63);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Buyer", b => modelBuilder.Entity("SushiBarDatabaseImplement.Models.Buyer", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("int"); .HasColumnType("integer");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTime?>("BuyerBirthDate") b.Property<DateTime?>("BuyerBirthDate")
.HasColumnType("datetime2"); .HasColumnType("timestamp without time zone");
b.Property<string>("BuyerName") b.Property<string>("BuyerName")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("text");
b.HasKey("Id"); b.HasKey("Id");
@ -49,28 +49,28 @@ namespace SushiBarDatabaseImplement.Migrations
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("int"); .HasColumnType("integer");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("CookName") b.Property<string>("CookName")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("text");
b.Property<string>("CookSurname") b.Property<string>("CookSurname")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("text");
b.Property<int>("Experience") b.Property<int>("Experience")
.HasColumnType("int"); .HasColumnType("integer");
b.Property<string>("Passport") b.Property<string>("Passport")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("text");
b.Property<string>("PhoneNumber") b.Property<string>("PhoneNumber")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("text");
b.HasKey("Id"); b.HasKey("Id");
@ -81,20 +81,20 @@ namespace SushiBarDatabaseImplement.Migrations
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("int"); .HasColumnType("integer");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Description") b.Property<string>("Description")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("text");
b.Property<string>("FoodName") b.Property<string>("FoodName")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("text");
b.Property<double>("Price") b.Property<double>("Price")
.HasColumnType("float"); .HasColumnType("double precision");
b.HasKey("Id"); b.HasKey("Id");
@ -105,15 +105,15 @@ namespace SushiBarDatabaseImplement.Migrations
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("int"); .HasColumnType("integer");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("CountPlaces") b.Property<int>("CountPlaces")
.HasColumnType("int"); .HasColumnType("integer");
b.Property<int>("PlaceNumber") b.Property<int>("PlaceNumber")
.HasColumnType("int"); .HasColumnType("integer");
b.HasKey("Id"); b.HasKey("Id");
@ -124,27 +124,27 @@ namespace SushiBarDatabaseImplement.Migrations
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("int"); .HasColumnType("integer");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("BuyerId") b.Property<int>("BuyerId")
.HasColumnType("int"); .HasColumnType("integer");
b.Property<int>("CookId") b.Property<int>("CookId")
.HasColumnType("int"); .HasColumnType("integer");
b.Property<double>("FullPrice") b.Property<double>("FullPrice")
.HasColumnType("float"); .HasColumnType("double precision");
b.Property<int>("PlaceId") b.Property<int>("PlaceId")
.HasColumnType("int"); .HasColumnType("integer");
b.Property<int>("Status") b.Property<int>("Status")
.HasColumnType("int"); .HasColumnType("integer");
b.Property<DateTime>("TaskDate") b.Property<DateTime>("TaskDate")
.HasColumnType("datetime2"); .HasColumnType("timestamp without time zone");
b.HasKey("Id"); b.HasKey("Id");
@ -155,18 +155,18 @@ namespace SushiBarDatabaseImplement.Migrations
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("int"); .HasColumnType("integer");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("Count") b.Property<int>("Count")
.HasColumnType("int"); .HasColumnType("integer");
b.Property<int>("MenuId") b.Property<int>("MenuId")
.HasColumnType("int"); .HasColumnType("integer");
b.Property<int>("TaskId") b.Property<int>("TaskId")
.HasColumnType("int"); .HasColumnType("integer");
b.HasKey("Id"); b.HasKey("Id");

View File

@ -1,12 +1,13 @@
using System; using System;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable #nullable disable
namespace SushiBarDatabaseImplement.Migrations namespace SushiBarDatabaseImplement.Migrations
{ {
/// <inheritdoc /> /// <inheritdoc />
public partial class InitialCreate : Migration public partial class InitMigration : Migration
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)
@ -15,10 +16,10 @@ namespace SushiBarDatabaseImplement.Migrations
name: "Buyers", name: "Buyers",
columns: table => new columns: table => new
{ {
Id = table.Column<int>(type: "int", nullable: false) Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"), .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
BuyerName = table.Column<string>(type: "nvarchar(max)", nullable: false), BuyerName = table.Column<string>(type: "text", nullable: false),
BuyerBirthDate = table.Column<DateTime>(type: "datetime2", nullable: true) BuyerBirthDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: true)
}, },
constraints: table => constraints: table =>
{ {
@ -29,13 +30,13 @@ namespace SushiBarDatabaseImplement.Migrations
name: "Cooks", name: "Cooks",
columns: table => new columns: table => new
{ {
Id = table.Column<int>(type: "int", nullable: false) Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"), .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
CookName = table.Column<string>(type: "nvarchar(max)", nullable: false), CookName = table.Column<string>(type: "text", nullable: false),
CookSurname = table.Column<string>(type: "nvarchar(max)", nullable: false), CookSurname = table.Column<string>(type: "text", nullable: false),
Experience = table.Column<int>(type: "int", nullable: false), Experience = table.Column<int>(type: "integer", nullable: false),
PhoneNumber = table.Column<string>(type: "nvarchar(max)", nullable: false), PhoneNumber = table.Column<string>(type: "text", nullable: false),
Passport = table.Column<string>(type: "nvarchar(max)", nullable: false) Passport = table.Column<string>(type: "text", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
@ -46,11 +47,11 @@ namespace SushiBarDatabaseImplement.Migrations
name: "Menus", name: "Menus",
columns: table => new columns: table => new
{ {
Id = table.Column<int>(type: "int", nullable: false) Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"), .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
FoodName = table.Column<string>(type: "nvarchar(max)", nullable: false), FoodName = table.Column<string>(type: "text", nullable: false),
Description = table.Column<string>(type: "nvarchar(max)", nullable: false), Description = table.Column<string>(type: "text", nullable: false),
Price = table.Column<double>(type: "float", nullable: false) Price = table.Column<double>(type: "double precision", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
@ -61,10 +62,10 @@ namespace SushiBarDatabaseImplement.Migrations
name: "Places", name: "Places",
columns: table => new columns: table => new
{ {
Id = table.Column<int>(type: "int", nullable: false) Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"), .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
PlaceNumber = table.Column<int>(type: "int", nullable: false), PlaceNumber = table.Column<int>(type: "integer", nullable: false),
CountPlaces = table.Column<int>(type: "int", nullable: false) CountPlaces = table.Column<int>(type: "integer", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
@ -75,14 +76,14 @@ namespace SushiBarDatabaseImplement.Migrations
name: "Tasks", name: "Tasks",
columns: table => new columns: table => new
{ {
Id = table.Column<int>(type: "int", nullable: false) Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"), .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
TaskDate = table.Column<DateTime>(type: "datetime2", nullable: false), TaskDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
Status = table.Column<int>(type: "int", nullable: false), Status = table.Column<int>(type: "integer", nullable: false),
FullPrice = table.Column<double>(type: "float", nullable: false), FullPrice = table.Column<double>(type: "double precision", nullable: false),
PlaceId = table.Column<int>(type: "int", nullable: false), PlaceId = table.Column<int>(type: "integer", nullable: false),
CookId = table.Column<int>(type: "int", nullable: false), CookId = table.Column<int>(type: "integer", nullable: false),
BuyerId = table.Column<int>(type: "int", nullable: false) BuyerId = table.Column<int>(type: "integer", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
@ -93,11 +94,11 @@ namespace SushiBarDatabaseImplement.Migrations
name: "TaskMenus", name: "TaskMenus",
columns: table => new columns: table => new
{ {
Id = table.Column<int>(type: "int", nullable: false) Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"), .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
TaskId = table.Column<int>(type: "int", nullable: false), TaskId = table.Column<int>(type: "integer", nullable: false),
MenuId = table.Column<int>(type: "int", nullable: false), MenuId = table.Column<int>(type: "integer", nullable: false),
Count = table.Column<int>(type: "int", nullable: false) Count = table.Column<int>(type: "integer", nullable: false)
}, },
constraints: table => constraints: table =>
{ {

View File

@ -2,8 +2,8 @@
using System; using System;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using SushiBarDatabaseImplement; using SushiBarDatabaseImplement;
#nullable disable #nullable disable
@ -18,24 +18,24 @@ namespace SushiBarDatabaseImplement.Migrations
#pragma warning disable 612, 618 #pragma warning disable 612, 618
modelBuilder modelBuilder
.HasAnnotation("ProductVersion", "8.0.3") .HasAnnotation("ProductVersion", "8.0.3")
.HasAnnotation("Relational:MaxIdentifierLength", 128); .HasAnnotation("Relational:MaxIdentifierLength", 63);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Buyer", b => modelBuilder.Entity("SushiBarDatabaseImplement.Models.Buyer", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("int"); .HasColumnType("integer");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTime?>("BuyerBirthDate") b.Property<DateTime?>("BuyerBirthDate")
.HasColumnType("datetime2"); .HasColumnType("timestamp without time zone");
b.Property<string>("BuyerName") b.Property<string>("BuyerName")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("text");
b.HasKey("Id"); b.HasKey("Id");
@ -46,28 +46,28 @@ namespace SushiBarDatabaseImplement.Migrations
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("int"); .HasColumnType("integer");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("CookName") b.Property<string>("CookName")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("text");
b.Property<string>("CookSurname") b.Property<string>("CookSurname")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("text");
b.Property<int>("Experience") b.Property<int>("Experience")
.HasColumnType("int"); .HasColumnType("integer");
b.Property<string>("Passport") b.Property<string>("Passport")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("text");
b.Property<string>("PhoneNumber") b.Property<string>("PhoneNumber")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("text");
b.HasKey("Id"); b.HasKey("Id");
@ -78,20 +78,20 @@ namespace SushiBarDatabaseImplement.Migrations
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("int"); .HasColumnType("integer");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Description") b.Property<string>("Description")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("text");
b.Property<string>("FoodName") b.Property<string>("FoodName")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("text");
b.Property<double>("Price") b.Property<double>("Price")
.HasColumnType("float"); .HasColumnType("double precision");
b.HasKey("Id"); b.HasKey("Id");
@ -102,15 +102,15 @@ namespace SushiBarDatabaseImplement.Migrations
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("int"); .HasColumnType("integer");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("CountPlaces") b.Property<int>("CountPlaces")
.HasColumnType("int"); .HasColumnType("integer");
b.Property<int>("PlaceNumber") b.Property<int>("PlaceNumber")
.HasColumnType("int"); .HasColumnType("integer");
b.HasKey("Id"); b.HasKey("Id");
@ -121,27 +121,27 @@ namespace SushiBarDatabaseImplement.Migrations
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("int"); .HasColumnType("integer");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("BuyerId") b.Property<int>("BuyerId")
.HasColumnType("int"); .HasColumnType("integer");
b.Property<int>("CookId") b.Property<int>("CookId")
.HasColumnType("int"); .HasColumnType("integer");
b.Property<double>("FullPrice") b.Property<double>("FullPrice")
.HasColumnType("float"); .HasColumnType("double precision");
b.Property<int>("PlaceId") b.Property<int>("PlaceId")
.HasColumnType("int"); .HasColumnType("integer");
b.Property<int>("Status") b.Property<int>("Status")
.HasColumnType("int"); .HasColumnType("integer");
b.Property<DateTime>("TaskDate") b.Property<DateTime>("TaskDate")
.HasColumnType("datetime2"); .HasColumnType("timestamp without time zone");
b.HasKey("Id"); b.HasKey("Id");
@ -152,18 +152,18 @@ namespace SushiBarDatabaseImplement.Migrations
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("int"); .HasColumnType("integer");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("Count") b.Property<int>("Count")
.HasColumnType("int"); .HasColumnType("integer");
b.Property<int>("MenuId") b.Property<int>("MenuId")
.HasColumnType("int"); .HasColumnType("integer");
b.Property<int>("TaskId") b.Property<int>("TaskId")
.HasColumnType("int"); .HasColumnType("integer");
b.HasKey("Id"); b.HasKey("Id");

View File

@ -15,11 +15,15 @@ namespace SushiBarDatabaseImplement
{ {
if (optionsBuilder.IsConfigured == false) if (optionsBuilder.IsConfigured == false)
{ {
optionsBuilder.UseSqlServer(@"Data Source=.\SQLEXPRESS;Initial Catalog=SushiBarDatabase;Integrated Security=True;MultipleActiveResultSets=True;TrustServerCertificate=True"); optionsBuilder.UseNpgsql(@"Host=localhost;Database=SUBDLab8;Username=postgres;Password=shotboll200412");
} }
base.OnConfiguring(optionsBuilder); base.OnConfiguring(optionsBuilder);
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);
} }
//optionsBuilder.UseNpgsql(@"Host=localhost;Database=ComputersShop_db;Username=postgres;Password=postgres");
public virtual DbSet<Buyer> Buyers { get; set; } public virtual DbSet<Buyer> Buyers { get; set; }
public virtual DbSet<Cook> Cooks { get; set; } public virtual DbSet<Cook> Cooks { get; set; }
public virtual DbSet<Menu> Menus { get; set; } public virtual DbSet<Menu> Menus { get; set; }

View File

@ -0,0 +1,110 @@
using MongoDB.Bson;
using MongoDB.Driver;
using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels;
using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels;
using SushiBarMongoDB.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarMongoDB.Implements
{
public class BuyerStorage : IBuyerStorage
{
public void ClearEntity()
{
using var context = new SushiBarMongoDB();
context.GetCollection<Buyer>("Buyers")
.DeleteMany(Builders<Buyer>.Filter.Empty);
}
public List<BuyerViewModel> GetFullList()
{
using var context = new SushiBarMongoDB();
var buyers = context.GetCollection<Buyer>("Buyers");
return buyers.Find(Builders<Buyer>.Filter.Empty)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public List<BuyerViewModel> GetFilteredList(BuyerSearchModel model)
{
if(string.IsNullOrEmpty(model.BuyerName)) return new List<BuyerViewModel>();
using var context = new SushiBarMongoDB();
var buyers = context.GetCollection<Buyer>("Buyers");
var filterBuilder = Builders<Buyer>.Filter;
var filter = filterBuilder.Regex(x => x.BuyerName, new BsonRegularExpression(model.BuyerName));
return buyers
.Find(filter)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public BuyerViewModel? GetElement(BuyerSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using (var context = new SushiBarMongoDB())
{
var buyers = context.GetCollection<Buyer>("Buyers");
var filterBuilder = Builders<Buyer>.Filter;
var filter = filterBuilder.Empty;
if (!model.Id.HasValue)
{
filter &= filterBuilder.Eq(x => x.Id, model.Id);
}
return buyers.Find(filter)
.FirstOrDefault()
?.GetViewModel;
}
}
public BuyerViewModel? Insert(BuyerBindingModel model)
{
using var context = new SushiBarMongoDB();
var buyers = context.GetCollection<Buyer>("Buyers");
model.Id = (int)buyers.CountDocuments(FilterDefinition<Buyer>.Empty)+1;
var buyer = Buyer.Create(model);
buyers.InsertOne(buyer);
return buyer.GetViewModel;
}
public BuyerViewModel? Update(BuyerBindingModel model)
{
using var context = new SushiBarMongoDB();
var buyers = context.GetCollection<Buyer>("Buyers");
var filter = Builders<Buyer>.Filter.Eq(x => x.Id, model.Id);
var buyer = buyers.Find(filter).FirstOrDefault();
if (buyer == null)
{
return null;
}
buyer.Update(model);
buyers.ReplaceOne(filter, buyer);
return buyer.GetViewModel;
}
public BuyerViewModel? Delete(BuyerBindingModel model)
{
using var context = new SushiBarMongoDB();
var categories = context.GetCollection<Buyer>("Buyers");
var filter = Builders<Buyer>.Filter.Eq(x => x.Id, model.Id);
var category = categories.FindOneAndDelete(filter);
return category?.GetViewModel;
}
}
}

View File

@ -0,0 +1,114 @@
using MongoDB.Bson;
using MongoDB.Driver;
using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels;
using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels;
using SushiBarMongoDB.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarMongoDB.Implements
{
public class CookStorage : ICookStorage
{
public void ClearEntity()
{
using var context = new SushiBarMongoDB();
context.GetCollection<Cook>("Cooks")
.DeleteMany(Builders<Cook>.Filter.Empty);
}
public List<CookViewModel> GetFullList()
{
using var context = new SushiBarMongoDB();
var cooks = context.GetCollection<Cook>("Cooks");
return cooks.Find(Builders<Cook>.Filter.Empty)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public List<CookViewModel> GetFilteredList(CookSearchModel model)
{
if (string.IsNullOrEmpty(model.CookName))
{
return new List<CookViewModel>();
}
using var context = new SushiBarMongoDB();
var cooks = context.GetCollection<Cook>("Cooks");
var filterBuilder = Builders<Cook>.Filter;
var filter = filterBuilder
.Regex(x => x.CookName, new BsonRegularExpression(model.CookName));
return cooks
.Find(filter)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public CookViewModel? GetElement(CookSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using (var context = new SushiBarMongoDB())
{
var cooks = context.GetCollection<Cook>("Cooks");
var filterBuilder = Builders<Cook>.Filter;
var filter = filterBuilder.Empty;
if (!model.Id.HasValue)
{
filter &= filterBuilder.Eq(x => x.Id, model.Id);
}
return cooks.Find(filter)
.FirstOrDefault()
?.GetViewModel;
}
}
public CookViewModel? Insert(CookBindingModel model)
{
using var context = new SushiBarMongoDB();
var cooks = context.GetCollection<Cook>("Cooks");
model.Id = (int)cooks.CountDocuments(FilterDefinition<Cook>.Empty) + 1;
var cook = Cook.Create(model);
cooks.InsertOne(cook);
return cook.GetViewModel;
}
public CookViewModel? Update(CookBindingModel model)
{
using var context = new SushiBarMongoDB();
var cooks = context.GetCollection<Cook>("Cooks");
var filter = Builders<Cook>.Filter.Eq(x => x.Id, model.Id);
var cook = cooks.Find(filter).FirstOrDefault();
if (cook == null)
{
return null;
}
cook.Update(model);
cooks.ReplaceOne(filter, cook);
return cook.GetViewModel;
}
public CookViewModel? Delete(CookBindingModel model)
{
using var context = new SushiBarMongoDB();
var cooks = context.GetCollection<Cook>("Cooks");
var filter = Builders<Cook>.Filter.Eq(x => x.Id, model.Id);
var cook = cooks.FindOneAndDelete(filter);
return cook?.GetViewModel;
}
}
}

View File

@ -0,0 +1,116 @@
using MongoDB.Bson;
using MongoDB.Driver;
using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels;
using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels;
using SushiBarMongoDB.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarMongoDB.Implements
{
public class MenuStorage : IMenuStorage
{
public void ClearEntity()
{
using var context = new SushiBarMongoDB();
context.GetCollection<Menu>("Menus")
.DeleteMany(Builders<Menu>.Filter.Empty);
}
public MenuViewModel? GetElement(MenuSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using (var context = new SushiBarMongoDB())
{
var menus = context.GetCollection<Menu>("Menus");
var filterBuilder = Builders<Menu>.Filter;
var filter = filterBuilder.Empty;
if (!model.Id.HasValue)
{
filter &= filterBuilder.Eq(x => x.Id, model.Id);
}
return menus.Find(filter)
.FirstOrDefault()
?.GetViewModel;
}
}
public List<MenuViewModel> GetFilteredList(MenuSearchModel model)
{
if (string.IsNullOrEmpty(model.FoodName))
{
return new List<MenuViewModel>();
}
using var context = new SushiBarMongoDB();
var menus = context.GetCollection<Menu>("Menus");
var filterBuilder = Builders<Menu>.Filter;
var filter = filterBuilder
.Regex(x => x.FoodName, new BsonRegularExpression(model.FoodName));
return menus
.Find(filter)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public List<MenuViewModel> GetFullList()
{
using var context = new SushiBarMongoDB();
var menus = context.GetCollection<Menu>("Menus");
return menus.Find(Builders<Menu>.Filter.Empty)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public MenuViewModel? Insert(MenuBindingModel model)
{
using var context = new SushiBarMongoDB();
var menus = context.GetCollection<Menu>("Menus");
model.Id = (int)menus.CountDocuments(FilterDefinition<Menu>.Empty) + 1;
var menu = Menu.Create(model);
menus.InsertOne(menu);
return menu.GetViewModel;
}
public MenuViewModel? Update(MenuBindingModel model)
{
using var context = new SushiBarMongoDB();
var menus = context.GetCollection<Menu>("Menus");
var filter = Builders<Menu>.Filter.Eq(x => x.Id, model.Id);
var menu = menus.Find(filter).FirstOrDefault();
if (menu == null)
{
return null;
}
menu.Update(model);
menus.ReplaceOne(filter, menu);
return menu.GetViewModel;
}
public MenuViewModel? Delete(MenuBindingModel model)
{
using var context = new SushiBarMongoDB();
var menus = context.GetCollection<Menu>("Menus");
var filter = Builders<Menu>.Filter.Eq(x => x.Id, model.Id);
var menu = menus.FindOneAndDelete(filter);
return menu?.GetViewModel;
}
}
}

View File

@ -0,0 +1,115 @@
using MongoDB.Bson;
using MongoDB.Driver;
using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels;
using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels;
using SushiBarMongoDB.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarMongoDB.Implements
{
public class PlaceStorage : IPlaceStorage
{
public void ClearEntity()
{
using var context = new SushiBarMongoDB();
context.GetCollection<Place>("Places")
.DeleteMany(Builders<Place>.Filter.Empty);
}
public PlaceViewModel? GetElement(PlaceSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using (var context = new SushiBarMongoDB())
{
var places = context.GetCollection<Place>("Places");
var filterBuilder = Builders<Place>.Filter;
var filter = filterBuilder.Empty;
if (!model.Id.HasValue)
{
filter &= filterBuilder.Eq(x => x.Id, model.Id);
}
return places.Find(filter)
.FirstOrDefault()
?.GetViewModel;
}
}
public List<PlaceViewModel> GetFilteredList(PlaceSearchModel model)
{
if (!model.PlaceNumber.HasValue)
{
return new List<PlaceViewModel>();
}
using var context = new SushiBarMongoDB();
var places = context.GetCollection<Place>("Places");
var filter = Builders<Place>.Filter.Eq(x => x.Id, model.Id);
return places
.Find(filter)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public List<PlaceViewModel> GetFullList()
{
using var context = new SushiBarMongoDB();
var places = context.GetCollection<Place>("Places");
return places.Find(Builders<Place>.Filter.Empty)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public PlaceViewModel? Insert(PlaceBindingModel model)
{
using var context = new SushiBarMongoDB();
var places = context.GetCollection<Place>("Places");
model.Id = (int)places.CountDocuments(FilterDefinition<Place>.Empty) + 1;
var place = Place.Create(model);
places.InsertOne(place);
return place.GetViewModel;
}
public PlaceViewModel? Update(PlaceBindingModel model)
{
using var context = new SushiBarMongoDB();
var places = context.GetCollection<Place>("Places");
var filter = Builders<Place>.Filter.Eq(x => x.Id, model.Id);
var place = places.Find(filter).FirstOrDefault();
if (place == null)
{
return null;
}
place.Update(model);
places.ReplaceOne(filter, place);
return place.GetViewModel;
}
public PlaceViewModel? Delete(PlaceBindingModel model)
{
using var context = new SushiBarMongoDB();
var places = context.GetCollection<Place>("Places");
var filter = Builders<Place>.Filter.Eq(x => x.Id, model.Id);
var place = places.FindOneAndDelete(filter);
return place?.GetViewModel;
}
}
}

View File

@ -0,0 +1,89 @@
using MongoDB.Bson;
using MongoDB.Driver;
using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels;
using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels;
using SushiBarMongoDB.Models;
using System.Xml;
using Task = SushiBarMongoDB.Models.Task;
namespace SushiBarMongoDB.Implements
{
public class TaskStorage : ITaskStorage
{
public void ClearEntity()
{
using var context = new SushiBarMongoDB();
context.GetCollection<Task>("Tasks")
.DeleteMany(Builders<Task>.Filter.Empty);
}
public List<TaskViewModel> GetFullList()
{
using var context = new SushiBarMongoDB();
var tasks = context.GetCollection<Task>("Tasks").Find(Builders<Task>.Filter.Empty).ToList();
return tasks.Select(x => x.GetViewModel).ToList();
}
public List<TaskViewModel> GetFilteredList(TaskSearchModel model)
{
using var context = new SushiBarMongoDB();
if(!model.Id.HasValue) return new List<TaskViewModel>();
var filterBuilder = Builders<Task>.Filter;
var filter = filterBuilder.Empty;
filter = filterBuilder.Eq("Id", model.Id);
var tasks = context.GetCollection<Task>("Tasks").Find(filter).ToList();
return tasks.Select(x => x.GetViewModel).ToList();
}
public TaskViewModel? GetElement(TaskSearchModel model)
{
using var context = new SushiBarMongoDB();
var tasks = context.GetCollection<Task>("Tasks");
if (!model.Id.HasValue) return null;
return tasks.Find(x => x.Id == model.Id).FirstOrDefault()?.GetViewModel;
}
public TaskViewModel? Insert(TaskBindingModel model)
{
using var context = new SushiBarMongoDB();
var tasks = context.GetCollection<Task>("Tasks");
model.Id = (int)tasks.CountDocuments(FilterDefinition<Task>.Empty) + 1;
var newTask = Task.Create(model);
if (newTask == null) return null;
tasks.InsertOne(newTask);
return newTask.GetViewModel;
}
public TaskViewModel? Update(TaskBindingModel model)
{
using var context = new SushiBarMongoDB();
var task = context.GetCollection<Task>("Tasks").Find(x => x.Id == model.Id).FirstOrDefault();
if (task == null) return null;
task.Update(model);
context.GetCollection<Task>("Tasks").ReplaceOne(x => x.Id == model.Id, task);
return task.GetViewModel;
}
public TaskViewModel? Delete(TaskBindingModel model)
{
using var context = new SushiBarMongoDB();
var element = context.GetCollection<Task>("Tasks").Find(x => x.Id == model.Id).FirstOrDefault();
if (element != null)
{
context.GetCollection<Task>("Tasks").DeleteOne(x => x.Id == model.Id);
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,53 @@
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
using SushiBarDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SushiBarContracts.BindingModels;
using SushiBarContracts.ViewModels;
namespace SushiBarMongoDB.Models
{
public class Buyer : IBuyerModel
{
[BsonId]
[BsonElement("_id")]
public int Id { get; set; }
[BsonRequired]
public string BuyerName { get; set; } = string.Empty;
[BsonIgnoreIfNull]
[BsonIgnoreIfDefault]
public DateTime? BuyerBirthDate { get; set; }
public static Buyer? Create(BuyerBindingModel model)
{
if (model == null) return null;
return new Buyer()
{
Id = model.Id,
BuyerName = model.BuyerName,
BuyerBirthDate = model.BuyerBirthDate,
};
}
public void Update(BuyerBindingModel model)
{
if (model == null) return;
Id = model.Id;
BuyerName = model.BuyerName;
BuyerBirthDate = model.BuyerBirthDate;
}
public BuyerViewModel GetViewModel => new()
{
Id = Id,
BuyerName = BuyerName,
BuyerBirthDate = BuyerBirthDate,
};
}
}

View File

@ -0,0 +1,70 @@
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
using SushiBarDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SushiBarContracts.BindingModels;
using SushiBarContracts.ViewModels;
namespace SushiBarMongoDB.Models
{
public class Cook : ICookModel
{
[BsonId]
[BsonElement("_id")]
public int Id { get; set; }
[BsonRequired]
public string CookName { get; set; } = string.Empty;
[BsonRequired]
public string CookSurname { get; set; } = string.Empty;
[BsonRequired]
public int Experience { get; set; }
[BsonRequired]
public string PhoneNumber { get; set; } = string.Empty;
[BsonRequired]
public string Passport { get; set; } = string.Empty;
public static Cook? Create(CookBindingModel model)
{
if (model == null) return null;
return new Cook()
{
Id = model.Id,
CookName = model.CookName,
CookSurname = model.CookSurname,
Experience = model.Experience,
PhoneNumber = model.PhoneNumber,
Passport = model.Passport,
};
}
public void Update(CookBindingModel model)
{
if (model == null) return;
Id = model.Id;
CookName = model.CookName;
CookSurname = model.CookSurname;
Experience = model.Experience;
PhoneNumber = model.PhoneNumber;
Passport = model.Passport;
}
public CookViewModel GetViewModel => new()
{
Id = Id,
CookName = CookName,
CookSurname = CookSurname,
Experience = Experience,
PhoneNumber = PhoneNumber,
Passport = Passport
};
}
}

View File

@ -0,0 +1,58 @@
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
using SushiBarDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SushiBarContracts.BindingModels;
using SushiBarContracts.ViewModels;
namespace SushiBarMongoDB.Models
{
public class Menu : IMenuModel
{
[BsonId]
[BsonElement("_id")]
public int Id { get; set; }
[BsonRequired]
public string FoodName { get; set; } = string.Empty;
[BsonRequired]
public string Description { get; set; } = string.Empty;
[BsonRequired]
public double Price { get; set; }
public static Menu? Create(MenuBindingModel model)
{
if (model == null) return null;
return new Menu()
{
Id = model.Id,
FoodName = model.FoodName,
Description = model.Description,
Price = model.Price,
};
}
public void Update(MenuBindingModel model)
{
if (model == null) return;
Id = model.Id;
FoodName = model.FoodName;
Description = model.Description;
Price = model.Price;
}
public MenuViewModel GetViewModel => new()
{
Id = Id,
FoodName = FoodName,
Description = Description,
Price = Price,
};
}
}

View File

@ -0,0 +1,52 @@
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
using SushiBarDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SushiBarContracts.BindingModels;
using SushiBarContracts.ViewModels;
namespace SushiBarMongoDB.Models
{
public class Place : IPlaceModel
{
[BsonId]
[BsonElement("_id")]
public int Id { get; set; }
[BsonRequired]
public int PlaceNumber { get; set; }
[BsonRequired]
public int CountPlaces { get; set; }
public static Place? Create(PlaceBindingModel model)
{
if (model == null) return null;
return new Place()
{
Id = model.Id,
PlaceNumber = model.PlaceNumber,
CountPlaces = model.CountPlaces,
};
}
public void Update(PlaceBindingModel model)
{
if (model == null) return;
Id = model.Id;
PlaceNumber = model.PlaceNumber;
CountPlaces = model.CountPlaces;
}
public PlaceViewModel GetViewModel => new()
{
Id = Id,
PlaceNumber = PlaceNumber,
CountPlaces = CountPlaces,
};
}
}

View File

@ -0,0 +1,95 @@
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
using SushiBarDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SushiBarContracts.BindingModels;
using SushiBarContracts.ViewModels;
namespace SushiBarMongoDB.Models
{
public class Task : ITaskModel
{
[BsonId]
[BsonElement("_id")]
public int Id { get; set; }
[BsonRequired]
public DateTime TaskDate { get; set; }
[BsonRequired]
public SushiBarDataModels.Enum.TaskStatus Status { get; set; }
[BsonRequired]
public double FullPrice { get; set; }
[BsonRequired]
[BsonElement("place_id")]
public int PlaceId { get; set; }
[BsonRequired]
[BsonElement("cook_id")]
public int CookId { get; set; }
[BsonRequired]
[BsonElement("buyer_id")]
public int BuyerId { get; set; }
[BsonRequired]
[BsonElement("menu_ids")]
public List<int> MenuIds { get; set; } = new List<int>();
[BsonIgnoreIfNull]
[BsonIgnoreIfDefault]
public virtual Place Place { get; set; }
[BsonIgnoreIfNull]
[BsonIgnoreIfDefault]
public virtual Cook Cook { get; set; }
[BsonIgnoreIfNull]
[BsonIgnoreIfDefault]
public virtual Buyer Buyer { get; set; }
[BsonIgnoreIfNull]
[BsonIgnoreIfDefault]
public virtual List<Menu> Menus { get; set; }
[BsonIgnore]
public Dictionary<int, (IMenuModel, int)> TaskMenus { get; set; } = new Dictionary<int, (IMenuModel, int)>();
public static Task? Create(TaskBindingModel model)
{
if (model == null) return null;
return new Task()
{
Id = model.Id,
TaskDate = model.TaskDate,
Status = model.Status,
FullPrice = model.FullPrice,
PlaceId = model.PlaceId,
CookId = model.CookId,
BuyerId = model.BuyerId,
MenuIds = model.MenuIds,
};
}
public void Update(TaskBindingModel model)
{
if (model == null) return;
Status = model.Status;
}
public TaskViewModel GetViewModel => new()
{
Id = Id,
TaskDate = TaskDate,
Status = Status,
FullPrice = FullPrice,
PlaceId = PlaceId,
CookId = CookId,
BuyerId = BuyerId,
};
}
}

View File

@ -0,0 +1,122 @@
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.Core.Configuration;
using Npgsql;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarMongoDB
{
public static class PostgresToMongo
{
public static void Convert()
{
string postgresConnection = "Host=localhost;Username=postgres;Password=shotboll200412;Database=SUBDLab8";
using var psqlConn = new NpgsqlConnection(postgresConnection);
psqlConn.Open();
var client = new MongoClient("mongodb://localhost:27017");
var database = client.GetDatabase("lab8SUBD");
var buyers = database.GetCollection<BsonDocument>("Buyers");
var cooks = database.GetCollection<BsonDocument>("Cooks");
var menus = database.GetCollection<BsonDocument>("Menus");
var places = database.GetCollection<BsonDocument>("Places");
var tasks = database.GetCollection<BsonDocument>("Tasks");
//Конвертация покупателей
using var psqlBuyers = new NpgsqlCommand("SELECT * FROM \"Buyers\"", psqlConn);
using var readBuyers = psqlBuyers.ExecuteReader();
while(readBuyers.Read())
{
var document = new BsonDocument();
for(int i = 0;i<readBuyers.FieldCount;i++)
{
document.Add(readBuyers.GetName(i), BsonValue.Create(readBuyers.GetValue(i)));
}
buyers.InsertOne(document);
}
readBuyers.Close();
psqlBuyers.Cancel();
//Конвертация поваров
using var psqlCooks = new NpgsqlCommand("SELECT * FROM \"Cooks\"", psqlConn);
using var readCooks = psqlCooks.ExecuteReader();
while (readCooks.Read())
{
var document = new BsonDocument();
for (int i = 0; i < readCooks.FieldCount; i++)
{
document.Add(readCooks.GetName(i), BsonValue.Create(readCooks.GetValue(i)));
}
cooks.InsertOne(document);
}
readCooks.Close();
psqlCooks.Cancel();
//Конвертация меню
using var psqlMenus = new NpgsqlCommand("SELECT * FROM \"Menus\"", psqlConn);
using var readMenus = psqlMenus.ExecuteReader();
while (readMenus.Read())
{
var document = new BsonDocument();
for (int i = 0; i < readMenus.FieldCount; i++)
{
document.Add(readMenus.GetName(i), BsonValue.Create(readMenus.GetValue(i)));
}
menus.InsertOne(document);
}
readMenus.Close();
psqlMenus.Cancel();
//Конвертация столиков
using var psqlPlaces = new NpgsqlCommand("SELECT * FROM \"Places\"", psqlConn);
using var readPlaces = psqlPlaces.ExecuteReader();
while (readPlaces.Read())
{
var document = new BsonDocument();
for (int i = 0; i < readPlaces.FieldCount; i++)
{
document.Add(readPlaces.GetName(i), BsonValue.Create(readPlaces.GetValue(i)));
}
places.InsertOne(document);
}
readPlaces.Close();
psqlPlaces.Cancel();
//Конфертация заказов
using var psqlTasks = new NpgsqlCommand("SELECT * FROM \"Tasks\"", psqlConn);
using var readTasks = psqlTasks.ExecuteReader();
while (readTasks.Read())
{
var document = new BsonDocument();
for (int i = 0; i < readTasks.FieldCount; i++)
{
string fieldName = readTasks.GetName(i);
if (fieldName == "PlaceId") fieldName = "place_id";
if (fieldName == "CookId") fieldName = "cook_id";
if (fieldName == "BuyerId") fieldName = "buyer_id";
if (fieldName == "MenuIds") fieldName = "menu_ids";
document.Add(readTasks.GetName(i), BsonValue.Create(readTasks.GetValue(i)));
}
tasks.InsertOne(document);
}
readTasks.Close();
psqlTasks.Cancel();
psqlConn.Close();
}
}
}

View File

@ -0,0 +1,28 @@
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarMongoDB
{
public class SushiBarMongoDB : IDisposable
{
private readonly MongoClient _client;
private readonly IMongoDatabase _database;
public SushiBarMongoDB(string connectionString = "mongodb://localhost:27017", string databaseName = "lab8SUBD")
{
_client = new MongoClient(connectionString);
_database = _client.GetDatabase(databaseName);
}
public IMongoCollection<T> GetCollection<T>(string collectionName)
{
return _database.GetCollection<T>(collectionName);
}
public void Dispose() { }
}
}

View File

@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Bogus" Version="35.5.1" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageReference Include="MongoDB.Bson" Version="2.25.0" />
<PackageReference Include="MongoDB.Driver" Version="2.25.0" />
<PackageReference Include="MongoDB.Driver.Core" Version="2.25.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SushiBarBusinessLogic\SushiBarBusinessLogic.csproj" />
<ProjectReference Include="..\SushiBarContracts\SushiBarContracts.csproj" />
<ProjectReference Include="..\SushiBarDataModels\SushiBarDataModels.csproj" />
</ItemGroup>
</Project>