diff --git a/SushiBar/SushiBar/FormMain.Designer.cs b/SushiBar/SushiBar/FormMain.Designer.cs index 8f4d641..53ce3ae 100644 --- a/SushiBar/SushiBar/FormMain.Designer.cs +++ b/SushiBar/SushiBar/FormMain.Designer.cs @@ -40,6 +40,7 @@ buttonCreateTask = new Button(); dataGridView = new DataGridView(); buttonTest = new Button(); + buttonPsqlToMongo = new Button(); menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); @@ -49,8 +50,7 @@ menuStrip1.Items.AddRange(new ToolStripItem[] { объектыToolStripMenuItem }); menuStrip1.Location = new Point(0, 0); menuStrip1.Name = "menuStrip1"; - menuStrip1.Padding = new Padding(7, 3, 0, 3); - menuStrip1.Size = new Size(1387, 30); + menuStrip1.Size = new Size(1214, 24); menuStrip1.TabIndex = 0; menuStrip1.Text = "menuStrip1"; // @@ -58,43 +58,42 @@ // объектыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { buyerToolStripMenuItem, cookToolStripMenuItem, menuToolStripMenuItem, placeToolStripMenuItem }); объектыToolStripMenuItem.Name = "объектыToolStripMenuItem"; - объектыToolStripMenuItem.Size = new Size(82, 24); + объектыToolStripMenuItem.Size = new Size(68, 20); объектыToolStripMenuItem.Text = "Объекты"; // // buyerToolStripMenuItem // buyerToolStripMenuItem.Name = "buyerToolStripMenuItem"; - buyerToolStripMenuItem.Size = new Size(159, 24); + buyerToolStripMenuItem.Size = new Size(139, 22); buyerToolStripMenuItem.Text = "Покупатель"; buyerToolStripMenuItem.Click += buyerToolStripMenuItem_Click; // // cookToolStripMenuItem // cookToolStripMenuItem.Name = "cookToolStripMenuItem"; - cookToolStripMenuItem.Size = new Size(159, 24); + cookToolStripMenuItem.Size = new Size(139, 22); cookToolStripMenuItem.Text = "Повар"; cookToolStripMenuItem.Click += cookToolStripMenuItem_Click; // // menuToolStripMenuItem // menuToolStripMenuItem.Name = "menuToolStripMenuItem"; - menuToolStripMenuItem.Size = new Size(159, 24); + menuToolStripMenuItem.Size = new Size(139, 22); menuToolStripMenuItem.Text = "Меню"; menuToolStripMenuItem.Click += menuToolStripMenuItem_Click; // // placeToolStripMenuItem // placeToolStripMenuItem.Name = "placeToolStripMenuItem"; - placeToolStripMenuItem.Size = new Size(159, 24); + placeToolStripMenuItem.Size = new Size(139, 22); placeToolStripMenuItem.Text = "Столик"; placeToolStripMenuItem.Click += placeToolStripMenuItem_Click; // // buttonIssuedTask // - buttonIssuedTask.Location = new Point(1106, 275); - buttonIssuedTask.Margin = new Padding(3, 4, 3, 4); + buttonIssuedTask.Location = new Point(968, 206); buttonIssuedTask.Name = "buttonIssuedTask"; - buttonIssuedTask.Size = new Size(226, 37); + buttonIssuedTask.Size = new Size(198, 28); buttonIssuedTask.TabIndex = 11; buttonIssuedTask.Text = "Заказ выдан"; buttonIssuedTask.UseVisualStyleBackColor = true; @@ -102,10 +101,9 @@ // // buttonTaskReady // - buttonTaskReady.Location = new Point(1106, 205); - buttonTaskReady.Margin = new Padding(3, 4, 3, 4); + buttonTaskReady.Location = new Point(968, 154); buttonTaskReady.Name = "buttonTaskReady"; - buttonTaskReady.Size = new Size(226, 37); + buttonTaskReady.Size = new Size(198, 28); buttonTaskReady.TabIndex = 10; buttonTaskReady.Text = "Заказ готов"; buttonTaskReady.UseVisualStyleBackColor = true; @@ -113,10 +111,9 @@ // // buttonTakeTaskInWork // - buttonTakeTaskInWork.Location = new Point(1106, 133); - buttonTakeTaskInWork.Margin = new Padding(3, 4, 3, 4); + buttonTakeTaskInWork.Location = new Point(968, 100); buttonTakeTaskInWork.Name = "buttonTakeTaskInWork"; - buttonTakeTaskInWork.Size = new Size(226, 37); + buttonTakeTaskInWork.Size = new Size(198, 28); buttonTakeTaskInWork.TabIndex = 9; buttonTakeTaskInWork.Text = "Отдать на выполнение"; buttonTakeTaskInWork.UseVisualStyleBackColor = true; @@ -124,10 +121,9 @@ // // buttonCreateTask // - buttonCreateTask.Location = new Point(1106, 61); - buttonCreateTask.Margin = new Padding(3, 4, 3, 4); + buttonCreateTask.Location = new Point(968, 46); buttonCreateTask.Name = "buttonCreateTask"; - buttonCreateTask.Size = new Size(226, 37); + buttonCreateTask.Size = new Size(198, 28); buttonCreateTask.TabIndex = 8; buttonCreateTask.Text = "Создать заказ"; buttonCreateTask.UseVisualStyleBackColor = true; @@ -139,31 +135,40 @@ dataGridView.BackgroundColor = Color.White; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.Dock = DockStyle.Left; - dataGridView.Location = new Point(0, 30); - dataGridView.Margin = new Padding(3, 4, 3, 4); + dataGridView.Location = new Point(0, 24); dataGridView.Name = "dataGridView"; dataGridView.ReadOnly = true; dataGridView.RowHeadersVisible = false; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(1049, 570); + dataGridView.Size = new Size(918, 426); dataGridView.TabIndex = 7; // // buttonTest // - buttonTest.Location = new Point(1106, 349); - buttonTest.Margin = new Padding(3, 4, 3, 4); + buttonTest.Location = new Point(968, 262); buttonTest.Name = "buttonTest"; - buttonTest.Size = new Size(226, 37); + buttonTest.Size = new Size(198, 28); buttonTest.TabIndex = 12; - buttonTest.Text = "ТЕСТ"; + buttonTest.Text = "Удалить все данные"; buttonTest.UseVisualStyleBackColor = true; 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 // - AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1387, 600); + ClientSize = new Size(1214, 450); + Controls.Add(buttonPsqlToMongo); Controls.Add(buttonTest); Controls.Add(buttonIssuedTask); Controls.Add(buttonTaskReady); @@ -172,7 +177,6 @@ Controls.Add(dataGridView); Controls.Add(menuStrip1); MainMenuStrip = menuStrip1; - Margin = new Padding(3, 4, 3, 4); Name = "FormMain"; Text = "Главное окно"; Load += FormMain_Load; @@ -197,5 +201,6 @@ private Button buttonCreateTask; private DataGridView dataGridView; private Button buttonTest; + private Button buttonPsqlToMongo; } } \ No newline at end of file diff --git a/SushiBar/SushiBar/FormMain.cs b/SushiBar/SushiBar/FormMain.cs index 90a0cae..bb21b29 100644 --- a/SushiBar/SushiBar/FormMain.cs +++ b/SushiBar/SushiBar/FormMain.cs @@ -1,6 +1,7 @@ using SushiBar; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicContracts; +using SushiBarMongoDB; using System; using System.Collections.Generic; using System.ComponentModel; @@ -16,14 +17,21 @@ namespace SushiBarView public partial class FormMain : Form { - private readonly ITaskLogic _logic; - private readonly ICookLogic _CLogic; + private readonly ITaskLogic _TaskLogic; + 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(); - _logic = logic; - _CLogic = cLogic; + _TaskLogic = logic; + _CookLogic = cLogic; + _BuyerLogic = buyerLogic; + _MenuLogic = menuLogic; + _PlaceLogic = placeLogic; } private void buyerToolStripMenuItem_Click(object sender, EventArgs e) @@ -69,7 +77,7 @@ namespace SushiBarView private void LoadData() { - var _list = _logic.ReadList(null); + var _list = _TaskLogic.ReadList(null); if (_list != null) { dataGridView.DataSource = _list; @@ -97,7 +105,7 @@ namespace SushiBarView int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); try { - var operationResult = _logic.TakeTaskInWork(new TaskBindingModel + var operationResult = _TaskLogic.TakeTaskInWork(new TaskBindingModel { Id = id, Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), @@ -122,7 +130,7 @@ namespace SushiBarView int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); try { - var operationResult = _logic.FinishTask(new TaskBindingModel + var operationResult = _TaskLogic.FinishTask(new TaskBindingModel { Id = id, Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), @@ -147,7 +155,7 @@ namespace SushiBarView int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); try { - var operationResult = _logic.DeliveryTask(new TaskBindingModel + var operationResult = _TaskLogic.DeliveryTask(new TaskBindingModel { Id = id, Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), @@ -168,25 +176,21 @@ namespace SushiBarView private void buttonTest_Click(object sender, EventArgs e) { - CookBindingModel model = new CookBindingModel() + try { - Id = 2, - CookName = "Иван", - CookSurname = "dssfsdfs", - Experience = 2, - PhoneNumber = "+79054324312", - Passport = "123124" - }; + _BuyerLogic.ClearEntity(); + _CookLogic.ClearEntity(); + _MenuLogic.ClearEntity(); + _PlaceLogic.ClearEntity(); + _TaskLogic.ClearEntity(); + LoadData(); + } + catch (Exception) { } + } - DateTime start = DateTime.Now; - _CLogic.Delete(model); - DateTime stop = DateTime.Now; - MessageBox.Show((start - stop).ToString(), "Test", MessageBoxButtons.OK); + private void buttonPsqlToMongo_Click(object sender, EventArgs e) + { + PostgresToMongo.Convert(); } } } - -//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; diff --git a/SushiBar/SushiBar/Program.cs b/SushiBar/SushiBar/Program.cs index 5ae1313..ec55139 100644 --- a/SushiBar/SushiBar/Program.cs +++ b/SushiBar/SushiBar/Program.cs @@ -3,8 +3,8 @@ using Microsoft.Extensions.Logging; using SushiBarBusinessLogic.BusinessLogics; using SushiBarContracts.BusinessLogicContracts; using SushiBarContracts.StoragesContracts; -//using SushiBarDatabaseImplement.Implements; -using SushiBarMongoDB.Implements; +using SushiBarDatabaseImplement.Implements; +//using SushiBarMongoDB.Implements; using SushiBarView; namespace SushiBar diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/BuyerLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/BuyerLogic.cs index d130dd4..aeb7e89 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/BuyerLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/BuyerLogic.cs @@ -90,5 +90,10 @@ namespace SushiBarBusinessLogic.BusinessLogics throw new ArgumentNullException("Нет названия", nameof(model.BuyerName)); } } + + public void ClearEntity() + { + _buyerStorage.ClearEntity(); + } } } diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/CookLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/CookLogic.cs index 7bfa486..9a60e1c 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/CookLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/CookLogic.cs @@ -89,5 +89,10 @@ namespace SushiBarBusinessLogic.BusinessLogics throw new ArgumentNullException("Нет названия", nameof(model.CookName)); } } + + public void ClearEntity() + { + _cookStorage.ClearEntity(); + } } } diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/MenuLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/MenuLogic.cs index 380ceee..e28c9ac 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/MenuLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/MenuLogic.cs @@ -89,5 +89,10 @@ namespace SushiBarBusinessLogic.BusinessLogics throw new ArgumentNullException("Нет названия", nameof(model.FoodName)); } } + + public void ClearEntity() + { + _menuStorage.ClearEntity(); + } } } diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/PlaceLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/PlaceLogic.cs index 562c4e8..b4deafb 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/PlaceLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/PlaceLogic.cs @@ -89,5 +89,10 @@ namespace SushiBarBusinessLogic.BusinessLogics throw new ArgumentNullException("Нет названия", nameof(model.PlaceNumber)); } } + + public void ClearEntity() + { + _placeStorage.ClearEntity(); + } } } diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/TaskLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/TaskLogic.cs index 888a31c..0612beb 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/TaskLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/TaskLogic.cs @@ -116,5 +116,10 @@ namespace SushiBarBusinessLogic.BusinessLogics return; } } + + public void ClearEntity() + { + _taskStorage.ClearEntity(); + } } } diff --git a/SushiBar/SushiBarContracts/BusinessLogicContracts/IBuyerLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicContracts/IBuyerLogic.cs index d0b7915..a0351bf 100644 --- a/SushiBar/SushiBarContracts/BusinessLogicContracts/IBuyerLogic.cs +++ b/SushiBar/SushiBarContracts/BusinessLogicContracts/IBuyerLogic.cs @@ -17,5 +17,6 @@ namespace SushiBarContracts.BusinessLogicContracts bool Create(BuyerBindingModel model); bool Update(BuyerBindingModel model); bool Delete(BuyerBindingModel model); + void ClearEntity(); } } diff --git a/SushiBar/SushiBarContracts/BusinessLogicContracts/ICookLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicContracts/ICookLogic.cs index e4d2b13..41c3183 100644 --- a/SushiBar/SushiBarContracts/BusinessLogicContracts/ICookLogic.cs +++ b/SushiBar/SushiBarContracts/BusinessLogicContracts/ICookLogic.cs @@ -17,5 +17,6 @@ namespace SushiBarContracts.BusinessLogicContracts bool Create(CookBindingModel model); bool Update(CookBindingModel model); bool Delete(CookBindingModel model); + void ClearEntity(); } } diff --git a/SushiBar/SushiBarContracts/BusinessLogicContracts/IMenuLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicContracts/IMenuLogic.cs index cb381a9..11f45f0 100644 --- a/SushiBar/SushiBarContracts/BusinessLogicContracts/IMenuLogic.cs +++ b/SushiBar/SushiBarContracts/BusinessLogicContracts/IMenuLogic.cs @@ -17,5 +17,6 @@ namespace SushiBarContracts.BusinessLogicContracts bool Create(MenuBindingModel model); bool Update(MenuBindingModel model); bool Delete(MenuBindingModel model); + void ClearEntity(); } } diff --git a/SushiBar/SushiBarContracts/BusinessLogicContracts/IPlaceLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicContracts/IPlaceLogic.cs index 812544f..555e176 100644 --- a/SushiBar/SushiBarContracts/BusinessLogicContracts/IPlaceLogic.cs +++ b/SushiBar/SushiBarContracts/BusinessLogicContracts/IPlaceLogic.cs @@ -17,5 +17,6 @@ namespace SushiBarContracts.BusinessLogicContracts bool Create(PlaceBindingModel model); bool Update(PlaceBindingModel model); bool Delete(PlaceBindingModel model); + void ClearEntity(); } } diff --git a/SushiBar/SushiBarContracts/BusinessLogicContracts/ITaskLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicContracts/ITaskLogic.cs index 5553ac2..c4722b6 100644 --- a/SushiBar/SushiBarContracts/BusinessLogicContracts/ITaskLogic.cs +++ b/SushiBar/SushiBarContracts/BusinessLogicContracts/ITaskLogic.cs @@ -20,5 +20,6 @@ namespace SushiBarContracts.BusinessLogicContracts bool TakeTaskInWork(TaskBindingModel model); bool FinishTask(TaskBindingModel model); bool DeliveryTask(TaskBindingModel model); + void ClearEntity(); } } diff --git a/SushiBar/SushiBarContracts/StoragesContracts/IBuyerStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/IBuyerStorage.cs index 56ead99..ff7707f 100644 --- a/SushiBar/SushiBarContracts/StoragesContracts/IBuyerStorage.cs +++ b/SushiBar/SushiBarContracts/StoragesContracts/IBuyerStorage.cs @@ -18,5 +18,6 @@ namespace SushiBarContracts.StoragesContracts BuyerViewModel? Insert(BuyerBindingModel model); BuyerViewModel? Update(BuyerBindingModel model); BuyerViewModel? Delete(BuyerBindingModel model); + void ClearEntity(); } } diff --git a/SushiBar/SushiBarContracts/StoragesContracts/ICookStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/ICookStorage.cs index 0273183..09bece9 100644 --- a/SushiBar/SushiBarContracts/StoragesContracts/ICookStorage.cs +++ b/SushiBar/SushiBarContracts/StoragesContracts/ICookStorage.cs @@ -18,5 +18,6 @@ namespace SushiBarContracts.StoragesContracts CookViewModel? Insert(CookBindingModel model); CookViewModel? Update(CookBindingModel model); CookViewModel? Delete(CookBindingModel model); + void ClearEntity(); } } diff --git a/SushiBar/SushiBarContracts/StoragesContracts/IMenuStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/IMenuStorage.cs index b5532b5..0f868f6 100644 --- a/SushiBar/SushiBarContracts/StoragesContracts/IMenuStorage.cs +++ b/SushiBar/SushiBarContracts/StoragesContracts/IMenuStorage.cs @@ -18,5 +18,6 @@ namespace SushiBarContracts.StoragesContracts MenuViewModel? Insert(MenuBindingModel model); MenuViewModel? Update(MenuBindingModel model); MenuViewModel? Delete(MenuBindingModel model); + void ClearEntity(); } } diff --git a/SushiBar/SushiBarContracts/StoragesContracts/IPlaceStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/IPlaceStorage.cs index 6e43ed3..7a5597d 100644 --- a/SushiBar/SushiBarContracts/StoragesContracts/IPlaceStorage.cs +++ b/SushiBar/SushiBarContracts/StoragesContracts/IPlaceStorage.cs @@ -18,5 +18,6 @@ namespace SushiBarContracts.StoragesContracts PlaceViewModel? Insert(PlaceBindingModel model); PlaceViewModel? Update(PlaceBindingModel model); PlaceViewModel? Delete(PlaceBindingModel model); + void ClearEntity(); } } diff --git a/SushiBar/SushiBarContracts/StoragesContracts/ITaskStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/ITaskStorage.cs index b5ec446..aaade8d 100644 --- a/SushiBar/SushiBarContracts/StoragesContracts/ITaskStorage.cs +++ b/SushiBar/SushiBarContracts/StoragesContracts/ITaskStorage.cs @@ -18,5 +18,6 @@ namespace SushiBarContracts.StoragesContracts TaskViewModel? Insert(TaskBindingModel model); TaskViewModel? Update(TaskBindingModel model); TaskViewModel? Delete(TaskBindingModel model); + void ClearEntity(); } } diff --git a/SushiBar/SushiBarDatabaseImplement/Implements/BuyerStorage.cs b/SushiBar/SushiBarDatabaseImplement/Implements/BuyerStorage.cs index bfcb573..28e0067 100644 --- a/SushiBar/SushiBarDatabaseImplement/Implements/BuyerStorage.cs +++ b/SushiBar/SushiBarDatabaseImplement/Implements/BuyerStorage.cs @@ -1,4 +1,5 @@ -using SushiBarContracts.BindingModels; +using Microsoft.EntityFrameworkCore; +using SushiBarContracts.BindingModels; using SushiBarContracts.SearchModels; using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; @@ -74,5 +75,13 @@ namespace SushiBarDatabaseImplement.Implements context.SaveChanges(); return component.GetViewModel; } + + public void ClearEntity() + { + using var context = new SushiBarDatabase(); + + string deleteAllQuery = "DELETE FROM \"Buyers\""; + context.Database.ExecuteSqlRaw(deleteAllQuery); + } } } diff --git a/SushiBar/SushiBarDatabaseImplement/Implements/CookStorage.cs b/SushiBar/SushiBarDatabaseImplement/Implements/CookStorage.cs index be418cd..bd4dca5 100644 --- a/SushiBar/SushiBarDatabaseImplement/Implements/CookStorage.cs +++ b/SushiBar/SushiBarDatabaseImplement/Implements/CookStorage.cs @@ -1,4 +1,5 @@ -using SushiBarContracts.BindingModels; +using Microsoft.EntityFrameworkCore; +using SushiBarContracts.BindingModels; using SushiBarContracts.SearchModels; using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; @@ -14,6 +15,14 @@ namespace SushiBarDatabaseImplement.Implements { 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) { using var context = new SushiBarDatabase(); diff --git a/SushiBar/SushiBarDatabaseImplement/Implements/MenuStorage.cs b/SushiBar/SushiBarDatabaseImplement/Implements/MenuStorage.cs index 4cc3583..4d7fb36 100644 --- a/SushiBar/SushiBarDatabaseImplement/Implements/MenuStorage.cs +++ b/SushiBar/SushiBarDatabaseImplement/Implements/MenuStorage.cs @@ -1,4 +1,5 @@ -using SushiBarContracts.BindingModels; +using Microsoft.EntityFrameworkCore; +using SushiBarContracts.BindingModels; using SushiBarContracts.SearchModels; using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; @@ -14,6 +15,14 @@ namespace SushiBarDatabaseImplement.Implements { 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) { using var context = new SushiBarDatabase(); diff --git a/SushiBar/SushiBarDatabaseImplement/Implements/PlaceStorage.cs b/SushiBar/SushiBarDatabaseImplement/Implements/PlaceStorage.cs index 0498f27..31499c4 100644 --- a/SushiBar/SushiBarDatabaseImplement/Implements/PlaceStorage.cs +++ b/SushiBar/SushiBarDatabaseImplement/Implements/PlaceStorage.cs @@ -1,4 +1,5 @@ -using SushiBarContracts.BindingModels; +using Microsoft.EntityFrameworkCore; +using SushiBarContracts.BindingModels; using SushiBarContracts.SearchModels; using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; @@ -14,6 +15,14 @@ namespace SushiBarDatabaseImplement.Implements { 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) { using var context = new SushiBarDatabase(); diff --git a/SushiBar/SushiBarDatabaseImplement/Implements/TaskStorage.cs b/SushiBar/SushiBarDatabaseImplement/Implements/TaskStorage.cs index efe3dd4..e88dde6 100644 --- a/SushiBar/SushiBarDatabaseImplement/Implements/TaskStorage.cs +++ b/SushiBar/SushiBarDatabaseImplement/Implements/TaskStorage.cs @@ -13,6 +13,14 @@ namespace SushiBarDatabaseImplement.Implements { 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) { using var context = new SushiBarDatabase(); diff --git a/SushiBar/SushiBarDatabaseImplement/Migrations/20240326181255_InitialCreate.Designer.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/20240507174252_InitMigration.Designer.cs similarity index 68% rename from SushiBar/SushiBarDatabaseImplement/Migrations/20240326181255_InitialCreate.Designer.cs rename to SushiBar/SushiBarDatabaseImplement/Migrations/20240507174252_InitMigration.Designer.cs index 935029e..55f55d5 100644 --- a/SushiBar/SushiBarDatabaseImplement/Migrations/20240326181255_InitialCreate.Designer.cs +++ b/SushiBar/SushiBarDatabaseImplement/Migrations/20240507174252_InitMigration.Designer.cs @@ -2,9 +2,9 @@ using System; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using SushiBarDatabaseImplement; #nullable disable @@ -12,8 +12,8 @@ using SushiBarDatabaseImplement; namespace SushiBarDatabaseImplement.Migrations { [DbContext(typeof(SushiBarDatabase))] - [Migration("20240326181255_InitialCreate")] - partial class InitialCreate + [Migration("20240507174252_InitMigration")] + partial class InitMigration { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -21,24 +21,24 @@ namespace SushiBarDatabaseImplement.Migrations #pragma warning disable 612, 618 modelBuilder .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 => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("BuyerBirthDate") - .HasColumnType("datetime2"); + .HasColumnType("timestamp without time zone"); b.Property("BuyerName") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.HasKey("Id"); @@ -49,28 +49,28 @@ namespace SushiBarDatabaseImplement.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("CookName") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("CookSurname") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("Experience") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("Passport") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("PhoneNumber") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.HasKey("Id"); @@ -81,20 +81,20 @@ namespace SushiBarDatabaseImplement.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("Description") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("FoodName") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("Price") - .HasColumnType("float"); + .HasColumnType("double precision"); b.HasKey("Id"); @@ -105,15 +105,15 @@ namespace SushiBarDatabaseImplement.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("CountPlaces") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("PlaceNumber") - .HasColumnType("int"); + .HasColumnType("integer"); b.HasKey("Id"); @@ -124,27 +124,27 @@ namespace SushiBarDatabaseImplement.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("BuyerId") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("CookId") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("FullPrice") - .HasColumnType("float"); + .HasColumnType("double precision"); b.Property("PlaceId") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("Status") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("TaskDate") - .HasColumnType("datetime2"); + .HasColumnType("timestamp without time zone"); b.HasKey("Id"); @@ -155,18 +155,18 @@ namespace SushiBarDatabaseImplement.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("Count") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("MenuId") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("TaskId") - .HasColumnType("int"); + .HasColumnType("integer"); b.HasKey("Id"); diff --git a/SushiBar/SushiBarDatabaseImplement/Migrations/20240326181255_InitialCreate.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/20240507174252_InitMigration.cs similarity index 54% rename from SushiBar/SushiBarDatabaseImplement/Migrations/20240326181255_InitialCreate.cs rename to SushiBar/SushiBarDatabaseImplement/Migrations/20240507174252_InitMigration.cs index a1f5031..7811642 100644 --- a/SushiBar/SushiBarDatabaseImplement/Migrations/20240326181255_InitialCreate.cs +++ b/SushiBar/SushiBarDatabaseImplement/Migrations/20240507174252_InitMigration.cs @@ -1,12 +1,13 @@ using System; using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace SushiBarDatabaseImplement.Migrations { /// - public partial class InitialCreate : Migration + public partial class InitMigration : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -15,10 +16,10 @@ namespace SushiBarDatabaseImplement.Migrations name: "Buyers", columns: table => new { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - BuyerName = table.Column(type: "nvarchar(max)", nullable: false), - BuyerBirthDate = table.Column(type: "datetime2", nullable: true) + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + BuyerName = table.Column(type: "text", nullable: false), + BuyerBirthDate = table.Column(type: "timestamp without time zone", nullable: true) }, constraints: table => { @@ -29,13 +30,13 @@ namespace SushiBarDatabaseImplement.Migrations name: "Cooks", columns: table => new { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - CookName = table.Column(type: "nvarchar(max)", nullable: false), - CookSurname = table.Column(type: "nvarchar(max)", nullable: false), - Experience = table.Column(type: "int", nullable: false), - PhoneNumber = table.Column(type: "nvarchar(max)", nullable: false), - Passport = table.Column(type: "nvarchar(max)", nullable: false) + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + CookName = table.Column(type: "text", nullable: false), + CookSurname = table.Column(type: "text", nullable: false), + Experience = table.Column(type: "integer", nullable: false), + PhoneNumber = table.Column(type: "text", nullable: false), + Passport = table.Column(type: "text", nullable: false) }, constraints: table => { @@ -46,11 +47,11 @@ namespace SushiBarDatabaseImplement.Migrations name: "Menus", columns: table => new { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - FoodName = table.Column(type: "nvarchar(max)", nullable: false), - Description = table.Column(type: "nvarchar(max)", nullable: false), - Price = table.Column(type: "float", nullable: false) + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + FoodName = table.Column(type: "text", nullable: false), + Description = table.Column(type: "text", nullable: false), + Price = table.Column(type: "double precision", nullable: false) }, constraints: table => { @@ -61,10 +62,10 @@ namespace SushiBarDatabaseImplement.Migrations name: "Places", columns: table => new { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - PlaceNumber = table.Column(type: "int", nullable: false), - CountPlaces = table.Column(type: "int", nullable: false) + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + PlaceNumber = table.Column(type: "integer", nullable: false), + CountPlaces = table.Column(type: "integer", nullable: false) }, constraints: table => { @@ -75,14 +76,14 @@ namespace SushiBarDatabaseImplement.Migrations name: "Tasks", columns: table => new { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - TaskDate = table.Column(type: "datetime2", nullable: false), - Status = table.Column(type: "int", nullable: false), - FullPrice = table.Column(type: "float", nullable: false), - PlaceId = table.Column(type: "int", nullable: false), - CookId = table.Column(type: "int", nullable: false), - BuyerId = table.Column(type: "int", nullable: false) + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + TaskDate = table.Column(type: "timestamp without time zone", nullable: false), + Status = table.Column(type: "integer", nullable: false), + FullPrice = table.Column(type: "double precision", nullable: false), + PlaceId = table.Column(type: "integer", nullable: false), + CookId = table.Column(type: "integer", nullable: false), + BuyerId = table.Column(type: "integer", nullable: false) }, constraints: table => { @@ -93,11 +94,11 @@ namespace SushiBarDatabaseImplement.Migrations name: "TaskMenus", columns: table => new { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - TaskId = table.Column(type: "int", nullable: false), - MenuId = table.Column(type: "int", nullable: false), - Count = table.Column(type: "int", nullable: false) + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + TaskId = table.Column(type: "integer", nullable: false), + MenuId = table.Column(type: "integer", nullable: false), + Count = table.Column(type: "integer", nullable: false) }, constraints: table => { diff --git a/SushiBar/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs index 5688d36..25ac086 100644 --- a/SushiBar/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs +++ b/SushiBar/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs @@ -2,8 +2,8 @@ using System; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using SushiBarDatabaseImplement; #nullable disable @@ -18,24 +18,24 @@ namespace SushiBarDatabaseImplement.Migrations #pragma warning disable 612, 618 modelBuilder .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 => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("BuyerBirthDate") - .HasColumnType("datetime2"); + .HasColumnType("timestamp without time zone"); b.Property("BuyerName") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.HasKey("Id"); @@ -46,28 +46,28 @@ namespace SushiBarDatabaseImplement.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("CookName") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("CookSurname") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("Experience") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("Passport") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("PhoneNumber") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.HasKey("Id"); @@ -78,20 +78,20 @@ namespace SushiBarDatabaseImplement.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("Description") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("FoodName") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("Price") - .HasColumnType("float"); + .HasColumnType("double precision"); b.HasKey("Id"); @@ -102,15 +102,15 @@ namespace SushiBarDatabaseImplement.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("CountPlaces") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("PlaceNumber") - .HasColumnType("int"); + .HasColumnType("integer"); b.HasKey("Id"); @@ -121,27 +121,27 @@ namespace SushiBarDatabaseImplement.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("BuyerId") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("CookId") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("FullPrice") - .HasColumnType("float"); + .HasColumnType("double precision"); b.Property("PlaceId") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("Status") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("TaskDate") - .HasColumnType("datetime2"); + .HasColumnType("timestamp without time zone"); b.HasKey("Id"); @@ -152,18 +152,18 @@ namespace SushiBarDatabaseImplement.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("Count") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("MenuId") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("TaskId") - .HasColumnType("int"); + .HasColumnType("integer"); b.HasKey("Id"); diff --git a/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs b/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs index 71b5a05..7b39b03 100644 --- a/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs +++ b/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs @@ -15,11 +15,15 @@ namespace SushiBarDatabaseImplement { 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); + AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); + AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true); } + //optionsBuilder.UseNpgsql(@"Host=localhost;Database=ComputersShop_db;Username=postgres;Password=postgres"); + public virtual DbSet Buyers { get; set; } public virtual DbSet Cooks { get; set; } public virtual DbSet Menus { get; set; } diff --git a/SushiBar/SushiBarMongoDB/Implements/CookStorage.cs b/SushiBar/SushiBarMongoDB/Implements/CookStorage.cs index c74f5cc..58b5df0 100644 --- a/SushiBar/SushiBarMongoDB/Implements/CookStorage.cs +++ b/SushiBar/SushiBarMongoDB/Implements/CookStorage.cs @@ -15,6 +15,14 @@ namespace SushiBarMongoDB.Implements { public class CookStorage : ICookStorage { + + public void ClearEntity() + { + using var context = new SushiBarMongoDB(); + context.GetCollection("Cooks") + .DeleteMany(Builders.Filter.Empty); + } + public List GetFullList() { using var context = new SushiBarMongoDB(); diff --git a/SushiBar/SushiBarMongoDB/PostgresToMongo.cs b/SushiBar/SushiBarMongoDB/PostgresToMongo.cs new file mode 100644 index 0000000..f7fb5d4 --- /dev/null +++ b/SushiBar/SushiBarMongoDB/PostgresToMongo.cs @@ -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("Buyers"); + var cooks = database.GetCollection("Cooks"); + var menus = database.GetCollection("Menus"); + var places = database.GetCollection("Places"); + var tasks = database.GetCollection("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