diff --git a/SushiBar/ImplementationExtensions/SushiBarContracts.dll b/SushiBar/ImplementationExtensions/SushiBarContracts.dll new file mode 100644 index 0000000..248121a Binary files /dev/null and b/SushiBar/ImplementationExtensions/SushiBarContracts.dll differ diff --git a/SushiBar/ImplementationExtensions/SushiBarDataModels.dll b/SushiBar/ImplementationExtensions/SushiBarDataModels.dll new file mode 100644 index 0000000..6242a3e Binary files /dev/null and b/SushiBar/ImplementationExtensions/SushiBarDataModels.dll differ diff --git a/SushiBar/ImplementationExtensions/SushiBarDatabaseImplement.dll b/SushiBar/ImplementationExtensions/SushiBarDatabaseImplement.dll new file mode 100644 index 0000000..2d7d96e Binary files /dev/null and b/SushiBar/ImplementationExtensions/SushiBarDatabaseImplement.dll differ diff --git a/SushiBar/ImplementationExtensions/SushiBarFileImplement.dll b/SushiBar/ImplementationExtensions/SushiBarFileImplement.dll new file mode 100644 index 0000000..1ed03b4 Binary files /dev/null and b/SushiBar/ImplementationExtensions/SushiBarFileImplement.dll differ diff --git a/SushiBar/ImplementationExtensions/SushiBarListImplement.dll b/SushiBar/ImplementationExtensions/SushiBarListImplement.dll new file mode 100644 index 0000000..4d66d2d Binary files /dev/null and b/SushiBar/ImplementationExtensions/SushiBarListImplement.dll differ diff --git a/SushiBar/SushiBar/DataGridViewExtension.cs b/SushiBar/SushiBar/DataGridViewExtension.cs new file mode 100644 index 0000000..7014c23 --- /dev/null +++ b/SushiBar/SushiBar/DataGridViewExtension.cs @@ -0,0 +1,46 @@ +using SushiBarContracts.Attributes; + +namespace SushiBarView +{ + internal static class DataGridViewExtension + { + public static void FillAndConfigGrid(this DataGridView grid, List? data) + { + if (data == null) + { + return; + } + grid.DataSource = data; + + var type = typeof(T); + var properties = type.GetProperties(); + foreach (DataGridViewColumn column in grid.Columns) + { + var property = properties.FirstOrDefault(x => x.Name == column.Name); + if (property == null) + { + throw new InvalidOperationException($"В типе {type.Name} не найдено свойство с именем {column.Name}"); + } + var attribute = property.GetCustomAttributes(typeof(ColumnAttribute), true)?.SingleOrDefault(); + if (attribute == null) + { + throw new InvalidOperationException($"Не найден атрибут типа ColumnAttribute для свойства {property.Name}"); + } + // ищем нужный нам атрибут + if (attribute is ColumnAttribute columnAttr) + { + column.HeaderText = columnAttr.Title; + column.Visible = columnAttr.Visible; + if (columnAttr.IsUseAutoSize) + { + column.AutoSizeMode = (DataGridViewAutoSizeColumnMode)Enum.Parse(typeof(DataGridViewAutoSizeColumnMode), columnAttr.GridViewAutoSize.ToString()); + } + else + { + column.Width = columnAttr.Width; + } + } + } + } + } +} diff --git a/SushiBar/SushiBar/FormClients.cs b/SushiBar/SushiBar/FormClients.cs index 98cdd76..f18923f 100644 --- a/SushiBar/SushiBar/FormClients.cs +++ b/SushiBar/SushiBar/FormClients.cs @@ -27,13 +27,7 @@ namespace SushiBarView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка клиентов"); } catch (Exception ex) diff --git a/SushiBar/SushiBar/FormImplementers.cs b/SushiBar/SushiBar/FormImplementers.cs index cb3425c..d07ad69 100644 --- a/SushiBar/SushiBar/FormImplementers.cs +++ b/SushiBar/SushiBar/FormImplementers.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.DI; namespace SushiBarView { @@ -20,14 +21,7 @@ namespace SushiBarView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ImplementerFIO"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка исполнителей"); } catch (Exception ex) @@ -45,13 +39,10 @@ namespace SushiBarView private void buttonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); - if (service is FormImplementer form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } @@ -59,14 +50,11 @@ namespace SushiBarView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); - if (service is FormImplementer form) + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } } diff --git a/SushiBar/SushiBar/FormIngredients.cs b/SushiBar/SushiBar/FormIngredients.cs index 781205f..85ee5a2 100644 --- a/SushiBar/SushiBar/FormIngredients.cs +++ b/SushiBar/SushiBar/FormIngredients.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.DI; namespace SushiBarView { @@ -40,27 +41,21 @@ namespace SushiBarView } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormIngredient)); - if (service is FormIngredient form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } private void ButtonUpd_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormIngredient)); - if (service is FormIngredient form) + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } } diff --git a/SushiBar/SushiBar/FormListSushi.cs b/SushiBar/SushiBar/FormListSushi.cs index d20376b..4b5037c 100644 --- a/SushiBar/SushiBar/FormListSushi.cs +++ b/SushiBar/SushiBar/FormListSushi.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.DI; namespace SushiBarView { @@ -42,13 +43,10 @@ namespace SushiBarView private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormSushi)); - if (service is FormSushi form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } @@ -56,14 +54,11 @@ namespace SushiBarView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormSushi)); - if (service is FormSushi form) + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } } diff --git a/SushiBar/SushiBar/FormMain.Designer.cs b/SushiBar/SushiBar/FormMain.Designer.cs index 773bf04..aeb58d0 100644 --- a/SushiBar/SushiBar/FormMain.Designer.cs +++ b/SushiBar/SushiBar/FormMain.Designer.cs @@ -39,20 +39,21 @@ списокСушиToolStripMenuItem = new ToolStripMenuItem(); сушиСИнгредиентамиToolStripMenuItem = new ToolStripMenuItem(); списокЗаказовToolStripMenuItem = new ToolStripMenuItem(); + письмаToolStripMenuItem = new ToolStripMenuItem(); buttonUpdate = new Button(); buttonSetToFinish = new Button(); buttonSetToDone = new Button(); buttonSetToWork = new Button(); buttonCreateOrder = new Button(); dataGridView = new DataGridView(); - письмаToolStripMenuItem = new ToolStripMenuItem(); + создатьБекапToolStripMenuItem = new ToolStripMenuItem(); menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); // // menuStrip // - menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem }); + menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, создатьБекапToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; menuStrip.Size = new Size(1112, 24); @@ -69,35 +70,35 @@ // ингредиентыToolStripMenuItem // ингредиентыToolStripMenuItem.Name = "ингредиентыToolStripMenuItem"; - ингредиентыToolStripMenuItem.Size = new Size(154, 22); + ингредиентыToolStripMenuItem.Size = new Size(180, 22); ингредиентыToolStripMenuItem.Text = "Ингредиенты"; ингредиентыToolStripMenuItem.Click += IngredientsToolStripMenuItem_Click; // // сушиToolStripMenuItem // сушиToolStripMenuItem.Name = "сушиToolStripMenuItem"; - сушиToolStripMenuItem.Size = new Size(154, 22); + сушиToolStripMenuItem.Size = new Size(180, 22); сушиToolStripMenuItem.Text = "Суши"; сушиToolStripMenuItem.Click += SushiToolStripMenuItem_Click; // // клиентыToolStripMenuItem // клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - клиентыToolStripMenuItem.Size = new Size(154, 22); + клиентыToolStripMenuItem.Size = new Size(180, 22); клиентыToolStripMenuItem.Text = "Клиенты"; клиентыToolStripMenuItem.Click += клиентыToolStripMenuItem_Click; // // исполнителиToolStripMenuItem // исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; - исполнителиToolStripMenuItem.Size = new Size(154, 22); + исполнителиToolStripMenuItem.Size = new Size(180, 22); исполнителиToolStripMenuItem.Text = "Исполнители"; исполнителиToolStripMenuItem.Click += employersToolStripMenuItem_Click; // // начатьРаботуToolStripMenuItem // начатьРаботуToolStripMenuItem.Name = "начатьРаботуToolStripMenuItem"; - начатьРаботуToolStripMenuItem.Size = new Size(154, 22); + начатьРаботуToolStripMenuItem.Size = new Size(180, 22); начатьРаботуToolStripMenuItem.Text = "Начать работу"; начатьРаботуToolStripMenuItem.Click += startWorkToolStripMenuItem_Click; // @@ -129,6 +130,13 @@ списокЗаказовToolStripMenuItem.Text = "Список заказов"; списокЗаказовToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; // + // письмаToolStripMenuItem + // + письмаToolStripMenuItem.Name = "письмаToolStripMenuItem"; + письмаToolStripMenuItem.Size = new Size(203, 22); + письмаToolStripMenuItem.Text = "Письма"; + письмаToolStripMenuItem.Click += письмаToolStripMenuItem_Click; + // // buttonUpdate // buttonUpdate.Anchor = AnchorStyles.Top | AnchorStyles.Right; @@ -201,12 +209,12 @@ dataGridView.Size = new Size(919, 426); dataGridView.TabIndex = 7; // - // письмаToolStripMenuItem + // создатьБекапToolStripMenuItem // - письмаToolStripMenuItem.Name = "письмаToolStripMenuItem"; - письмаToolStripMenuItem.Size = new Size(203, 22); - письмаToolStripMenuItem.Text = "Письма"; - письмаToolStripMenuItem.Click += письмаToolStripMenuItem_Click; + создатьБекапToolStripMenuItem.Name = "создатьБекапToolStripMenuItem"; + создатьБекапToolStripMenuItem.Size = new Size(97, 20); + создатьБекапToolStripMenuItem.Text = "Создать бекап"; + создатьБекапToolStripMenuItem.Click += создатьБекапToolStripMenuItem_Click; // // FormMain // @@ -251,5 +259,6 @@ private ToolStripMenuItem исполнителиToolStripMenuItem; private ToolStripMenuItem начатьРаботуToolStripMenuItem; private ToolStripMenuItem письмаToolStripMenuItem; + private ToolStripMenuItem создатьБекапToolStripMenuItem; } } \ No newline at end of file diff --git a/SushiBar/SushiBar/FormMain.cs b/SushiBar/SushiBar/FormMain.cs index e9057ef..2706a7e 100644 --- a/SushiBar/SushiBar/FormMain.cs +++ b/SushiBar/SushiBar/FormMain.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.DI; namespace SushiBarView { @@ -10,8 +11,8 @@ namespace SushiBarView private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; private readonly IWorkProcess _workProcess; - - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) + private readonly IBackUpLogic _backUpLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess, IBackUpLogic backUpLogic) { InitializeComponent(); _logger = logger; @@ -19,6 +20,8 @@ namespace SushiBarView _reportLogic = reportLogic; _workProcess = workProcess; _workProcess = workProcess; + _backUpLogic = backUpLogic; + LoadData(); } private void FormMain_Load(object sender, EventArgs e) { @@ -29,14 +32,7 @@ namespace SushiBarView _logger.LogInformation("Загрузка заказов"); try { - var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["SushiId"].Visible = false; - dataGridView.Columns["Implementerid"].Visible = false; - dataGridView.Columns["ClientEmail"].Visible = false; - } + dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null)); _logger.LogInformation("Загрузка заказов"); } catch (Exception ex) @@ -47,28 +43,19 @@ namespace SushiBarView } private void IngredientsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormIngredients)); - if (service is FormIngredients form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void SushiToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormListSushi)); - if (service is FormListSushi form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void ButtonCreateOrder_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); - if (service is FormCreateOrder form) - { - form.ShowDialog(); - LoadData(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + LoadData(); } private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) { @@ -152,61 +139,67 @@ namespace SushiBarView } private void SushiListToolStripMenuItem_Click(object sender, EventArgs e) { - using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; - if (dialog.ShowDialog() == DialogResult.OK) - { - _reportLogic.SaveListSushiToWordFile(new ReportBindingModel { FileName = dialog.FileName }); - MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void SushiIngredientToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportSushiIngredients)); - if (service is FormReportSushiIngredients form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); - if (service is FormReportOrders form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void клиентыToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormClients)); - if (service is FormClients form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void employersToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); - if (service is FormImplementers form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void startWorkToolStripMenuItem_Click(object sender, EventArgs e) { - _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); - MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + _workProcess.DoWork(DependencyManager.Instance.Resolve(), _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); } private void письмаToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormViewMail)); - if (service is FormViewMail form) + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } + private void создатьБекапToolStripMenuItem_Click(object sender, EventArgs e) + { + try { - form.ShowDialog(); + if (_backUpLogic != null) + { + var fbd = new FolderBrowserDialog(); + if (fbd.ShowDialog() == DialogResult.OK) + { + _backUpLogic.CreateBackUp(new BackUpSaveBindingModel + { + FolderName = fbd.SelectedPath + }); + MessageBox.Show("Бекап создан", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); } } } diff --git a/SushiBar/SushiBar/FormSushi.cs b/SushiBar/SushiBar/FormSushi.cs index 515011f..111bc50 100644 --- a/SushiBar/SushiBar/FormSushi.cs +++ b/SushiBar/SushiBar/FormSushi.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.DI; using SushiBarContracts.SearchModels; using SushiBarDataModels.Models; @@ -70,23 +71,25 @@ namespace SushiBarView } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormSushiIngredients)); - if (service is FormSushiIngredients form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) + if (form.IngredientModel == null) { if (form.IngredientModel == null) { return; } - _logger.LogInformation("Добавление нового ингредиента: { IngredientName} - { Count}", form.IngredientModel.IngredientName, form.Count); + _logger.LogInformation("Добавление нового компонента:{ ComponentName}-{ Count}", form.IngredientModel.IngredientName, form.Count); if (_sushiIngredients.ContainsKey(form.Id)) { - _sushiIngredients[form.Id] = (form.IngredientModel, form.Count); + _sushiIngredients[form.Id] = (form.IngredientModel, + form.Count); } else { - _sushiIngredients.Add(form.Id, (form.IngredientModel, form.Count)); + _sushiIngredients.Add(form.Id, (form.IngredientModel, + form.Count)); } LoadData(); } @@ -96,22 +99,19 @@ namespace SushiBarView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormSushiIngredients)); - if (service is FormSushiIngredients form) + var form = DependencyManager.Instance.Resolve(); + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _sushiIngredients[id].Item2; + if (form.ShowDialog() == DialogResult.OK) { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); - form.Id = id; - form.Count = _sushiIngredients[id].Item2; - if (form.ShowDialog() == DialogResult.OK) + if (form.IngredientModel == null) { - if (form.IngredientModel == null) - { - return; - } - _logger.LogInformation("Изменение ингредиента: { IngredientName} - { Count} ", form.IngredientModel.IngredientName, form.Count); - _sushiIngredients[form.Id] = (form.IngredientModel, form.Count); - LoadData(); + return; } + _logger.LogInformation("Изменение компонента:{ ComponentName}-{ Count}", form.IngredientModel.IngredientName, form.Count); + _sushiIngredients[form.Id] = (form.IngredientModel, form.Count); + LoadData(); } } } diff --git a/SushiBar/SushiBar/Program.cs b/SushiBar/SushiBar/Program.cs index 4605c28..6d8f230 100644 --- a/SushiBar/SushiBar/Program.cs +++ b/SushiBar/SushiBar/Program.cs @@ -10,13 +10,13 @@ using SushiBarDatabaseImplement.Implements; using SushiBarBusinessLogic; using SushiBarBusinessLogic.MailWorker; using SushiBarContracts.BindingModels; +using SushiBarContracts.DI; namespace SushiBarView { internal static class Program { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; + /// /// The main entry point for the application. /// @@ -26,76 +26,69 @@ namespace SushiBarView // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - var services = new ServiceCollection(); - ConfigureServices(services); - _serviceProvider = services.BuildServiceProvider(); - try - { - var mailSender = _serviceProvider.GetService(); - mailSender?.MailConfig(new MailConfigBindingModel - { - MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, - MailPassword = System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? string.Empty, - SmtpClientHost = System.Configuration.ConfigurationManager.AppSettings["SmtpClientHost"] ?? string.Empty, - SmtpClientPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpClientPort"]), - PopHost = System.Configuration.ConfigurationManager.AppSettings["PopHost"] ?? string.Empty, - PopPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"]) - }); + InitDependency(); + try + { + var mailSender = DependencyManager.Instance.Resolve(); mailSender?.MailConfig(new MailConfigBindingModel + { + MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, + MailPassword = System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? string.Empty, + SmtpClientHost = System.Configuration.ConfigurationManager.AppSettings["SmtpClientHost"] ?? string.Empty, + SmtpClientPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpClientPort"]), + PopHost = System.Configuration.ConfigurationManager.AppSettings["PopHost"] ?? string.Empty, + PopPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"]) + }); - var timer = new System.Threading.Timer(new TimerCallback(MailCheck!), null, 0, 100000); - } - catch (Exception ex) - { - var logger = _serviceProvider.GetService(); - logger?.LogError(ex, "<22><> <20><> <20> <20><>"); - } + var timer = new System.Threading.Timer(new TimerCallback(MailCheck!), null, 0, 100000); + } + catch (Exception ex) + { + var logger = DependencyManager.Instance.Resolve(); + logger?.LogError(ex, "<22><> <20><> <20> <20><>"); + } - Application.Run(_serviceProvider.GetRequiredService()); - } + Application.Run(DependencyManager.Instance.Resolve()); + } - private static void ConfigureServices(ServiceCollection services) + private static void InitDependency() { - services.AddLogging(option => + DependencyManager.InitDependency(); + + DependencyManager.Instance.AddLogging(option => { option.SetMinimumLevel(LogLevel.Information); option.AddNLog("nlog.config"); }); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + DependencyManager.Instance.RegisterType(true); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); - - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddSingleton(); - } - private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); - } + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + private static void MailCheck(object obj) => DependencyManager.Instance.Resolve()?.MailCheck(); + } } diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/BackUpLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/BackUpLogic.cs new file mode 100644 index 0000000..9d82936 --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/BackUpLogic.cs @@ -0,0 +1,103 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarDataModels; +using System; +using System.Collections.Generic; +using System.IO.Compression; +using System.Linq; +using System.Reflection; +using System.Runtime.Serialization.Json; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarBusinessLogic.BusinessLogics +{ + public class BackUpLogic : IBackUpLogic + { + private readonly ILogger _logger; + + private readonly IBackUpInfo _backUpInfo; + + public BackUpLogic(ILogger logger, IBackUpInfo backUpInfo) + { + _logger = logger; + _backUpInfo = backUpInfo; + } + + public void CreateBackUp(BackUpSaveBindingModel model) + { + if (_backUpInfo == null) + { + return; + } + try + { + _logger.LogDebug("Clear folder"); + // зачистка папки и удаление старого архива + var dirInfo = new DirectoryInfo(model.FolderName); + if (dirInfo.Exists) + { + foreach (var file in dirInfo.GetFiles()) + { + file.Delete(); + } + } + _logger.LogDebug("Delete archive"); + string fileName = $"{model.FolderName}.zip"; + if (File.Exists(fileName)) + { + File.Delete(fileName); + } + // берем метод для сохранения + _logger.LogDebug("Get assembly"); + var typeIId = typeof(IId); + var assembly = typeIId.Assembly; + if (assembly == null) + { + throw new ArgumentNullException("Сборка не найдена", nameof(assembly)); + } + var types = assembly.GetTypes(); + var method = GetType().GetMethod("SaveToFile", BindingFlags.NonPublic | BindingFlags.Instance); + _logger.LogDebug("Find {count} types", types.Length); + foreach (var type in types) + { + if (type.IsInterface && type.GetInterface(typeIId.Name) != null) + { + var modelType = _backUpInfo.GetTypeByModelInterface(type.Name); + if (modelType == null) + { + throw new InvalidOperationException($"Не найден класс-модель для {type.Name}"); + } + _logger.LogDebug("Call SaveToFile method for {name} type", type.Name); + // вызываем метод на выполнение + method?.MakeGenericMethod(modelType).Invoke(this, new object[] { model.FolderName }); + } + } + _logger.LogDebug("Create zip and remove folder"); + // архивируем + ZipFile.CreateFromDirectory(model.FolderName, fileName); + // удаляем папку + dirInfo.Delete(true); + } + catch (Exception) + { + throw; + } + } + + private void SaveToFile(string folderName) where T : class, new() + { + var records = _backUpInfo.GetList(); + if (records == null) + { + _logger.LogWarning("{type} type get null list", typeof(T).Name); + return; + } + var jsonFormatter = new DataContractJsonSerializer(typeof(List)); + using var fs = new FileStream(string.Format("{0}/{1}.json", folderName, typeof(T).Name), FileMode.OpenOrCreate); + jsonFormatter.WriteObject(fs, records); + } + } +} diff --git a/SushiBar/SushiBarContracts/Attributes/ColumnAttribute.cs b/SushiBar/SushiBarContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..0c7aa5c --- /dev/null +++ b/SushiBar/SushiBarContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.Attributes +{ + [AttributeUsage(AttributeTargets.Property)] + public class ColumnAttribute : Attribute + { + public string Title { get; private set; } + + public bool Visible { get; private set; } + + public int Width { get; private set; } + + public GridViewAutoSize GridViewAutoSize { get; private set; } + + public bool IsUseAutoSize { get; private set; } + + public ColumnAttribute(string title = "", bool visible = true, int width = 0, GridViewAutoSize gridViewAutoSize = GridViewAutoSize.None, bool isUseAutoSize = false) + { + Title = title; + Visible = visible; + Width = width; + GridViewAutoSize = gridViewAutoSize; + IsUseAutoSize = isUseAutoSize; + } + } +} diff --git a/SushiBar/SushiBarContracts/Attributes/GridViewAutoSize.cs b/SushiBar/SushiBarContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..796e101 --- /dev/null +++ b/SushiBar/SushiBarContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.Attributes +{ + public enum GridViewAutoSize + { + NotSet = 0, + + None = 1, + + ColumnHeader = 2, + + AllCellsExceptHeader = 4, + + AllCells = 6, + + DisplayedCellsExceptHeader = 8, + + DisplayedCells = 10, + + Fill = 16 + } +} diff --git a/SushiBar/SushiBarContracts/BindingModels/BackUpSaveBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/BackUpSaveBindingModel.cs new file mode 100644 index 0000000..876ae34 --- /dev/null +++ b/SushiBar/SushiBarContracts/BindingModels/BackUpSaveBindingModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.BindingModels +{ + public class BackUpSaveBindingModel + { + public string FolderName { get; set; } = string.Empty; + } +} diff --git a/SushiBar/SushiBarContracts/BindingModels/MessageInfoBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/MessageInfoBindingModel.cs index 7fcd282..194cd2f 100644 --- a/SushiBar/SushiBarContracts/BindingModels/MessageInfoBindingModel.cs +++ b/SushiBar/SushiBarContracts/BindingModels/MessageInfoBindingModel.cs @@ -1,4 +1,4 @@ -using PrecastConcretePlantDataModels.Models; +using SushiBarDataModels.Models; using SushiBarDataModels.Models; using System; using System.Collections.Generic; @@ -16,5 +16,6 @@ namespace SushiBarContracts.BindingModels public string Subject { get; set; } = string.Empty; public string Body { get; set; } = string.Empty; public DateTime DateDelivery { get; set; } - } + public int Id => throw new NotImplementedException(); + } } diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IBackUpLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..ba20b47 --- /dev/null +++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -0,0 +1,14 @@ +using SushiBarContracts.BindingModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.BusinessLogicsContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBindingModel model); + } +} diff --git a/SushiBar/SushiBarContracts/DI/DependencyManager.cs b/SushiBar/SushiBarContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..c281781 --- /dev/null +++ b/SushiBar/SushiBarContracts/DI/DependencyManager.cs @@ -0,0 +1,41 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.DI +{ + public class DependencyManager + { + private readonly IDependencyContainer _dependencyManager; + + private static DependencyManager? _manager; + + private static readonly object _locjObject = new(); + + private DependencyManager() + { + _dependencyManager = new ServiceDependencyContainer(); + } + + public static DependencyManager Instance { get { if (_manager == null) { lock (_locjObject) { _manager = new DependencyManager(); } } return _manager; } } + + public static void InitDependency() + { + var ext = ServiceProviderLoader.GetImplementationExtensions(); + if (ext == null) + { + throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям"); + } + // регистрируем зависимости + ext.RegisterServices(); + } + + public void AddLogging(Action configure) => _dependencyManager.AddLogging(configure); + public void RegisterType(bool isSingle = false) where U : class, T where T : class => _dependencyManager.RegisterType(isSingle); + public void RegisterType(bool isSingle = false) where T : class => _dependencyManager.RegisterType(isSingle); + public T Resolve() => _dependencyManager.Resolve(); + } +} diff --git a/SushiBar/SushiBarContracts/DI/IDependencyContainer.cs b/SushiBar/SushiBarContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..3aab857 --- /dev/null +++ b/SushiBar/SushiBarContracts/DI/IDependencyContainer.cs @@ -0,0 +1,20 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.DI +{ + public interface IDependencyContainer + { + void AddLogging(Action configure); + + void RegisterType(bool isSingle) where U : class, T where T : class; + + void RegisterType(bool isSingle) where T : class; + + T Resolve(); + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/DI/IImplementationExtension.cs b/SushiBar/SushiBarContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..8321d20 --- /dev/null +++ b/SushiBar/SushiBarContracts/DI/IImplementationExtension.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.DI +{ + public interface IImplementationExtension + { + public int Priority { get; } + public void RegisterServices(); + } +} diff --git a/SushiBar/SushiBarContracts/DI/ServiceDependencyContainer.cs b/SushiBar/SushiBarContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..65b3e4a --- /dev/null +++ b/SushiBar/SushiBarContracts/DI/ServiceDependencyContainer.cs @@ -0,0 +1,62 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.DI +{ + public class ServiceDependencyContainer : IDependencyContainer + { + private ServiceProvider? _serviceProvider; + + private readonly ServiceCollection _serviceCollection; + + public ServiceDependencyContainer() + { + _serviceCollection = new ServiceCollection(); + } + + public void AddLogging(Action configure) + { + _serviceCollection.AddLogging(configure); + } + + public void RegisterType(bool isSingle) where U : class, T where T : class + { + if (isSingle) + { + _serviceCollection.AddSingleton(); + } + else + { + _serviceCollection.AddTransient(); + } + _serviceProvider = null; + } + + public void RegisterType(bool isSingle) where T : class + { + if (isSingle) + { + _serviceCollection.AddSingleton(); + } + else + { + _serviceCollection.AddTransient(); + } + _serviceProvider = null; + } + + public T Resolve() + { + if (_serviceProvider == null) + { + _serviceProvider = _serviceCollection.BuildServiceProvider(); + } + return _serviceProvider.GetService()!; + } + } +} diff --git a/SushiBar/SushiBarContracts/DI/ServiceProviderLoader.cs b/SushiBar/SushiBarContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..de1b619 --- /dev/null +++ b/SushiBar/SushiBarContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.DI +{ + public class ServiceProviderLoader + { + public static IImplementationExtension? GetImplementationExtensions() + { + IImplementationExtension? source = null; + var files = Directory.GetFiles(TryGetImplementationExtensionsFolder(), "*.dll", SearchOption.AllDirectories); + foreach (var file in files.Distinct()) + { + Assembly asm = Assembly.LoadFrom(file); + foreach (var t in asm.GetExportedTypes()) + { + if (t.IsClass && typeof(IImplementationExtension).IsAssignableFrom(t)) + { + if (source == null) + { + source = (IImplementationExtension)Activator.CreateInstance(t)!; + } + else + { + var newSource = (IImplementationExtension)Activator.CreateInstance(t)!; + if (newSource.Priority > source.Priority) + { + source = newSource; + } + } + } + } + } + return source; + } + + private static string TryGetImplementationExtensionsFolder() + { + var directory = new DirectoryInfo(Directory.GetCurrentDirectory()); + while (directory != null && !directory.GetDirectories("ImplementationExtensions", SearchOption.AllDirectories).Any(x => x.Name == "ImplementationExtensions")) + { + directory = directory.Parent; + } + return $"{directory?.FullName}\\ImplementationExtensions"; + } + } +} diff --git a/SushiBar/SushiBarContracts/DI/UnityDependencyContainer.cs b/SushiBar/SushiBarContracts/DI/UnityDependencyContainer.cs new file mode 100644 index 0000000..cfa3110 --- /dev/null +++ b/SushiBar/SushiBarContracts/DI/UnityDependencyContainer.cs @@ -0,0 +1,43 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Unity; +using Unity.Microsoft.Logging; + +namespace SushiBarContracts.DI +{ + public class UnityDependencyContainer : IDependencyContainer + { + private readonly IUnityContainer _container; + + public UnityDependencyContainer() + { + _container = new UnityContainer(); + } + + public void AddLogging(Action configure) + { + var factory = LoggerFactory.Create(configure); + _container.AddExtension(new LoggingExtension(factory)); + } + + public void RegisterType(bool isSingle) where T : class + { + _container.RegisterType(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient); + + } + + public T Resolve() + { + return _container.Resolve(); + } + + void IDependencyContainer.RegisterType(bool isSingle) + { + _container.RegisterType(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient); + } + } +} diff --git a/SushiBar/SushiBarContracts/StoragesContracts/IBackUpInfo.cs b/SushiBar/SushiBarContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..a678e2e --- /dev/null +++ b/SushiBar/SushiBarContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.StoragesContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} diff --git a/SushiBar/SushiBarContracts/SushiBarContracts.csproj b/SushiBar/SushiBarContracts/SushiBarContracts.csproj index 22d1530..48069ed 100644 --- a/SushiBar/SushiBarContracts/SushiBarContracts.csproj +++ b/SushiBar/SushiBarContracts/SushiBarContracts.csproj @@ -6,6 +6,12 @@ enable + + + + + + diff --git a/SushiBar/SushiBarContracts/ViewModels/ClientViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/ClientViewModel.cs index c0968f7..4f49fa7 100644 --- a/SushiBar/SushiBarContracts/ViewModels/ClientViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/ClientViewModel.cs @@ -1,4 +1,5 @@ -using SushiBarDataModels; +using SushiBarContracts.Attributes; +using SushiBarDataModels; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,17 +11,14 @@ namespace SushiBarContracts.ViewModels { public class ClientViewModel : IClientModel { + [Column(visible: false)] public int Id { get; set; } - - [DisplayName("ФИО Клиента")] + [Column("ФИО клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ClientFIO { get; set; } = string.Empty; - - [DisplayName("Логин (эл. почтаы)")] + [Column("Логин (эл. почта)", width: 150)] public string Email { get; set; } = string.Empty; - - [DisplayName("Пароль")] + [Column("Пароль", width: 150)] public string Password { get; set; } = string.Empty; - } } diff --git a/SushiBar/SushiBarContracts/ViewModels/ImplementerViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/ImplementerViewModel.cs index 192c8dc..abbc6fd 100644 --- a/SushiBar/SushiBarContracts/ViewModels/ImplementerViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/ImplementerViewModel.cs @@ -1,4 +1,5 @@ -using SushiBarDataModels.Models; +using SushiBarContracts.Attributes; +using SushiBarDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,18 +11,19 @@ namespace SushiBarContracts.ViewModels { public class ImplementerViewModel : IImplementerModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("ФИО исполнителя")] + [Column("ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Пароль")] + [Column("Пароль", width: 150)] public string Password { get; set; } = string.Empty; - [DisplayName("Стаж работы")] + [Column("Стаж работы", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int WorkExperience { get; set; } - [DisplayName("Квалификация")] + [Column("Квалификация", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int Qualification { get; set; } } } diff --git a/SushiBar/SushiBarContracts/ViewModels/IngredientViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/IngredientViewModel.cs index eada9d4..7f2e198 100644 --- a/SushiBar/SushiBarContracts/ViewModels/IngredientViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/IngredientViewModel.cs @@ -1,14 +1,16 @@ -using SushiBarDataModels.Models; +using SushiBarContracts.Attributes; +using SushiBarDataModels.Models; using System.ComponentModel; namespace SushiBarContracts.ViewModels { public class IngredientViewModel : IIngredientModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название ингредиента")] + [Column("Название компонента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string IngredientName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column("Цена", width: 80)] public double Cost { get; set; } } } diff --git a/SushiBar/SushiBarContracts/ViewModels/MessageInfoViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/MessageInfoViewModel.cs index f4c4557..d94c9f6 100644 --- a/SushiBar/SushiBarContracts/ViewModels/MessageInfoViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/MessageInfoViewModel.cs @@ -1,4 +1,5 @@ -using PrecastConcretePlantDataModels.Models; +using SushiBarContracts.Attributes; +using SushiBarDataModels.Models; using SushiBarDataModels.Models; using System; using System.Collections.Generic; @@ -11,20 +12,23 @@ namespace SushiBarContracts.ViewModels { public class MessageInfoViewModel : IMessageInfoModel { - public string MessageId { get; set; } = string.Empty; + [Column(visible: false)] + public string MessageId { get; set; } = string.Empty; + [Column(visible: false)] + public int? ClientId { get; set; } - public int? ClientId { get; set; } + [Column("Отправитель", gridViewAutoSize: GridViewAutoSize.DisplayedCells, isUseAutoSize: true)] + public string SenderName { get; set; } = string.Empty; - [DisplayName("Отправитель")] - public string SenderName { get; set; } = string.Empty; + [Column("Дата письма", width: 100)] + public DateTime DateDelivery { get; set; } - [DisplayName("Дата письма")] - public DateTime DateDelivery { get; set; } + [Column("Заголовок", width: 150)] + public string Subject { get; set; } = string.Empty; - [DisplayName("Заголовок")] - public string Subject { get; set; } = string.Empty; - - [DisplayName("Текст")] - public string Body { get; set; } = string.Empty; - } + [Column("Текст", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string Body { get; set; } = string.Empty; + [Column(visible: false)] + public int Id => throw new NotImplementedException(); + } } diff --git a/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs index 22003be..93b4bbc 100644 --- a/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs @@ -1,4 +1,5 @@ -using SushiBarDataModels.Enums; +using SushiBarContracts.Attributes; +using SushiBarDataModels.Enums; using SushiBarDataModels.Models; using System.ComponentModel; @@ -6,34 +7,38 @@ namespace SushiBarContracts.ViewModels { public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] + [Column("Номер", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int Id { get; set; } + [Column(visible: false)] public int? ImplementerId { get; set; } - [DisplayName("Исполнитель")] + [Column("Фамилия исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string? ImplementerFIO { get; set; } = null; + [Column(visible: false)] public int SushiId { get; set; } + [Column(visible: false)] public int ClientId { get; set; } + [Column(visible: false)] public string ClientEmail { get; set; } = string.Empty; - [DisplayName("ФИО клиента")] + [Column("Фамилия клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Изделие")] + [Column("Изделие", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public string SushiName { get; set; } = string.Empty; - [DisplayName("Количество")] + [Column("Количество", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int Count { get; set; } - [DisplayName("Сумма")] + [Column("Сумма", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public double Sum { get; set; } - [DisplayName("Статус")] + [Column("Статус", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] + [Column("Дата создания", width: 100)] public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] + [Column("Дата выполнения", width: 100)] public DateTime? DateImplement { get; set; } } } \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs index 1312769..baafc9c 100644 --- a/SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs @@ -1,15 +1,18 @@ -using SushiBarDataModels.Models; +using SushiBarContracts.Attributes; +using SushiBarDataModels.Models; using System.ComponentModel; namespace SushiBarContracts.ViewModels { public class SushiViewModel : ISushiModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название изделия")] + [Column("Название изделия", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string SushiName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column("Цена", width: 100)] public double Price { get; set; } + [Column(visible: false)] public Dictionary SushiIngredients{ get; set; } = new(); } } \ No newline at end of file diff --git a/SushiBar/SushiBarDataModels/Models/IMessageInfoModel.cs b/SushiBar/SushiBarDataModels/Models/IMessageInfoModel.cs index 5da4404..9450cf9 100644 --- a/SushiBar/SushiBarDataModels/Models/IMessageInfoModel.cs +++ b/SushiBar/SushiBarDataModels/Models/IMessageInfoModel.cs @@ -1,12 +1,13 @@ -using System; +using SushiBarDataModels; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace PrecastConcretePlantDataModels.Models +namespace SushiBarDataModels.Models { - public interface IMessageInfoModel + public interface IMessageInfoModel : IId { string MessageId { get; } diff --git a/SushiBar/SushiBarDatabaseImplement/DataBaseImplementationExtension.cs b/SushiBar/SushiBarDatabaseImplement/DataBaseImplementationExtension.cs new file mode 100644 index 0000000..cf484f9 --- /dev/null +++ b/SushiBar/SushiBarDatabaseImplement/DataBaseImplementationExtension.cs @@ -0,0 +1,30 @@ +using SushiBarContracts.DI; +using SushiBarContracts.StoragesContracts; +using SushiBarDatabaseImplement.Models; +using SushiBarContracts.StoragesContracts; +using SushiBarDatabaseImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarDatabaseImplement +{ + internal class DataBaseImplementationExtension : IImplementationExtension + { + public int Priority => 2; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + + } +} diff --git a/SushiBar/SushiBarDatabaseImplement/Models/BackUpInfo.cs b/SushiBar/SushiBarDatabaseImplement/Models/BackUpInfo.cs new file mode 100644 index 0000000..a591e9b --- /dev/null +++ b/SushiBar/SushiBarDatabaseImplement/Models/BackUpInfo.cs @@ -0,0 +1,31 @@ +using SushiBarContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarDatabaseImplement.Models +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + using var context = new SushiBarDatabase(); + return context.Set().ToList(); + } + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + var assembly = typeof(BackUpInfo).Assembly; + var types = assembly.GetTypes(); + foreach (var type in types) + { + if (type.IsClass && type.GetInterface(modelInterfaceName) != null) + { + return type; + } + } + return null; + } + } +} diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Client.cs b/SushiBar/SushiBarDatabaseImplement/Models/Client.cs index fde667a..bd1b2c4 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Client.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Client.cs @@ -3,24 +3,32 @@ using SushiBarContracts.ViewModels; using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; using SushiBarDataModels; +using System.Runtime.Serialization; namespace SushiBarDatabaseImplement.Models { + [DataContract] public class Client : IClientModel { + [DataMember] public int Id { get; private set; } [Required] + [DataMember] public string ClientFIO { get; private set; } = string.Empty; [Required] + [DataMember] public string Email { get; private set; } = string.Empty; [Required] + [DataMember] public string Password { get; private set; } = string.Empty; [ForeignKey("ClientId")] public virtual List Orders { get; set; } = new(); + [ForeignKey("ClientId")] + public virtual List Messages { get; set; } = new(); public static Client? Create(ClientBindingModel? model) { diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Implementer.cs b/SushiBar/SushiBarDatabaseImplement/Models/Implementer.cs index edb1f81..0bb109b 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Implementer.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Implementer.cs @@ -8,23 +8,30 @@ using System.Threading.Tasks; using SushiBarContracts.BindingModels; using SushiBarDatabaseImplement.Models; using SushiBarContracts.ViewModels; +using System.Runtime.Serialization; namespace SushiBarDataModels.Models { + [DataContract] public class Implementer : IImplementerModel { + [DataMember] public int Id { get; set; } [Required] + [DataMember] public string ImplementerFIO { get; set; } = string.Empty; [Required] + [DataMember] public string Password { get; set; } = string.Empty; [Required] + [DataMember] public int WorkExperience { get; set; } [Required] + [DataMember] public int Qualification { get; set; } [ForeignKey("ImplementerId")] diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Ingredient.cs b/SushiBar/SushiBarDatabaseImplement/Models/Ingredient.cs index 37d313f..48fb28a 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Ingredient.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Ingredient.cs @@ -3,17 +3,22 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace SushiBarDatabaseImplement.Models { + [DataContract] public class Ingredient : IIngredientModel { + [DataMember] public int Id { get; private set; } [Required] + [DataMember] public string IngredientName { get; private set; } = string.Empty; [Required] + [DataMember] public double Cost { get; set; } [ForeignKey("IngredientId")] diff --git a/SushiBar/SushiBarDatabaseImplement/Models/MessageInfo.cs b/SushiBar/SushiBarDatabaseImplement/Models/MessageInfo.cs index 10b0699..d9387c2 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/MessageInfo.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/MessageInfo.cs @@ -1,14 +1,17 @@ -using PrecastConcretePlantDataModels.Models; +using SushiBarDataModels.Models; using SushiBarContracts.BindingModels; using SushiBarContracts.ViewModels; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace SushiBarDatabaseImplement.Models { + [DataContract] public class MessageInfo : IMessageInfoModel { [Key] + [DataMember] public string MessageId { get; private set; } = string.Empty; public int? ClientId { get; private set; } @@ -49,6 +52,6 @@ namespace SushiBarDatabaseImplement.Models SenderName = SenderName, DateDelivery = DateDelivery, }; - + public int Id => throw new NotImplementedException(); } } diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Order.cs b/SushiBar/SushiBarDatabaseImplement/Models/Order.cs index d24f89b..d3fd0a8 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Order.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Order.cs @@ -3,29 +3,40 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Enums; using SushiBarDataModels.Models; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace SushiBarDatabaseImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] + public int Id { get; set; } + [DataMember] [Required] public int SushiId { get; set; } [Required] + [DataMember] public int Count { get; set; } [Required] + [DataMember] public int ClientId { get; set; } [Required] + [DataMember] public double Sum { get; set; } [Required] + [DataMember] public OrderStatus Status { get; set; } [Required] + [DataMember] public DateTime DateCreate { get; set; } + [DataMember] public DateTime? DateImplement { get; set; } - public int Id { get; set; } - public virtual Client? Client { get; set; } - public Sushi? Sushi { get; set; } + [DataMember] public int? ImplementerId { get; private set; } + public virtual Client? Client { get; set; } + public Sushi? Sushi { get; set; } public virtual Implementer? Implementer { get; set; } = new(); public static Order? Create(SushiBarDatabase context, OrderBindingModel? model) diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Sushi.cs b/SushiBar/SushiBarDatabaseImplement/Models/Sushi.cs index 009329f..c260ba3 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Sushi.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Sushi.cs @@ -3,22 +3,28 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace SushiBarDatabaseImplement.Models { + [DataContract] public class Sushi : ISushiModel { + [DataMember] public int Id { get; set; } [Required] + [DataMember] public string SushiName { get; set; } = string.Empty; [Required] + [DataMember] public double Price { get; set; } private Dictionary? _sushiIngredients = null; [NotMapped] + [DataMember] public Dictionary SushiIngredients { get diff --git a/SushiBar/SushiBarDatabaseImplement/SushiBarDatabaseImplement.csproj b/SushiBar/SushiBarDatabaseImplement/SushiBarDatabaseImplement.csproj index ec6a8f0..672291c 100644 --- a/SushiBar/SushiBarDatabaseImplement/SushiBarDatabaseImplement.csproj +++ b/SushiBar/SushiBarDatabaseImplement/SushiBarDatabaseImplement.csproj @@ -1,4 +1,4 @@ - + net8.0 @@ -20,4 +20,8 @@ + + + + diff --git a/SushiBar/SushiBarFileImplement/DataFileSingleton.cs b/SushiBar/SushiBarFileImplement/DataFileSingleton.cs index b0c1fcc..f8bf6b3 100644 --- a/SushiBar/SushiBarFileImplement/DataFileSingleton.cs +++ b/SushiBar/SushiBarFileImplement/DataFileSingleton.cs @@ -16,6 +16,7 @@ namespace SushiBarFileImplement public List ListSushi { get; private set; } public List Clients { get; private set; } public List Implementers { get; private set; } + public List Messages { get; private set; } public static DataFileSingleton GetInstance() { @@ -32,6 +33,7 @@ namespace SushiBarFileImplement public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement); + public void SaveMessages() => SaveData(Orders, ImplementerFileName, "Messages", x => x.GetXElement); private DataFileSingleton() { diff --git a/SushiBar/SushiBarFileImplement/FileImplementationExtension.cs b/SushiBar/SushiBarFileImplement/FileImplementationExtension.cs new file mode 100644 index 0000000..8ada815 --- /dev/null +++ b/SushiBar/SushiBarFileImplement/FileImplementationExtension.cs @@ -0,0 +1,28 @@ +using SushiBarContracts.DI; +using SushiBarContracts.StoragesContracts; +using SushiBarFileImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarFileImplement +{ + public class FileImplementationExtension : IImplementationExtension + { + public int Priority => 1; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + + } +} diff --git a/SushiBar/SushiBarFileImplement/Implements/BackUpInfo.cs b/SushiBar/SushiBarFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..776dd14 --- /dev/null +++ b/SushiBar/SushiBarFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,34 @@ +using SushiBarContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarFileImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + // Получаем значения из singleton-объекта универсального свойства содержащее тип T + var source = DataFileSingleton.GetInstance(); + return (List?)source.GetType().GetProperties() + .FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == typeof(T)) + ?.GetValue(source); + } + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + var assembly = typeof(BackUpInfo).Assembly; + var types = assembly.GetTypes(); + foreach (var type in types) + { + if (type.IsClass && type.GetInterface(modelInterfaceName) != null) + { + return type; + } + } + return null; + } + } +} diff --git a/SushiBar/SushiBarFileImplement/Implements/ClientStorage.cs b/SushiBar/SushiBarFileImplement/Implements/ClientStorage.cs index efc6a96..cc8e790 100644 --- a/SushiBar/SushiBarFileImplement/Implements/ClientStorage.cs +++ b/SushiBar/SushiBarFileImplement/Implements/ClientStorage.cs @@ -1,11 +1,12 @@ using SushiBarContracts.BindingModel; using SushiBarContracts.SearchModel; +using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; using SushiBarFileImplement.Models; namespace SushiBarFileImplement.Implements { - public class ClientStorage + public class ClientStorage : IClientStorage { private readonly DataFileSingleton source; public ClientStorage() diff --git a/SushiBar/SushiBarFileImplement/Implements/MessageInfoStorage.cs b/SushiBar/SushiBarFileImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..527ec4c --- /dev/null +++ b/SushiBar/SushiBarFileImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,58 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarFileImplement.Implements +{ + public class MessageInfoStorage : IMessageInfoStorage + { + private readonly DataFileSingleton _source; + public MessageInfoStorage() + { + _source = DataFileSingleton.GetInstance(); + } + + public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) + { + if (model.MessageId != null) + { + return _source.Messages.FirstOrDefault(x => x.MessageId == model.MessageId)?.GetViewModel; + } + return null; + } + + public List GetFilteredList(MessageInfoSearchModel model) + { + return _source.Messages + .Where(x => x.ClientId == model.ClientId) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + return _source.Messages + .Select(x => x.GetViewModel) + .ToList(); + } + + public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + { + var newMessage = MessageInfo.Create(model); + if (newMessage == null) + { + return null; + } + _source.Messages.Add(newMessage); + _source.SaveMessages(); + return newMessage.GetViewModel; + } + } +} diff --git a/SushiBar/SushiBarFileImplement/Models/Client.cs b/SushiBar/SushiBarFileImplement/Models/Client.cs index 5a837bd..8dd82bd 100644 --- a/SushiBar/SushiBarFileImplement/Models/Client.cs +++ b/SushiBar/SushiBarFileImplement/Models/Client.cs @@ -1,15 +1,21 @@ using SushiBarContracts.BindingModel; using SushiBarContracts.ViewModels; using SushiBarDataModels; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SushiBarFileImplement.Models { + [DataContract] public class Client : IClientModel { + [DataMember] public int Id { get; private set; } - public string ClientFIO { get; private set; } = string.Empty; - public string Email { get; private set; } = string.Empty; + [DataMember] + public string ClientFIO { get; private set; } = string.Empty; + [DataMember] + public string Email { get; private set; } = string.Empty; + [DataMember] public string Password { get; private set; } = string.Empty; public static Client? Create(ClientBindingModel model) { diff --git a/SushiBar/SushiBarFileImplement/Models/Implementer.cs b/SushiBar/SushiBarFileImplement/Models/Implementer.cs index da8bcc8..2057142 100644 --- a/SushiBar/SushiBarFileImplement/Models/Implementer.cs +++ b/SushiBar/SushiBarFileImplement/Models/Implementer.cs @@ -4,22 +4,25 @@ using SushiBarDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace SushiBarFileImplement.Models { + [DataContract] public class Implementer : IImplementerModel { + [DataMember] public int Id { get; private set; } - + [DataMember] public string ImplementerFIO { get; private set; } = string.Empty; - + [DataMember] public string Password { get; private set; } = string.Empty; - + [DataMember] public int WorkExperience { get; private set; } - + [DataMember] public int Qualification { get; private set; } public static Implementer? Create(XElement element) diff --git a/SushiBar/SushiBarFileImplement/Models/Ingredient.cs b/SushiBar/SushiBarFileImplement/Models/Ingredient.cs index d940c5a..4a98380 100644 --- a/SushiBar/SushiBarFileImplement/Models/Ingredient.cs +++ b/SushiBar/SushiBarFileImplement/Models/Ingredient.cs @@ -1,14 +1,19 @@ using SushiBarContracts.BindingModels; using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SushiBarFileImplement.Models { + [DataContract] public class Ingredient : IIngredientModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string IngredientName { get; private set; } = string.Empty; + [DataMember] public double Cost { get; set; } public static Ingredient? Create(IngredientBindingModel model) { diff --git a/SushiBar/SushiBarFileImplement/Models/MessageInfo.cs b/SushiBar/SushiBarFileImplement/Models/MessageInfo.cs new file mode 100644 index 0000000..62903ba --- /dev/null +++ b/SushiBar/SushiBarFileImplement/Models/MessageInfo.cs @@ -0,0 +1,84 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace SushiBarFileImplement.Models +{ + [DataContract] + public class MessageInfo : IMessageInfoModel + { + [DataMember] + public string MessageId { get; private set; } = string.Empty; + [DataMember] + public int? ClientId { get; private set; } + [DataMember] + public string SenderName { get; private set; } = string.Empty; + [DataMember] + public DateTime DateDelivery { get; private set; } = DateTime.Now; + [DataMember] + public string Subject { get; private set; } = string.Empty; + [DataMember] + public string Body { get; private set; } = string.Empty; + + public static MessageInfo? Create(MessageInfoBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Body = model.Body, + Subject = model.Subject, + ClientId = model.ClientId, + MessageId = model.MessageId, + SenderName = model.SenderName, + DateDelivery = model.DateDelivery, + }; + } + + public static MessageInfo? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + Body = element.Attribute("Body")!.Value, + Subject = element.Attribute("Subject")!.Value, + ClientId = Convert.ToInt32(element.Attribute("ClientId")!.Value), + MessageId = element.Attribute("MessageId")!.Value, + SenderName = element.Attribute("SenderName")!.Value, + DateDelivery = Convert.ToDateTime(element.Attribute("DateDelivery")!.Value), + }; + } + + public MessageInfoViewModel GetViewModel => new() + { + Body = Body, + Subject = Subject, + ClientId = ClientId, + MessageId = MessageId, + SenderName = SenderName, + DateDelivery = DateDelivery, + }; + + public XElement GetXElement => new("MessageInfo", + new XAttribute("Body", Body), + new XAttribute("Subject", Subject), + new XAttribute("ClientId", ClientId), + new XAttribute("MessageId", MessageId), + new XAttribute("SenderName", SenderName), + new XAttribute("DateDelivery", DateDelivery) + ); + public int Id => throw new NotImplementedException(); + } +} diff --git a/SushiBar/SushiBarFileImplement/Models/Order.cs b/SushiBar/SushiBarFileImplement/Models/Order.cs index d762731..3118533 100644 --- a/SushiBar/SushiBarFileImplement/Models/Order.cs +++ b/SushiBar/SushiBarFileImplement/Models/Order.cs @@ -2,20 +2,31 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Enums; using SushiBarDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SushiBarFileImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int Id { get; private set; } + [DataMember] public int SushiId { get; private set; } + [DataMember] public int ClientId { get; private set; } + [DataMember] public int? ImplementerId { get; set; } + [DataMember] public int Count { get; private set; } + [DataMember] public double Sum { get; private set; } - public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + [DataMember] + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + [DataMember] public DateTime DateCreate { get; private set; } = DateTime.Now; + [DataMember] public DateTime? DateImplement { get; private set; } public static Order? Create(OrderBindingModel? model) { diff --git a/SushiBar/SushiBarFileImplement/Models/Sushi.cs b/SushiBar/SushiBarFileImplement/Models/Sushi.cs index d697e76..4ea0f2c 100644 --- a/SushiBar/SushiBarFileImplement/Models/Sushi.cs +++ b/SushiBar/SushiBarFileImplement/Models/Sushi.cs @@ -1,14 +1,19 @@ using SushiBarContracts.BindingModels; using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SushiBarFileImplement.Models { + [DataContract] public class Sushi : ISushiModel { + [DataMember] public int Id { get; private set; } - public string SushiName { get; private set; } = string.Empty; + [DataMember] + public string SushiName { get; private set; } = string.Empty; + [DataMember] public double Price { get; private set; } public Dictionary Ingredients { get; private set; } = new(); private Dictionary? _productIngredients = null; diff --git a/SushiBar/SushiBarFileImplement/SushiBarFileImplement.csproj b/SushiBar/SushiBarFileImplement/SushiBarFileImplement.csproj index b4adc48..4ed33b8 100644 --- a/SushiBar/SushiBarFileImplement/SushiBarFileImplement.csproj +++ b/SushiBar/SushiBarFileImplement/SushiBarFileImplement.csproj @@ -11,4 +11,8 @@ + + + + diff --git a/SushiBar/SushiBarListImplement/DataListSingleton.cs b/SushiBar/SushiBarListImplement/DataListSingleton.cs index 5b6c0d2..9e0b832 100644 --- a/SushiBar/SushiBarListImplement/DataListSingleton.cs +++ b/SushiBar/SushiBarListImplement/DataListSingleton.cs @@ -11,6 +11,7 @@ namespace SushiBarListImplement public List ListSushi { get; set; } public List Clients { get; set; } public List Implementers { get; set; } + public List Messages { get; set; } private DataListSingleton() { Ingredients = new List(); @@ -18,6 +19,7 @@ namespace SushiBarListImplement ListSushi = new List(); Clients = new List(); Implementers = new List(); + Messages = new List(); } public static DataListSingleton GetInstance() { diff --git a/SushiBar/SushiBarListImplement/Implements/BackUpInfo.cs b/SushiBar/SushiBarListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..e6df037 --- /dev/null +++ b/SushiBar/SushiBarListImplement/Implements/BackUpInfo.cs @@ -0,0 +1,22 @@ +using SushiBarContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarListImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + throw new NotImplementedException(); + } + + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + throw new NotImplementedException(); + } + } +} diff --git a/SushiBar/SushiBarListImplement/Implements/ClientStorage.cs b/SushiBar/SushiBarListImplement/Implements/ClientStorage.cs index 22ea4d9..1e15f43 100644 --- a/SushiBar/SushiBarListImplement/Implements/ClientStorage.cs +++ b/SushiBar/SushiBarListImplement/Implements/ClientStorage.cs @@ -1,5 +1,6 @@ using SushiBarContracts.BindingModel; using SushiBarContracts.SearchModel; +using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; using SushiBarListImplement; using SushiBarListImplements.Models; @@ -11,7 +12,7 @@ using System.Threading.Tasks; namespace SushiBarListImplements.Implements { - public class ClientStorage + public class ClientStorage : IClientStorage { private readonly DataListSingleton _source; public ClientStorage() diff --git a/SushiBar/SushiBarListImplement/Implements/MessageInfoStorage.cs b/SushiBar/SushiBarListImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..e27abf4 --- /dev/null +++ b/SushiBar/SushiBarListImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,63 @@ + + +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarListImplement.Models; + +namespace SushiBarListImplement.Implements +{ + public class MessageInfoStorage : IMessageInfoStorage + { + private readonly DataListSingleton _source; + public MessageInfoStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) + { + foreach (var message in _source.Messages) + { + if (model.MessageId != null && model.MessageId.Equals(message.MessageId)) + return message.GetViewModel; + } + return null; + } + + public List GetFilteredList(MessageInfoSearchModel model) + { + List result = new(); + foreach (var item in _source.Messages) + { + if (item.ClientId.HasValue && item.ClientId == model.ClientId) + { + result.Add(item.GetViewModel); + } + } + return result; + } + + public List GetFullList() + { + List result = new(); + foreach (var item in _source.Messages) + { + result.Add(item.GetViewModel); + } + return result; + } + + public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + { + var newMessage = MessageInfo.Create(model); + if (newMessage == null) + { + return null; + } + _source.Messages.Add(newMessage); + return newMessage.GetViewModel; + } + } +} diff --git a/SushiBar/SushiBarListImplement/ListImplementationExtension.cs b/SushiBar/SushiBarListImplement/ListImplementationExtension.cs new file mode 100644 index 0000000..f171a48 --- /dev/null +++ b/SushiBar/SushiBarListImplement/ListImplementationExtension.cs @@ -0,0 +1,26 @@ + + +using SushiBarContracts.DI; +using SushiBarContracts.StoragesContracts; +using SushiBarListImplement.Implements; +using SushiBarListImplements.Implements; + +namespace SushiBarListImplement +{ + public class ListImplementationExtension : IImplementationExtension + { + public int Priority => 0; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + + } +} diff --git a/SushiBar/SushiBarListImplement/Models/Client.cs b/SushiBar/SushiBarListImplement/Models/Client.cs index 19359c7..4d9b24f 100644 --- a/SushiBar/SushiBarListImplement/Models/Client.cs +++ b/SushiBar/SushiBarListImplement/Models/Client.cs @@ -1,14 +1,19 @@ using SushiBarContracts.BindingModel; using SushiBarContracts.ViewModels; using SushiBarDataModels; +using System.Runtime.Serialization; namespace SushiBarListImplements.Models { public class Client : IClientModel { + public int Id { get; private set; } + public string ClientFIO { get; private set; } = string.Empty; + public string Email { get; set; } = string.Empty; + public string Password { get; set; } = string.Empty; public static Client? Create(ClientBindingModel? model) { diff --git a/SushiBar/SushiBarListImplement/Models/Implementer.cs b/SushiBar/SushiBarListImplement/Models/Implementer.cs index 45bbc3c..d133b57 100644 --- a/SushiBar/SushiBarListImplement/Models/Implementer.cs +++ b/SushiBar/SushiBarListImplement/Models/Implementer.cs @@ -4,21 +4,24 @@ using SushiBarDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace SushiBarListImplement.Models { + [DataContract] public class Implementer : IImplementerModel { + public int Id { get; private set; } - + public string ImplementerFIO { get; private set; } = string.Empty; - + public string Password { get; private set; } = string.Empty; - + public int WorkExperience { get; private set; } - + public int Qualification { get; private set; } public static Implementer? Create(ImplementerBindingModel model) diff --git a/SushiBar/SushiBarListImplement/Models/MessageInfo.cs b/SushiBar/SushiBarListImplement/Models/MessageInfo.cs new file mode 100644 index 0000000..d3852a0 --- /dev/null +++ b/SushiBar/SushiBarListImplement/Models/MessageInfo.cs @@ -0,0 +1,52 @@ + + +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; + +namespace SushiBarListImplement.Models +{ + public class MessageInfo : IMessageInfoModel + { + public string MessageId { get; private set; } = string.Empty; + + public int? ClientId { get; private set; } + + public string SenderName { get; private set; } = string.Empty; + + public DateTime DateDelivery { get; private set; } = DateTime.Now; + + public string Subject { get; private set; } = string.Empty; + + public string Body { get; private set; } = string.Empty; + + public static MessageInfo? Create(MessageInfoBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Body = model.Body, + Subject = model.Subject, + ClientId = model.ClientId, + MessageId = model.MessageId, + SenderName = model.SenderName, + DateDelivery = model.DateDelivery, + }; + } + + public MessageInfoViewModel GetViewModel => new() + { + Body = Body, + Subject = Subject, + ClientId = ClientId, + MessageId = MessageId, + SenderName = SenderName, + DateDelivery = DateDelivery, + }; + + public int Id => throw new NotImplementedException(); + } +} diff --git a/SushiBar/SushiBarListImplement/SushiBarListImplement.csproj b/SushiBar/SushiBarListImplement/SushiBarListImplement.csproj index b4adc48..4ed33b8 100644 --- a/SushiBar/SushiBarListImplement/SushiBarListImplement.csproj +++ b/SushiBar/SushiBarListImplement/SushiBarListImplement.csproj @@ -11,4 +11,8 @@ + + + +