From 8fb37a3a7caac8f1167c6885cc7e39d3ac158f3b Mon Sep 17 00:00:00 2001 From: dasha Date: Wed, 19 Apr 2023 17:28:03 +0400 Subject: [PATCH 1/9] =?UTF-8?q?=D0=BD=D1=83=20=D0=B2=D1=80=D0=BE=D0=B4?= =?UTF-8?q?=D0=B5=20=D0=B2=D1=81=D0=B5=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBar/App.config | 11 + SushiBar/SushiBar/FormMails.Designer.cs | 64 ++++ SushiBar/SushiBar/FormMails.cs | 40 +++ SushiBar/SushiBar/FormMails.resx | 120 ++++++++ SushiBar/SushiBar/FormMain.Designer.cs | 12 +- SushiBar/SushiBar/FormMain.cs | 9 + SushiBar/SushiBar/Program.cs | 28 ++ SushiBar/SushiBar/SushiBarView.csproj | 3 + .../BusinessLogics/MessageInfoLogic.cs | 43 +++ .../BusinessLogics/OrderLogic.cs | 31 +- .../MailWorker/AbstractMailWorker.cs | 92 ++++++ .../MailWorker/MailKitWorker.cs | 78 +++++ .../SushiBarBusinessLogic.csproj | 1 + .../Controllers/HomeController.cs | 10 + .../SushiBarClientApp/Views/Home/Mails.cshtml | 54 ++++ .../Views/Shared/_Layout.cshtml | 5 +- .../BindingModels/MailConfigBindingModel.cs | 17 ++ .../BindingModels/MailSendInfoBindingModel.cs | 11 + .../BindingModels/MessageInfoBindingModel.cs | 19 ++ .../IMessageInfoLogic.cs | 13 + .../SearchModels/MessageInfoSearchModel.cs | 9 + .../StoragesContracts/IMessageInfoStorage.cs | 17 ++ .../ViewModels/MessageInfoViewModel.cs | 24 ++ .../Models/IMessageInfoModel.cs | 17 ++ .../Implements/MessageInfoStorage.cs | 51 ++++ .../20230419132122_MessageMigr.Designer.cs | 285 ++++++++++++++++++ .../Migrations/20230419132122_MessageMigr.cs | 38 +++ .../SushiBarDatabaseModelSnapshot.cs | 28 ++ .../Models/Message.cs | 50 +++ .../SushiBarDatabase.cs | 2 + .../DataFileSingleton.cs | 4 + .../Implements/MessageInfoStorage.cs | 52 ++++ .../SushiBarFileImplement/Models/Message.cs | 76 +++++ .../DataListSingleton.cs | 4 +- .../Implements/MessageInfoStorage.cs | 68 +++++ .../SushiBarListImplement/Models/Message.cs | 48 +++ .../Controllers/ClientController.cs | 22 +- SushiBar/SushiBarRestApi/Program.cs | 17 ++ SushiBar/SushiBarRestApi/appsettings.json | 9 +- 39 files changed, 1474 insertions(+), 8 deletions(-) create mode 100644 SushiBar/SushiBar/App.config create mode 100644 SushiBar/SushiBar/FormMails.Designer.cs create mode 100644 SushiBar/SushiBar/FormMails.cs create mode 100644 SushiBar/SushiBar/FormMails.resx create mode 100644 SushiBar/SushiBarBusinessLogic/BusinessLogics/MessageInfoLogic.cs create mode 100644 SushiBar/SushiBarBusinessLogic/MailWorker/AbstractMailWorker.cs create mode 100644 SushiBar/SushiBarBusinessLogic/MailWorker/MailKitWorker.cs create mode 100644 SushiBar/SushiBarClientApp/Views/Home/Mails.cshtml create mode 100644 SushiBar/SushiBarContracts/BindingModels/MailConfigBindingModel.cs create mode 100644 SushiBar/SushiBarContracts/BindingModels/MailSendInfoBindingModel.cs create mode 100644 SushiBar/SushiBarContracts/BindingModels/MessageInfoBindingModel.cs create mode 100644 SushiBar/SushiBarContracts/BusinessLogicsContracts/IMessageInfoLogic.cs create mode 100644 SushiBar/SushiBarContracts/SearchModels/MessageInfoSearchModel.cs create mode 100644 SushiBar/SushiBarContracts/StoragesContracts/IMessageInfoStorage.cs create mode 100644 SushiBar/SushiBarContracts/ViewModels/MessageInfoViewModel.cs create mode 100644 SushiBar/SushiBarDataModels/Models/IMessageInfoModel.cs create mode 100644 SushiBar/SushiBarDatabaseImplement/Implements/MessageInfoStorage.cs create mode 100644 SushiBar/SushiBarDatabaseImplement/Migrations/20230419132122_MessageMigr.Designer.cs create mode 100644 SushiBar/SushiBarDatabaseImplement/Migrations/20230419132122_MessageMigr.cs create mode 100644 SushiBar/SushiBarDatabaseImplement/Models/Message.cs create mode 100644 SushiBar/SushiBarFileImplement/Implements/MessageInfoStorage.cs create mode 100644 SushiBar/SushiBarFileImplement/Models/Message.cs create mode 100644 SushiBar/SushiBarListImplement/Implements/MessageInfoStorage.cs create mode 100644 SushiBar/SushiBarListImplement/Models/Message.cs diff --git a/SushiBar/SushiBar/App.config b/SushiBar/SushiBar/App.config new file mode 100644 index 0000000..28415f5 --- /dev/null +++ b/SushiBar/SushiBar/App.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/SushiBar/SushiBar/FormMails.Designer.cs b/SushiBar/SushiBar/FormMails.Designer.cs new file mode 100644 index 0000000..39eec76 --- /dev/null +++ b/SushiBar/SushiBar/FormMails.Designer.cs @@ -0,0 +1,64 @@ +using DocumentFormat.OpenXml.Wordprocessing; + +namespace SushiBarView +{ + partial class FormMails + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(803, 450); + dataGridView.TabIndex = 0; + // + // FormMails + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Name = "FormMails"; + Text = "Письма"; + Load += FormMails_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBar/FormMails.cs b/SushiBar/SushiBar/FormMails.cs new file mode 100644 index 0000000..799addb --- /dev/null +++ b/SushiBar/SushiBar/FormMails.cs @@ -0,0 +1,40 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BusinessLogicsContracts; + +namespace SushiBarView +{ + public partial class FormMails : Form + { + private readonly ILogger _logger; + private readonly IMessageInfoLogic _logic; + + public FormMails(ILogger logger, IMessageInfoLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormMails_Load(object sender, EventArgs e) + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["MessageId"].Visible = false; + dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка писем"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки писем"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } +} diff --git a/SushiBar/SushiBar/FormMails.resx b/SushiBar/SushiBar/FormMails.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/SushiBar/SushiBar/FormMails.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SushiBar/SushiBar/FormMain.Designer.cs b/SushiBar/SushiBar/FormMain.Designer.cs index a017ded..365940f 100644 --- a/SushiBar/SushiBar/FormMain.Designer.cs +++ b/SushiBar/SushiBar/FormMain.Designer.cs @@ -43,6 +43,7 @@ this.buttonSetToFinish = new System.Windows.Forms.Button(); this.buttonCreateOrder = new System.Windows.Forms.Button(); this.dataGridView = new System.Windows.Forms.DataGridView(); + this.письмаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -52,7 +53,8 @@ this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.справочникиToolStripMenuItem, this.отчетыToolStripMenuItem, - this.запускРаботToolStripMenuItem}); + this.запускРаботToolStripMenuItem, + this.письмаToolStripMenuItem}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; this.menuStrip.Size = new System.Drawing.Size(1086, 24); @@ -181,6 +183,13 @@ this.dataGridView.Size = new System.Drawing.Size(899, 426); this.dataGridView.TabIndex = 7; // + // письмаToolStripMenuItem + // + this.письмаToolStripMenuItem.Name = "письмаToolStripMenuItem"; + this.письмаToolStripMenuItem.Size = new System.Drawing.Size(62, 20); + this.письмаToolStripMenuItem.Text = "Письма"; + this.письмаToolStripMenuItem.Click += new System.EventHandler(this.MailsToolStripMenuItem_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -220,5 +229,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 00f291c..2497490 100644 --- a/SushiBar/SushiBar/FormMain.cs +++ b/SushiBar/SushiBar/FormMain.cs @@ -205,5 +205,14 @@ namespace SushiBarView MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } + + private void MailsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormMails)); + if (service is FormMails form) + { + form.ShowDialog(); + } + } } } \ No newline at end of file diff --git a/SushiBar/SushiBar/Program.cs b/SushiBar/SushiBar/Program.cs index 3f66517..79f031c 100644 --- a/SushiBar/SushiBar/Program.cs +++ b/SushiBar/SushiBar/Program.cs @@ -7,6 +7,8 @@ using SushiBarBusinessLogic.OfficePackage; using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.StoragesContracts; using SushiBarDatabaseImplement.Implements; +using SushiBarBusinessLogic.MailWorker; +using SushiBarContracts.BindingModels; namespace SushiBarView { @@ -27,7 +29,27 @@ namespace SushiBarView 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"]) + }); + // + var timer = new System.Threading.Timer(new TimerCallback(MailCheck!), null, 0, 100000); + } + catch (Exception ex) + { + var logger = _serviceProvider.GetService(); + logger?.LogError(ex, " "); + } Application.Run(_serviceProvider.GetRequiredService()); } @@ -43,6 +65,7 @@ namespace SushiBarView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -50,7 +73,10 @@ namespace SushiBarView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddSingleton(); services.AddTransient(); services.AddTransient(); @@ -68,7 +94,9 @@ namespace SushiBarView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } + private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); } } diff --git a/SushiBar/SushiBar/SushiBarView.csproj b/SushiBar/SushiBar/SushiBarView.csproj index 18ff806..3c2c0b6 100644 --- a/SushiBar/SushiBar/SushiBarView.csproj +++ b/SushiBar/SushiBar/SushiBarView.csproj @@ -32,6 +32,9 @@ + + Always + Always diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/MessageInfoLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/MessageInfoLogic.cs new file mode 100644 index 0000000..59f5433 --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/MessageInfoLogic.cs @@ -0,0 +1,43 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; + +namespace SushiBarBusinessLogic.BusinessLogics +{ + public class MessageInfoLogic : IMessageInfoLogic + { + private readonly ILogger _logger; + private readonly IMessageInfoStorage _messageStorage; + public MessageInfoLogic(ILogger logger, IMessageInfoStorage messageStorage) + { + _logger = logger; + _messageStorage = messageStorage; + } + public bool Create(MessageInfoBindingModel model) + { + if (_messageStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public List? ReadList(MessageInfoSearchModel? model) + { + _logger.LogInformation("ReadList. MessageId:{MessageId}.ClientId:{ClientId} ", + model?.MessageId, model?.ClientId); + var list = model == null ? _messageStorage.GetFullList() : + _messageStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs index 171f94e..96f559f 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.Logging; +using SushiBarBusinessLogic.MailWorker; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.SearchModels; @@ -12,11 +13,15 @@ namespace SushiBarBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + private readonly AbstractMailWorker _mailWorker; + private readonly IClientLogic _clientLogic; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + public OrderLogic(ILogger logger, IOrderStorage orderStorage, AbstractMailWorker mailWorker, IClientLogic clientLogic) { _logger = logger; _orderStorage = orderStorage; + _mailWorker = mailWorker; + _clientLogic = clientLogic; } public List? ReadList(OrderSearchModel? model) { @@ -40,12 +45,14 @@ namespace SushiBarBusinessLogic.BusinessLogics return false; } model.Status = OrderStatus.Принят; - if (_orderStorage.Insert(model) == null) + var result = _orderStorage.Insert(model); + if (result == null) { model.Status = OrderStatus.Неизвестен; _logger.LogWarning("Insert operation failed"); return false; } + SendOrderMessage(result.ClientId, $"Суши-бар, Заказ №{result.Id}", $"Заказ №{result.Id} от {result.DateCreate} на сумму {result.Sum:0.00} принят"); return true; } private void CheckModel(OrderBindingModel model, bool withParams = true) @@ -92,12 +99,14 @@ namespace SushiBarBusinessLogic.BusinessLogics model.DateImplement = viewModel.DateImplement; } CheckModel(model, false); - if (_orderStorage.Update(model) == null) + var result = _orderStorage.Update(model); + if (result == null) { model.Status--; _logger.LogWarning("Update operation failed"); return false; } + SendOrderMessage(result.ClientId, $"Суши-бар, Заказ №{result.Id}", $"Заказ №{model.Id} изменен статус на {result.Status}"); return true; } @@ -132,5 +141,21 @@ namespace SushiBarBusinessLogic.BusinessLogics _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); return element; } + + private bool SendOrderMessage(int clientId, string subject, string text) + { + var client = _clientLogic.ReadElement(new() { Id = clientId }); + if (client == null) + { + return false; + } + _mailWorker.MailSendAsync(new() + { + MailAddress = client.Email, + Subject = subject, + Text = text + }); + return true; + } } } diff --git a/SushiBar/SushiBarBusinessLogic/MailWorker/AbstractMailWorker.cs b/SushiBar/SushiBarBusinessLogic/MailWorker/AbstractMailWorker.cs new file mode 100644 index 0000000..52a9624 --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic/MailWorker/AbstractMailWorker.cs @@ -0,0 +1,92 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace SushiBarBusinessLogic.MailWorker +{ + public abstract class AbstractMailWorker + { + protected string _mailLogin = string.Empty; + + protected string _mailPassword = string.Empty; + + protected string _smtpClientHost = string.Empty; + + protected int _smtpClientPort; + + protected string _popHost = string.Empty; + + protected int _popPort; + + private readonly IMessageInfoLogic _messageInfoLogic; + + private readonly ILogger _logger; + + public AbstractMailWorker(ILogger logger, IMessageInfoLogic messageInfoLogic) + { + _logger = logger; + _messageInfoLogic = messageInfoLogic; + } + + public void MailConfig(MailConfigBindingModel config) + { + _mailLogin = config.MailLogin; + _mailPassword = config.MailPassword; + _smtpClientHost = config.SmtpClientHost; + _smtpClientPort = config.SmtpClientPort; + _popHost = config.PopHost; + _popPort = config.PopPort; + _logger.LogDebug("Config: {login}, {password}, {clientHost}, {clientPOrt}, {popHost}, {popPort}", _mailLogin, _mailPassword, _smtpClientHost, _smtpClientPort, _popHost, _popPort); + } + + public async void MailSendAsync(MailSendInfoBindingModel info) + { + if (string.IsNullOrEmpty(_mailLogin) || string.IsNullOrEmpty(_mailPassword)) + { + return; + } + + if (string.IsNullOrEmpty(_smtpClientHost) || _smtpClientPort == 0) + { + return; + } + + if (string.IsNullOrEmpty(info.MailAddress) || string.IsNullOrEmpty(info.Subject) || string.IsNullOrEmpty(info.Text)) + { + return; + } + + _logger.LogDebug("Send Mail: {To}, {Subject}", info.MailAddress, info.Subject); + await SendMailAsync(info); + } + + public async void MailCheck() + { + if (string.IsNullOrEmpty(_mailLogin) || string.IsNullOrEmpty(_mailPassword)) + { + return; + } + + if (string.IsNullOrEmpty(_popHost) || _popPort == 0) + { + return; + } + + if (_messageInfoLogic == null) + { + return; + } + + var list = await ReceiveMailAsync(); + _logger.LogDebug("Check Mail: {Count} new mails", list.Count); + foreach (var mail in list) + { + _messageInfoLogic.Create(mail); + } + } + + protected abstract Task SendMailAsync(MailSendInfoBindingModel info); + + protected abstract Task> ReceiveMailAsync(); + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarBusinessLogic/MailWorker/MailKitWorker.cs b/SushiBar/SushiBarBusinessLogic/MailWorker/MailKitWorker.cs new file mode 100644 index 0000000..645528c --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic/MailWorker/MailKitWorker.cs @@ -0,0 +1,78 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using MailKit.Net.Pop3; +using MailKit.Security; +using Microsoft.Extensions.Logging; +using System.Net; +using System.Net.Mail; +using System.Text; + +namespace SushiBarBusinessLogic.MailWorker +{ + public class MailKitWorker : AbstractMailWorker + { + public MailKitWorker(ILogger logger, IMessageInfoLogic messageInfoLogic) : base(logger, messageInfoLogic) { } + + protected override async Task SendMailAsync(MailSendInfoBindingModel info) + { + using var objMailMessage = new MailMessage(); + using var objSmtpClient = new SmtpClient(_smtpClientHost, _smtpClientPort); + try + { + objMailMessage.From = new MailAddress(_mailLogin); + objMailMessage.To.Add(new MailAddress(info.MailAddress)); + objMailMessage.Subject = info.Subject; + objMailMessage.Body = info.Text; + objMailMessage.SubjectEncoding = Encoding.UTF8; + objMailMessage.BodyEncoding = Encoding.UTF8; + + objSmtpClient.UseDefaultCredentials = false; + objSmtpClient.EnableSsl = true; + objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; + objSmtpClient.Credentials = new NetworkCredential(_mailLogin, _mailPassword); + + await Task.Run(() => objSmtpClient.Send(objMailMessage)); + } + catch (Exception) + { + throw; + } + } + + protected override async Task> ReceiveMailAsync() + { + var list = new List(); + using var client = new Pop3Client(); + await Task.Run(() => + { + try + { + client.Connect(_popHost, _popPort, SecureSocketOptions.SslOnConnect); + client.Authenticate(_mailLogin, _mailPassword); + for (int i = 0; i < client.Count; i++) + { + var message = client.GetMessage(i); + foreach (var mail in message.From.Mailboxes) + { + list.Add(new MessageInfoBindingModel + { + DateDelivery = message.Date.DateTime, + MessageId = message.MessageId, + SenderName = mail.Address, + Subject = message.Subject, + Body = message.TextBody + }); + } + } + } + catch (AuthenticationException) + { } + finally + { + client.Disconnect(true); + } + }); + return list; + } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj b/SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj index ceb68ea..58817f5 100644 --- a/SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj +++ b/SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj @@ -8,6 +8,7 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/SushiBar/SushiBarClientApp/Controllers/HomeController.cs b/SushiBar/SushiBarClientApp/Controllers/HomeController.cs index 06c2de0..ebaf9ff 100644 --- a/SushiBar/SushiBarClientApp/Controllers/HomeController.cs +++ b/SushiBar/SushiBarClientApp/Controllers/HomeController.cs @@ -143,5 +143,15 @@ namespace SushiBarClientApp.Controllers var prod = APIClient.GetRequest($"api/main/getsushi?sushiId={sushi}"); return count * (prod?.Price ?? 1); } + + [HttpGet] + public IActionResult Mails() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/client/getmessages?clientId={APIClient.Client.Id}")); + } } } \ No newline at end of file diff --git a/SushiBar/SushiBarClientApp/Views/Home/Mails.cshtml b/SushiBar/SushiBarClientApp/Views/Home/Mails.cshtml new file mode 100644 index 0000000..aa313fa --- /dev/null +++ b/SushiBar/SushiBarClientApp/Views/Home/Mails.cshtml @@ -0,0 +1,54 @@ +@using SushiBarContracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "Mails"; +} + +
+

Заказы

+
+ + +
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + } + +
+ Дата письма + + Заголовок + + Текст +
+ @Html.DisplayFor(modelItem => item.DateDelivery) + + @Html.DisplayFor(modelItem => item.Subject) + + @Html.DisplayFor(modelItem => item.Body) +
+ } +
\ No newline at end of file diff --git a/SushiBar/SushiBarClientApp/Views/Shared/_Layout.cshtml b/SushiBar/SushiBarClientApp/Views/Shared/_Layout.cshtml index f644d1f..fc29d08 100644 --- a/SushiBar/SushiBarClientApp/Views/Shared/_Layout.cshtml +++ b/SushiBar/SushiBarClientApp/Views/Shared/_Layout.cshtml @@ -24,7 +24,10 @@ + + diff --git a/SushiBar/SushiBarContracts/BindingModels/MailConfigBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/MailConfigBindingModel.cs new file mode 100644 index 0000000..e8f20ad --- /dev/null +++ b/SushiBar/SushiBarContracts/BindingModels/MailConfigBindingModel.cs @@ -0,0 +1,17 @@ +namespace SushiBarContracts.BindingModels +{ + public class MailConfigBindingModel + { + public string MailLogin { get; set; } = string.Empty; + + public string MailPassword { get; set; } = string.Empty; + // откуда отправляем письма + public string SmtpClientHost { get; set; } = string.Empty; + + public int SmtpClientPort { get; set; } + // откуда получаем + public string PopHost { get; set; } = string.Empty; + + public int PopPort { get; set; } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/BindingModels/MailSendInfoBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/MailSendInfoBindingModel.cs new file mode 100644 index 0000000..ac7b746 --- /dev/null +++ b/SushiBar/SushiBarContracts/BindingModels/MailSendInfoBindingModel.cs @@ -0,0 +1,11 @@ +namespace SushiBarContracts.BindingModels +{ + public class MailSendInfoBindingModel + { + public string MailAddress { get; set; } = string.Empty; + + public string Subject { get; set; } = string.Empty; + + public string Text { get; set; } = string.Empty; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/BindingModels/MessageInfoBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/MessageInfoBindingModel.cs new file mode 100644 index 0000000..453ceb5 --- /dev/null +++ b/SushiBar/SushiBarContracts/BindingModels/MessageInfoBindingModel.cs @@ -0,0 +1,19 @@ +using SushiBarDataModels.Models; + +namespace SushiBarContracts.BindingModels +{ + public class MessageInfoBindingModel : IMessageInfoModel + { + public string MessageId { get; set; } = string.Empty; + + public int? ClientId { get; set; } + + public string SenderName { get; set; } = string.Empty; + + public string Subject { get; set; } = string.Empty; + + public string Body { get; set; } = string.Empty; + + public DateTime DateDelivery { get; set; } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IMessageInfoLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IMessageInfoLogic.cs new file mode 100644 index 0000000..1981f05 --- /dev/null +++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IMessageInfoLogic.cs @@ -0,0 +1,13 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; + +namespace SushiBarContracts.BusinessLogicsContracts +{ + public interface IMessageInfoLogic + { + List? ReadList(MessageInfoSearchModel? model); + + bool Create(MessageInfoBindingModel model); + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/SearchModels/MessageInfoSearchModel.cs b/SushiBar/SushiBarContracts/SearchModels/MessageInfoSearchModel.cs new file mode 100644 index 0000000..a7e5f83 --- /dev/null +++ b/SushiBar/SushiBarContracts/SearchModels/MessageInfoSearchModel.cs @@ -0,0 +1,9 @@ +namespace SushiBarContracts.SearchModels +{ + public class MessageInfoSearchModel + { + public int? ClientId { get; set; } + + public string? MessageId { get; set; } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/StoragesContracts/IMessageInfoStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/IMessageInfoStorage.cs new file mode 100644 index 0000000..ef768da --- /dev/null +++ b/SushiBar/SushiBarContracts/StoragesContracts/IMessageInfoStorage.cs @@ -0,0 +1,17 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; + +namespace SushiBarContracts.StoragesContracts +{ + public interface IMessageInfoStorage + { + List GetFullList(); + + List GetFilteredList(MessageInfoSearchModel model); + + MessageInfoViewModel? GetElement(MessageInfoSearchModel model); + + MessageInfoViewModel? Insert(MessageInfoBindingModel model); + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/ViewModels/MessageInfoViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/MessageInfoViewModel.cs new file mode 100644 index 0000000..ba77305 --- /dev/null +++ b/SushiBar/SushiBarContracts/ViewModels/MessageInfoViewModel.cs @@ -0,0 +1,24 @@ +using SushiBarDataModels.Models; +using System.ComponentModel; + +namespace SushiBarContracts.ViewModels +{ + public class MessageInfoViewModel : IMessageInfoModel + { + public string MessageId { get; set; } = string.Empty; + + public int? ClientId { get; set; } + + [DisplayName("Отправитель")] + public string SenderName { get; set; } = string.Empty; + + [DisplayName("Дата письма")] + public DateTime DateDelivery { get; set; } + + [DisplayName("Заголовок")] + public string Subject { get; set; } = string.Empty; + + [DisplayName("Текст")] + public string Body { get; set; } = string.Empty; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarDataModels/Models/IMessageInfoModel.cs b/SushiBar/SushiBarDataModels/Models/IMessageInfoModel.cs new file mode 100644 index 0000000..0443646 --- /dev/null +++ b/SushiBar/SushiBarDataModels/Models/IMessageInfoModel.cs @@ -0,0 +1,17 @@ +namespace SushiBarDataModels.Models +{ + public interface IMessageInfoModel + { + string MessageId { get; } + + int? ClientId { get; } + + string SenderName { get; } + + DateTime DateDelivery { get; } + + string Subject { get; } + + string Body { get; } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarDatabaseImplement/Implements/MessageInfoStorage.cs b/SushiBar/SushiBarDatabaseImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..f58ec16 --- /dev/null +++ b/SushiBar/SushiBarDatabaseImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,51 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarDatabaseImplement.Models; + +namespace SushiBarDatabaseImplement.Implements +{ + public class MessageInfoStorage : IMessageInfoStorage + { + public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) + { + if (model.MessageId == null) + return null; + using var context = new SushiBarDatabase(); + return context.Messages.FirstOrDefault(x => x.MessageId == model.MessageId)?.GetViewModel; + } + + public List GetFilteredList(MessageInfoSearchModel model) + { + if (!model.ClientId.HasValue) + return new(); + using var context = new SushiBarDatabase(); + return context.Messages + .Where(x => x.ClientId == model.ClientId) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + using var context = new SushiBarDatabase(); + return context.Messages + .Select(x => x.GetViewModel) + .ToList(); + } + + public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + { + var newMessage = Message.Create(model); + if (newMessage == null) + { + return null; + } + using var context = new SushiBarDatabase(); + context.Messages.Add(newMessage); + context.SaveChanges(); + return newMessage.GetViewModel; + } + } +} diff --git a/SushiBar/SushiBarDatabaseImplement/Migrations/20230419132122_MessageMigr.Designer.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/20230419132122_MessageMigr.Designer.cs new file mode 100644 index 0000000..7548afa --- /dev/null +++ b/SushiBar/SushiBarDatabaseImplement/Migrations/20230419132122_MessageMigr.Designer.cs @@ -0,0 +1,285 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using SushiBarDatabaseImplement; + +#nullable disable + +namespace SushiBarDatabaseImplement.Migrations +{ + [DbContext(typeof(SushiBarDatabase))] + [Migration("20230419132122_MessageMigr")] + partial class MessageMigr + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Ingredient", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Cost") + .HasColumnType("float"); + + b.Property("IngredientName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Ingredients"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Message", b => + { + b.Property("MessageId") + .HasColumnType("nvarchar(450)"); + + b.Property("Body") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("DateDelivery") + .HasColumnType("datetime2"); + + b.Property("SenderName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("MessageId"); + + b.ToTable("Messages"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ImplementerId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.Property("SushiId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.HasIndex("SushiId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Sushi", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("SushiName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("ListSushi"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiIngredient", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("IngredientId") + .HasColumnType("int"); + + b.Property("SushiId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("IngredientId"); + + b.HasIndex("SushiId"); + + b.ToTable("SushiIngredients"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b => + { + b.HasOne("SushiBarDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SushiBarDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi") + .WithMany("Orders") + .HasForeignKey("SushiId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + + b.Navigation("Sushi"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiIngredient", b => + { + b.HasOne("SushiBarDatabaseImplement.Models.Ingredient", "Ingredient") + .WithMany("SushiIngredients") + .HasForeignKey("IngredientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi") + .WithMany("Ingredients") + .HasForeignKey("SushiId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Ingredient"); + + b.Navigation("Sushi"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Ingredient", b => + { + b.Navigation("SushiIngredients"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Sushi", b => + { + b.Navigation("Ingredients"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SushiBar/SushiBarDatabaseImplement/Migrations/20230419132122_MessageMigr.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/20230419132122_MessageMigr.cs new file mode 100644 index 0000000..f5ecc0a --- /dev/null +++ b/SushiBar/SushiBarDatabaseImplement/Migrations/20230419132122_MessageMigr.cs @@ -0,0 +1,38 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace SushiBarDatabaseImplement.Migrations +{ + /// + public partial class MessageMigr : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Messages", + columns: table => new + { + MessageId = table.Column(type: "nvarchar(450)", nullable: false), + ClientId = table.Column(type: "int", nullable: true), + SenderName = table.Column(type: "nvarchar(max)", nullable: false), + DateDelivery = table.Column(type: "datetime2", nullable: false), + Subject = table.Column(type: "nvarchar(max)", nullable: false), + Body = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Messages", x => x.MessageId); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Messages"); + } + } +} diff --git a/SushiBar/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs index 72d343f..e1614c0 100644 --- a/SushiBar/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs +++ b/SushiBar/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs @@ -94,6 +94,34 @@ namespace SushiBarDatabaseImplement.Migrations b.ToTable("Ingredients"); }); + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Message", b => + { + b.Property("MessageId") + .HasColumnType("nvarchar(450)"); + + b.Property("Body") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("DateDelivery") + .HasColumnType("datetime2"); + + b.Property("SenderName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("MessageId"); + + b.ToTable("Messages"); + }); + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b => { b.Property("Id") diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Message.cs b/SushiBar/SushiBarDatabaseImplement/Models/Message.cs new file mode 100644 index 0000000..dc8867c --- /dev/null +++ b/SushiBar/SushiBarDatabaseImplement/Models/Message.cs @@ -0,0 +1,50 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; +using System.ComponentModel.DataAnnotations; + +namespace SushiBarDatabaseImplement.Models +{ + public class Message : IMessageInfoModel + { + [Key] + 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 Message? 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, + }; + } +} diff --git a/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs b/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs index c9b8aa1..f84eb9c 100644 --- a/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs +++ b/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs @@ -25,5 +25,7 @@ namespace SushiBarDatabaseImplement public virtual DbSet Clients { set; get; } public virtual DbSet Implementers { set; get; } + + public virtual DbSet Messages { set; get; } } } diff --git a/SushiBar/SushiBarFileImplement/DataFileSingleton.cs b/SushiBar/SushiBarFileImplement/DataFileSingleton.cs index b4d7213..d94d77d 100644 --- a/SushiBar/SushiBarFileImplement/DataFileSingleton.cs +++ b/SushiBar/SushiBarFileImplement/DataFileSingleton.cs @@ -11,11 +11,13 @@ namespace SushiBarFileImplement private readonly string SushiFileName = "Sushi.xml"; private readonly string ClientFileName = "Client.xml"; private readonly string ImplementerFileName = "Implementer.xml"; + private readonly string MessageFileName = "Message.xml"; public List Ingredients { get; private set; } public List Orders { get; private set; } 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() { if (instance == null) @@ -31,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(Messages, MessageFileName, "Messages", x => x.GetXElement); private DataFileSingleton() { Ingredients = LoadData(IngredientFileName, "Ingredient", x => Ingredient.Create(x)!)!; @@ -38,6 +41,7 @@ namespace SushiBarFileImplement Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!; + Messages = LoadData(MessageFileName, "Message", x => Message.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) diff --git a/SushiBar/SushiBarFileImplement/Implements/MessageInfoStorage.cs b/SushiBar/SushiBarFileImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..9105420 --- /dev/null +++ b/SushiBar/SushiBarFileImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,52 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarFileImplement.Models; + +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 null; + return source.Messages.FirstOrDefault(x => x.MessageId == model.MessageId)?.GetViewModel; + } + + public List GetFilteredList(MessageInfoSearchModel model) + { + if (!model.ClientId.HasValue) + return new(); + 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 = Message.Create(model); + if (newMessage == null) + { + return null; + } + source.Messages.Add(newMessage); + source.SaveMessages(); + return newMessage.GetViewModel; + } + } +} diff --git a/SushiBar/SushiBarFileImplement/Models/Message.cs b/SushiBar/SushiBarFileImplement/Models/Message.cs new file mode 100644 index 0000000..2fdb025 --- /dev/null +++ b/SushiBar/SushiBarFileImplement/Models/Message.cs @@ -0,0 +1,76 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; +using System.Reflection; +using System.Xml.Linq; + +namespace SushiBarFileImplement.Models +{ + public class Message : 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 Message? Create(MessageInfoBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Body = model.Body, + Subject = model.Subject, + DateDelivery = model.DateDelivery, + SenderName = model.SenderName, + ClientId = model.ClientId, + MessageId = model.MessageId + }; + } + + public static Message? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + Body = element.Attribute("Body")!.Value, + Subject = element.Attribute("Subject")!.Value, + DateDelivery = Convert.ToDateTime(element.Attribute("DateDelivery")!.Value), + SenderName = element.Attribute("SenderName")!.Value, + ClientId = Convert.ToInt32(element.Attribute("ClientId")!.Value), + MessageId = element.Attribute("MessageId")!.Value, + }; + } + + public MessageInfoViewModel GetViewModel => new() + { + Body = Body, + Subject = Subject, + DateDelivery = DateDelivery, + SenderName = SenderName, + ClientId = ClientId, + MessageId = MessageId + }; + + public XElement GetXElement => new("MessageInfo", + new XAttribute("Subject", Subject), + new XAttribute("Body", Body), + new XAttribute("ClientId", ClientId), + new XAttribute("MessageId", MessageId), + new XAttribute("SenderName", SenderName), + new XAttribute("DateDelivery", DateDelivery) + ); + } +} diff --git a/SushiBar/SushiBarListImplement/DataListSingleton.cs b/SushiBar/SushiBarListImplement/DataListSingleton.cs index 2afc72e..8b527ad 100644 --- a/SushiBar/SushiBarListImplement/DataListSingleton.cs +++ b/SushiBar/SushiBarListImplement/DataListSingleton.cs @@ -10,13 +10,15 @@ 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(); Orders = new List(); ListSushi = new List(); - Clients = new List(); + Clients = new List(); Implementers = new List(); + Messages = new List(); } public static DataListSingleton GetInstance() { diff --git a/SushiBar/SushiBarListImplement/Implements/MessageInfoStorage.cs b/SushiBar/SushiBarListImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..dae6580 --- /dev/null +++ b/SushiBar/SushiBarListImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,68 @@ +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) + { + if (model.MessageId == null) + { + return null; + } + foreach (var message in _source.Messages) + { + if (model.MessageId.Equals(message.MessageId)) + return message.GetViewModel; + } + return null; + } + + public List GetFilteredList(MessageInfoSearchModel model) + { + if (!model.ClientId.HasValue) + { + return new(); + } + var result = new List(); + foreach (var item in _source.Messages) + { + if (item.ClientId == model.ClientId) + { + result.Add(item.GetViewModel); + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + foreach (var item in _source.Messages) + { + result.Add(item.GetViewModel); + } + return result; + } + + public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + { + var newMessage = Message.Create(model); + if (newMessage == null) + { + return null; + } + _source.Messages.Add(newMessage); + return newMessage.GetViewModel; + } + } +} diff --git a/SushiBar/SushiBarListImplement/Models/Message.cs b/SushiBar/SushiBarListImplement/Models/Message.cs new file mode 100644 index 0000000..e6a08d4 --- /dev/null +++ b/SushiBar/SushiBarListImplement/Models/Message.cs @@ -0,0 +1,48 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; + +namespace SushiBarListImplement.Models +{ + public class Message : 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 Message? Create(MessageInfoBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Body = model.Body, + Subject = model.Subject, + DateDelivery = model.DateDelivery, + SenderName = model.SenderName, + ClientId = model.ClientId, + MessageId = model.MessageId + }; + } + + public MessageInfoViewModel GetViewModel => new() + { + Body = Body, + Subject = Subject, + DateDelivery = DateDelivery, + SenderName = SenderName, + ClientId = ClientId, + MessageId = MessageId + }; + } +} diff --git a/SushiBar/SushiBarRestApi/Controllers/ClientController.cs b/SushiBar/SushiBarRestApi/Controllers/ClientController.cs index 53e5c4f..c191876 100644 --- a/SushiBar/SushiBarRestApi/Controllers/ClientController.cs +++ b/SushiBar/SushiBarRestApi/Controllers/ClientController.cs @@ -14,10 +14,13 @@ namespace SushiBarRestApi.Controllers private readonly IClientLogic _logic; - public ClientController(IClientLogic logic, ILogger logger) + private readonly IMessageInfoLogic _mailLogic; + + public ClientController(IClientLogic logic, ILogger logger, IMessageInfoLogic mailLogic) { _logger = logger; _logic = logic; + _mailLogic = mailLogic; } [HttpGet] @@ -65,5 +68,22 @@ namespace SushiBarRestApi.Controllers throw; } } + + [HttpGet] + public List? GetMessages(int clientId) + { + try + { + return _mailLogic.ReadList(new MessageInfoSearchModel + { + ClientId = clientId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения писем клиента"); + throw; + } + } } } \ No newline at end of file diff --git a/SushiBar/SushiBarRestApi/Program.cs b/SushiBar/SushiBarRestApi/Program.cs index 5d0c986..a46417c 100644 --- a/SushiBar/SushiBarRestApi/Program.cs +++ b/SushiBar/SushiBarRestApi/Program.cs @@ -3,6 +3,8 @@ using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.StoragesContracts; using SushiBarDatabaseImplement.Implements; using Microsoft.OpenApi.Models; +using SushiBarBusinessLogic.MailWorker; +using SushiBarContracts.BindingModels; var builder = WebApplication.CreateBuilder(args); @@ -14,11 +16,15 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddSingleton(); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle @@ -30,6 +36,17 @@ builder.Services.AddSwaggerGen(c => var app = builder.Build(); +var mailSender = app.Services.GetService(); +mailSender?.MailConfig(new MailConfigBindingModel +{ + MailLogin = builder.Configuration?.GetSection("MailLogin")?.Value?.ToString() ?? string.Empty, + MailPassword = builder.Configuration?.GetSection("MailPassword")?.Value?.ToString() ?? string.Empty, + SmtpClientHost = builder.Configuration?.GetSection("SmtpClientHost")?.Value?.ToString() ?? string.Empty, + SmtpClientPort = Convert.ToInt32(builder.Configuration?.GetSection("SmtpClientPort")?.Value?.ToString()), + PopHost = builder.Configuration?.GetSection("PopHost")?.Value?.ToString() ?? string.Empty, + PopPort = Convert.ToInt32(builder.Configuration?.GetSection("PopPort")?.Value?.ToString()) +}); + // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { diff --git a/SushiBar/SushiBarRestApi/appsettings.json b/SushiBar/SushiBarRestApi/appsettings.json index 10f68b8..6afdb7e 100644 --- a/SushiBar/SushiBarRestApi/appsettings.json +++ b/SushiBar/SushiBarRestApi/appsettings.json @@ -5,5 +5,12 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + + "SmtpClientHost": "smtp.gmail.com", + "SmtpClientPort": "587", + "PopHost": "pop.gmail.com", + "PopPort": "995", + "MailLogin": "orderbuyerzxc@gmail.com", + "MailPassword": "sjxa uvgn pepe tatl" } From ed47c9c6e891cf9eaaf24b1be1abbc0c77d91f6e Mon Sep 17 00:00:00 2001 From: dasha Date: Wed, 19 Apr 2023 17:49:38 +0400 Subject: [PATCH 2/9] =?UTF-8?q?=3F=D0=BA=D0=BE=D1=80=D1=80=D0=B5=D0=BA?= =?UTF-8?q?=D1=82=D0=BD=D0=BE=D0=B5=3F=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80?= =?UTF-8?q?=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=B8=D1=81=D0=B5?= =?UTF-8?q?=D0=BC=20=D0=B2=20=D0=B2=D0=B5=D0=B1=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MailWorker/AbstractMailWorker.cs | 10 ++++++++-- .../SushiBarBusinessLogic/MailWorker/MailKitWorker.cs | 2 +- SushiBar/SushiBarClientApp/Views/Home/Mails.cshtml | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/SushiBar/SushiBarBusinessLogic/MailWorker/AbstractMailWorker.cs b/SushiBar/SushiBarBusinessLogic/MailWorker/AbstractMailWorker.cs index 52a9624..3afe6fb 100644 --- a/SushiBar/SushiBarBusinessLogic/MailWorker/AbstractMailWorker.cs +++ b/SushiBar/SushiBarBusinessLogic/MailWorker/AbstractMailWorker.cs @@ -1,6 +1,7 @@ using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; +using SushiBarBusinessLogic.BusinessLogics; namespace SushiBarBusinessLogic.MailWorker { @@ -20,12 +21,15 @@ namespace SushiBarBusinessLogic.MailWorker private readonly IMessageInfoLogic _messageInfoLogic; + private readonly IClientLogic _clientLogic; + private readonly ILogger _logger; - public AbstractMailWorker(ILogger logger, IMessageInfoLogic messageInfoLogic) + public AbstractMailWorker(ILogger logger, IMessageInfoLogic messageInfoLogic, IClientLogic clientLogic) { _logger = logger; _messageInfoLogic = messageInfoLogic; + _clientLogic = clientLogic; } public void MailConfig(MailConfigBindingModel config) @@ -36,7 +40,8 @@ namespace SushiBarBusinessLogic.MailWorker _smtpClientPort = config.SmtpClientPort; _popHost = config.PopHost; _popPort = config.PopPort; - _logger.LogDebug("Config: {login}, {password}, {clientHost}, {clientPOrt}, {popHost}, {popPort}", _mailLogin, _mailPassword, _smtpClientHost, _smtpClientPort, _popHost, _popPort); + _logger.LogDebug("Config: {login}, {password}, {clientHost}, {clientPOrt}, {popHost}, {popPort}", + _mailLogin, _mailPassword, _smtpClientHost, _smtpClientPort, _popHost, _popPort); } public async void MailSendAsync(MailSendInfoBindingModel info) @@ -81,6 +86,7 @@ namespace SushiBarBusinessLogic.MailWorker _logger.LogDebug("Check Mail: {Count} new mails", list.Count); foreach (var mail in list) { + mail.ClientId = _clientLogic.ReadElement(new() { Email = mail.SenderName })?.Id; _messageInfoLogic.Create(mail); } } diff --git a/SushiBar/SushiBarBusinessLogic/MailWorker/MailKitWorker.cs b/SushiBar/SushiBarBusinessLogic/MailWorker/MailKitWorker.cs index 645528c..b3934aa 100644 --- a/SushiBar/SushiBarBusinessLogic/MailWorker/MailKitWorker.cs +++ b/SushiBar/SushiBarBusinessLogic/MailWorker/MailKitWorker.cs @@ -11,7 +11,7 @@ namespace SushiBarBusinessLogic.MailWorker { public class MailKitWorker : AbstractMailWorker { - public MailKitWorker(ILogger logger, IMessageInfoLogic messageInfoLogic) : base(logger, messageInfoLogic) { } + public MailKitWorker(ILogger logger, IMessageInfoLogic messageInfoLogic, IClientLogic clientLogic) : base(logger, messageInfoLogic, clientLogic) { } protected override async Task SendMailAsync(MailSendInfoBindingModel info) { diff --git a/SushiBar/SushiBarClientApp/Views/Home/Mails.cshtml b/SushiBar/SushiBarClientApp/Views/Home/Mails.cshtml index aa313fa..bf1b6d4 100644 --- a/SushiBar/SushiBarClientApp/Views/Home/Mails.cshtml +++ b/SushiBar/SushiBarClientApp/Views/Home/Mails.cshtml @@ -7,7 +7,7 @@ }
-

Заказы

+

Письма

From cd04a4dc87f3b6d8702fd45dbdf9f8333c7237df Mon Sep 17 00:00:00 2001 From: dasha Date: Wed, 19 Apr 2023 21:28:40 +0400 Subject: [PATCH 3/9] =?UTF-8?q?=D1=80=D0=B5=D0=B3=D1=83=D0=BB=D1=8F=D1=80?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=BD=D0=B0=D0=B4=D0=BE=20=D0=B7=D0=B0=D1=82?= =?UTF-8?q?=D0=B5=D1=81=D1=82=D0=B8=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SushiBarBusinessLogic/BusinessLogics/ClientLogic.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ClientLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ClientLogic.cs index c51ccac..dc5e71f 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ClientLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ClientLogic.cs @@ -4,6 +4,7 @@ using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.SearchModels; using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; +using System.Text.RegularExpressions; namespace SushiBarBusinessLogic.BusinessLogics { @@ -105,6 +106,14 @@ namespace SushiBarBusinessLogic.BusinessLogics { throw new ArgumentNullException("Нет пароля клиента", nameof(model.Password)); } + if (!Regex.IsMatch(model.Email, @"^[^@\s]+@[^@\s]+\.[^@\s]+$", RegexOptions.IgnoreCase)) + { + throw new ArgumentException("Неправильно введенный email", nameof(model.Email)); + } + if (!Regex.IsMatch(model.Password, @"^^((\w+\d+\W+)|(\w+\W+\d+)|(\d+\w+\W+)|(\d+\W+\w+)|(\W+\w+\d+)|(\W+\d+\w+))[\w\d\W]*$", RegexOptions.IgnoreCase)) + { + throw new ArgumentException("Неправильно введенный пароль", nameof(model.Password)); + } _logger.LogInformation("Client. ClientFIO: {ClientFIO}. Email: {Email}. Id: {Id}", model.ClientFIO, model.Email, model.Id); var element = _clientStorage.GetElement(new ClientSearchModel From 528ead03a85e6a4f20f9162c9d5241cb36aba84c Mon Sep 17 00:00:00 2001 From: dasha Date: Thu, 20 Apr 2023 16:18:10 +0400 Subject: [PATCH 4/9] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=86=D0=B5=D0=BB=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D0=BD=D0=BE=D1=81=D1=82=D0=B8=20=D0=B1=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...230420121751_FixMessageKeyMigr.Designer.cs | 296 ++++++++++++++++++ .../20230420121751_FixMessageKeyMigr.cs | 38 +++ .../SushiBarDatabaseModelSnapshot.cs | 11 + .../Models/Client.cs | 3 + 4 files changed, 348 insertions(+) create mode 100644 SushiBar/SushiBarDatabaseImplement/Migrations/20230420121751_FixMessageKeyMigr.Designer.cs create mode 100644 SushiBar/SushiBarDatabaseImplement/Migrations/20230420121751_FixMessageKeyMigr.cs diff --git a/SushiBar/SushiBarDatabaseImplement/Migrations/20230420121751_FixMessageKeyMigr.Designer.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/20230420121751_FixMessageKeyMigr.Designer.cs new file mode 100644 index 0000000..d7eb399 --- /dev/null +++ b/SushiBar/SushiBarDatabaseImplement/Migrations/20230420121751_FixMessageKeyMigr.Designer.cs @@ -0,0 +1,296 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using SushiBarDatabaseImplement; + +#nullable disable + +namespace SushiBarDatabaseImplement.Migrations +{ + [DbContext(typeof(SushiBarDatabase))] + [Migration("20230420121751_FixMessageKeyMigr")] + partial class FixMessageKeyMigr + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Ingredient", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Cost") + .HasColumnType("float"); + + b.Property("IngredientName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Ingredients"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Message", b => + { + b.Property("MessageId") + .HasColumnType("nvarchar(450)"); + + b.Property("Body") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("DateDelivery") + .HasColumnType("datetime2"); + + b.Property("SenderName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("MessageId"); + + b.HasIndex("ClientId"); + + b.ToTable("Messages"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ImplementerId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.Property("SushiId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.HasIndex("SushiId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Sushi", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("SushiName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("ListSushi"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiIngredient", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("IngredientId") + .HasColumnType("int"); + + b.Property("SushiId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("IngredientId"); + + b.HasIndex("SushiId"); + + b.ToTable("SushiIngredients"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Message", b => + { + b.HasOne("SushiBarDatabaseImplement.Models.Client", null) + .WithMany("Messages") + .HasForeignKey("ClientId"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b => + { + b.HasOne("SushiBarDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SushiBarDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi") + .WithMany("Orders") + .HasForeignKey("SushiId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + + b.Navigation("Sushi"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiIngredient", b => + { + b.HasOne("SushiBarDatabaseImplement.Models.Ingredient", "Ingredient") + .WithMany("SushiIngredients") + .HasForeignKey("IngredientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi") + .WithMany("Ingredients") + .HasForeignKey("SushiId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Ingredient"); + + b.Navigation("Sushi"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Client", b => + { + b.Navigation("Messages"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Ingredient", b => + { + b.Navigation("SushiIngredients"); + }); + + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Sushi", b => + { + b.Navigation("Ingredients"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SushiBar/SushiBarDatabaseImplement/Migrations/20230420121751_FixMessageKeyMigr.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/20230420121751_FixMessageKeyMigr.cs new file mode 100644 index 0000000..bb5cb93 --- /dev/null +++ b/SushiBar/SushiBarDatabaseImplement/Migrations/20230420121751_FixMessageKeyMigr.cs @@ -0,0 +1,38 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace SushiBarDatabaseImplement.Migrations +{ + /// + public partial class FixMessageKeyMigr : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateIndex( + name: "IX_Messages_ClientId", + table: "Messages", + column: "ClientId"); + + migrationBuilder.AddForeignKey( + name: "FK_Messages_Clients_ClientId", + table: "Messages", + column: "ClientId", + principalTable: "Clients", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Messages_Clients_ClientId", + table: "Messages"); + + migrationBuilder.DropIndex( + name: "IX_Messages_ClientId", + table: "Messages"); + } + } +} diff --git a/SushiBar/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs index e1614c0..11b63c0 100644 --- a/SushiBar/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs +++ b/SushiBar/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs @@ -119,6 +119,8 @@ namespace SushiBarDatabaseImplement.Migrations b.HasKey("MessageId"); + b.HasIndex("ClientId"); + b.ToTable("Messages"); }); @@ -211,6 +213,13 @@ namespace SushiBarDatabaseImplement.Migrations b.ToTable("SushiIngredients"); }); + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Message", b => + { + b.HasOne("SushiBarDatabaseImplement.Models.Client", null) + .WithMany("Messages") + .HasForeignKey("ClientId"); + }); + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b => { b.HasOne("SushiBarDatabaseImplement.Models.Client", "Client") @@ -257,6 +266,8 @@ namespace SushiBarDatabaseImplement.Migrations modelBuilder.Entity("SushiBarDatabaseImplement.Models.Client", b => { + b.Navigation("Messages"); + b.Navigation("Orders"); }); diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Client.cs b/SushiBar/SushiBarDatabaseImplement/Models/Client.cs index 644b200..28ee46e 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Client.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Client.cs @@ -18,6 +18,9 @@ namespace SushiBarDatabaseImplement.Models [ForeignKey("ClientId")] public virtual List Orders { get; set; } = new(); + + [ForeignKey("ClientId")] + public virtual List Messages { get; set; } = new(); public static Client? Create(ClientBindingModel model) { if (model == null) From 2b8f7a8d873e889c2e1694dcba47903564b53362 Mon Sep 17 00:00:00 2001 From: dasha Date: Thu, 20 Apr 2023 16:25:55 +0400 Subject: [PATCH 5/9] ? --- SushiBar/SushiBarDatabaseImplement/Models/Message.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Message.cs b/SushiBar/SushiBarDatabaseImplement/Models/Message.cs index dc8867c..f6b7173 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Message.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Message.cs @@ -9,15 +9,14 @@ namespace SushiBarDatabaseImplement.Models { [Key] public string MessageId { get; private set; } = string.Empty; - - public int? ClientId { get; private set; } - + public int? ClientId { get; private set; } + [Required] public string SenderName { get; private set; } = string.Empty; - + [Required] public DateTime DateDelivery { get; private set; } = DateTime.Now; - + [Required] public string Subject { get; private set; } = string.Empty; - + [Required] public string Body { get; private set; } = string.Empty; public static Message? Create(MessageInfoBindingModel model) From d5cbd5e5082a5c2ee77ea8ddbc22ca3367bf6f94 Mon Sep 17 00:00:00 2001 From: dasha Date: Sat, 22 Apr 2023 14:47:39 +0400 Subject: [PATCH 6/9] =?UTF-8?q?=D0=BE=D0=B3=D1=80=D0=B0=D0=BD=D0=B8=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81=D0=B8=D0=BC=D0=B2=D0=BE=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBarClientApp/Views/Home/Enter.cshtml | 4 ++-- SushiBar/SushiBarClientApp/Views/Home/Register.cshtml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/SushiBar/SushiBarClientApp/Views/Home/Enter.cshtml b/SushiBar/SushiBarClientApp/Views/Home/Enter.cshtml index 106d3d5..183e763 100644 --- a/SushiBar/SushiBarClientApp/Views/Home/Enter.cshtml +++ b/SushiBar/SushiBarClientApp/Views/Home/Enter.cshtml @@ -8,11 +8,11 @@
Логин:
-
+
Пароль:
-
+
diff --git a/SushiBar/SushiBarClientApp/Views/Home/Register.cshtml b/SushiBar/SushiBarClientApp/Views/Home/Register.cshtml index 398b516..1f87e95 100644 --- a/SushiBar/SushiBarClientApp/Views/Home/Register.cshtml +++ b/SushiBar/SushiBarClientApp/Views/Home/Register.cshtml @@ -8,11 +8,11 @@
Логин:
-
+
Пароль:
-
+
ФИО:
From be41de91c5dc73b93a1d2b965e381b0a80e523da Mon Sep 17 00:00:00 2001 From: dasha Date: Fri, 28 Apr 2023 19:42:36 +0400 Subject: [PATCH 7/9] =?UTF-8?q?=D1=82=D1=83=D1=82=20=D1=82=D0=BE=D0=B6?= =?UTF-8?q?=D0=B5=20=D0=BD=D0=B0=D0=B4=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBarBusinessLogic/BusinessLogics/ClientLogic.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ClientLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ClientLogic.cs index dc5e71f..566a22d 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ClientLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ClientLogic.cs @@ -110,7 +110,8 @@ namespace SushiBarBusinessLogic.BusinessLogics { throw new ArgumentException("Неправильно введенный email", nameof(model.Email)); } - if (!Regex.IsMatch(model.Password, @"^^((\w+\d+\W+)|(\w+\W+\d+)|(\d+\w+\W+)|(\d+\W+\w+)|(\W+\w+\d+)|(\W+\d+\w+))[\w\d\W]*$", RegexOptions.IgnoreCase)) + if (!Regex.IsMatch(model.Password, @"^^((\w+\d+\W+)|(\w+\W+\d+)|(\d+\w+\W+)|(\d+\W+\w+)|(\W+\w+\d+)|(\W+\d+\w+))[\w\d\W]*$", RegexOptions.IgnoreCase) + || model.Password.Length < 10 || model.Password.Length > 50) { throw new ArgumentException("Неправильно введенный пароль", nameof(model.Password)); } From db69a77fcc99784935d3f8d4a76c94d3d3b49915 Mon Sep 17 00:00:00 2001 From: dasha Date: Mon, 1 May 2023 02:10:15 +0400 Subject: [PATCH 8/9] =?UTF-8?q?=D0=BF=D1=83=D1=81=D1=82=D1=8C=20=D0=B2?= =?UTF-8?q?=D1=81=D0=B5=D0=B3=D0=B4=D0=B0=20=D0=B1=D1=83=D0=B4=D0=B5=D1=82?= =?UTF-8?q?=20=D1=81=D0=BE=D0=BB=D0=BD=D1=86=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + SushiBar/SushiBar/DataGridViewExtension.cs | 46 +++++++++ SushiBar/SushiBar/FormClients.cs | 8 +- SushiBar/SushiBar/FormImplementers.cs | 13 +-- SushiBar/SushiBar/FormIngredients.cs | 13 +-- SushiBar/SushiBar/FormListSushi.cs | 14 +-- SushiBar/SushiBar/FormMails.cs | 9 +- SushiBar/SushiBar/FormMain.Designer.cs | 28 ++++-- SushiBar/SushiBar/FormMain.cs | 60 ++++++++---- SushiBar/SushiBar/FormSushi.cs | 5 +- SushiBar/SushiBar/Program.cs | 84 ++++++++-------- .../BusinessLogics/BackUpLogic.cs | 98 +++++++++++++++++++ .../Attributes/ColumnAttribute.cs | 25 +++++ .../Attributes/GridViewAutoSize.cs | 21 ++++ .../BindingModels/BackUpSaveBinidngModel.cs | 7 ++ .../BindingModels/MessageInfoBindingModel.cs | 2 + .../BusinessLogicsContracts/IBackUpLogic.cs | 9 ++ .../SushiBarContracts/DI/DependencyManager.cs | 61 ++++++++++++ .../DI/IDependencyContainer.cs | 35 +++++++ .../DI/IImplementationExtension.cs | 11 +++ .../DI/ServiceDependencyContainer.cs | 57 +++++++++++ .../DI/ServiceProviderLoader.cs | 50 ++++++++++ .../DI/UnityDependencyContainer.cs | 50 ++++++++++ .../StoragesContracts/IBackUpInfo.cs | 9 ++ .../SushiBarContracts.csproj | 2 + .../ViewModels/ClientViewModel.cs | 11 ++- .../ViewModels/ImplementerViewModel.cs | 12 ++- .../ViewModels/IngredientViewModel.cs | 9 +- .../ViewModels/MessageInfoViewModel.cs | 17 ++-- .../ViewModels/OrderViewModel.cs | 27 ++--- .../ViewModels/SushiViewModel.cs | 9 +- .../Models/IMessageInfoModel.cs | 2 +- .../DatabaseImplementationExtension.cs | 22 +++++ .../Implements/BackUpInfo.cs | 27 +++++ .../Models/Client.cs | 12 ++- .../Models/Implementer.cs | 9 +- .../Models/Ingredient.cs | 8 +- .../Models/Message.cs | 12 ++- .../SushiBarDatabaseImplement/Models/Order.cs | 11 +++ .../SushiBarDatabaseImplement/Models/Sushi.cs | 9 +- .../SushiBarDatabaseImplement.csproj | 4 + .../FileImplementationExtension.cs | 22 +++++ .../Implements/BackUpInfo.cs | 29 ++++++ .../SushiBarFileImplement/Models/Client.cs | 8 +- .../Models/Implementer.cs | 11 ++- .../Models/Ingredient.cs | 7 +- .../SushiBarFileImplement/Models/Message.cs | 15 ++- .../SushiBarFileImplement/Models/Order.cs | 15 ++- .../SushiBarFileImplement/Models/Sushi.cs | 8 +- .../SushiBarFileImplement.csproj | 4 + .../Implements/BackUpInfo.cs | 17 ++++ .../ListImplementationExtension.cs | 22 +++++ .../SushiBarListImplement/Models/Message.cs | 2 + .../SushiBarListImplement.csproj | 4 + 54 files changed, 902 insertions(+), 181 deletions(-) create mode 100644 SushiBar/SushiBar/DataGridViewExtension.cs create mode 100644 SushiBar/SushiBarBusinessLogic/BusinessLogics/BackUpLogic.cs create mode 100644 SushiBar/SushiBarContracts/Attributes/ColumnAttribute.cs create mode 100644 SushiBar/SushiBarContracts/Attributes/GridViewAutoSize.cs create mode 100644 SushiBar/SushiBarContracts/BindingModels/BackUpSaveBinidngModel.cs create mode 100644 SushiBar/SushiBarContracts/BusinessLogicsContracts/IBackUpLogic.cs create mode 100644 SushiBar/SushiBarContracts/DI/DependencyManager.cs create mode 100644 SushiBar/SushiBarContracts/DI/IDependencyContainer.cs create mode 100644 SushiBar/SushiBarContracts/DI/IImplementationExtension.cs create mode 100644 SushiBar/SushiBarContracts/DI/ServiceDependencyContainer.cs create mode 100644 SushiBar/SushiBarContracts/DI/ServiceProviderLoader.cs create mode 100644 SushiBar/SushiBarContracts/DI/UnityDependencyContainer.cs create mode 100644 SushiBar/SushiBarContracts/StoragesContracts/IBackUpInfo.cs create mode 100644 SushiBar/SushiBarDatabaseImplement/DatabaseImplementationExtension.cs create mode 100644 SushiBar/SushiBarDatabaseImplement/Implements/BackUpInfo.cs create mode 100644 SushiBar/SushiBarFileImplement/FileImplementationExtension.cs create mode 100644 SushiBar/SushiBarFileImplement/Implements/BackUpInfo.cs create mode 100644 SushiBar/SushiBarListImplement/Implements/BackUpInfo.cs create mode 100644 SushiBar/SushiBarListImplement/ListImplementationExtension.cs diff --git a/.gitignore b/.gitignore index ca1c7a3..7ccc4e3 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs +ImplementationExtensions # Mono auto generated files mono_crash.* diff --git a/SushiBar/SushiBar/DataGridViewExtension.cs b/SushiBar/SushiBar/DataGridViewExtension.cs new file mode 100644 index 0000000..58f5aa1 --- /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; + } + } + } + } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBar/FormClients.cs b/SushiBar/SushiBar/FormClients.cs index 4781843..0e25a27 100644 --- a/SushiBar/SushiBar/FormClients.cs +++ b/SushiBar/SushiBar/FormClients.cs @@ -26,13 +26,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 a578d4b..1062f5a 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 { @@ -22,13 +23,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) @@ -40,7 +35,7 @@ namespace SushiBarView } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + var service = DependencyManager.Instance.Resolve(); if (service is FormImplementer form) { if (form.ShowDialog() == DialogResult.OK) @@ -53,7 +48,7 @@ namespace SushiBarView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + var service = DependencyManager.Instance.Resolve(); if (service is FormImplementer form) { form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); diff --git a/SushiBar/SushiBar/FormIngredients.cs b/SushiBar/SushiBar/FormIngredients.cs index 781205f..8294890 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 { @@ -22,13 +23,7 @@ namespace SushiBarView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["IngredientName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка ингредиентов"); } catch (Exception ex) @@ -40,7 +35,7 @@ namespace SushiBarView } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormIngredient)); + var service = DependencyManager.Instance.Resolve(); if (service is FormIngredient form) { if (form.ShowDialog() == DialogResult.OK) @@ -53,7 +48,7 @@ namespace SushiBarView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormIngredient)); + var service = DependencyManager.Instance.Resolve(); if (service is FormIngredient form) { form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); diff --git a/SushiBar/SushiBar/FormListSushi.cs b/SushiBar/SushiBar/FormListSushi.cs index d20376b..9b44467 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 { @@ -23,14 +24,7 @@ namespace SushiBarView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["SushiName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["SushiIngredients"].Visible = false; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка суши"); } catch (Exception ex) @@ -42,7 +36,7 @@ namespace SushiBarView private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormSushi)); + var service = DependencyManager.Instance.Resolve(); if (service is FormSushi form) { if (form.ShowDialog() == DialogResult.OK) @@ -56,7 +50,7 @@ namespace SushiBarView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormSushi)); + var service = DependencyManager.Instance.Resolve(); if (service is FormSushi form) { form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); diff --git a/SushiBar/SushiBar/FormMails.cs b/SushiBar/SushiBar/FormMails.cs index 799addb..fe75477 100644 --- a/SushiBar/SushiBar/FormMails.cs +++ b/SushiBar/SushiBar/FormMails.cs @@ -19,14 +19,7 @@ namespace SushiBarView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["MessageId"].Visible = false; - dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка писем"); } catch (Exception ex) diff --git a/SushiBar/SushiBar/FormMain.Designer.cs b/SushiBar/SushiBar/FormMain.Designer.cs index 365940f..f9d8057 100644 --- a/SushiBar/SushiBar/FormMain.Designer.cs +++ b/SushiBar/SushiBar/FormMain.Designer.cs @@ -39,11 +39,12 @@ this.ингредиентыПоСушиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.запускРаботToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.письмаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.createBackUpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.buttonUpdate = new System.Windows.Forms.Button(); this.buttonSetToFinish = new System.Windows.Forms.Button(); this.buttonCreateOrder = new System.Windows.Forms.Button(); this.dataGridView = new System.Windows.Forms.DataGridView(); - this.письмаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -54,7 +55,8 @@ this.справочникиToolStripMenuItem, this.отчетыToolStripMenuItem, this.запускРаботToolStripMenuItem, - this.письмаToolStripMenuItem}); + this.письмаToolStripMenuItem, + this.createBackUpToolStripMenuItem}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; this.menuStrip.Size = new System.Drawing.Size(1086, 24); @@ -138,6 +140,20 @@ this.запускРаботToolStripMenuItem.Text = "Запуск работ"; this.запускРаботToolStripMenuItem.Click += new System.EventHandler(this.DoWorkToolStripMenuItem_Click); // + // письмаToolStripMenuItem + // + this.письмаToolStripMenuItem.Name = "письмаToolStripMenuItem"; + this.письмаToolStripMenuItem.Size = new System.Drawing.Size(62, 20); + this.письмаToolStripMenuItem.Text = "Письма"; + this.письмаToolStripMenuItem.Click += new System.EventHandler(this.MailsToolStripMenuItem_Click); + // + // createBackUpToolStripMenuItem + // + this.createBackUpToolStripMenuItem.Name = "createBackUpToolStripMenuItem"; + this.createBackUpToolStripMenuItem.Size = new System.Drawing.Size(97, 20); + this.createBackUpToolStripMenuItem.Text = "Создать бекап"; + this.createBackUpToolStripMenuItem.Click += new System.EventHandler(this.CreateBackUpToolStripMenuItem_Click); + // // buttonUpdate // this.buttonUpdate.Location = new System.Drawing.Point(905, 253); @@ -183,13 +199,6 @@ this.dataGridView.Size = new System.Drawing.Size(899, 426); this.dataGridView.TabIndex = 7; // - // письмаToolStripMenuItem - // - this.письмаToolStripMenuItem.Name = "письмаToolStripMenuItem"; - this.письмаToolStripMenuItem.Size = new System.Drawing.Size(62, 20); - this.письмаToolStripMenuItem.Text = "Письма"; - this.письмаToolStripMenuItem.Click += new System.EventHandler(this.MailsToolStripMenuItem_Click); - // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -230,5 +239,6 @@ private ToolStripMenuItem исполнителиToolStripMenuItem; private ToolStripMenuItem запускРаботToolStripMenuItem; private ToolStripMenuItem письмаToolStripMenuItem; + private ToolStripMenuItem createBackUpToolStripMenuItem; } } \ No newline at end of file diff --git a/SushiBar/SushiBar/FormMain.cs b/SushiBar/SushiBar/FormMain.cs index 2497490..ab6b906 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,13 +11,15 @@ 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; _orderLogic = orderLogic; _reportLogic = reportLogic; _workProcess = workProcess; + _backUpLogic = backUpLogic; } private void FormMain_Load(object sender, EventArgs e) { @@ -27,17 +30,7 @@ namespace SushiBarView _logger.LogInformation("Загрузка заказов"); try { - var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["SushiId"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["ImplementerId"].Visible = false; - dataGridView.Columns["SushiName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null)); _logger.LogInformation("Загрузка заказов"); } catch (Exception ex) @@ -48,7 +41,7 @@ namespace SushiBarView } private void IngredientsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormIngredients)); + var service = DependencyManager.Instance.Resolve(); if (service is FormIngredients form) { form.ShowDialog(); @@ -56,7 +49,7 @@ namespace SushiBarView } private void SushiToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormListSushi)); + var service = DependencyManager.Instance.Resolve(); if (service is FormListSushi form) { form.ShowDialog(); @@ -64,7 +57,7 @@ namespace SushiBarView } private void ButtonCreateOrder_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + var service = DependencyManager.Instance.Resolve(); if (service is FormCreateOrder form) { form.ShowDialog(); @@ -163,7 +156,7 @@ namespace SushiBarView private void SushiIngredientToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportSushiIngredients)); + var service = DependencyManager.Instance.Resolve(); if (service is FormReportSushiIngredients form) { form.ShowDialog(); @@ -172,7 +165,7 @@ namespace SushiBarView private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); + var service = DependencyManager.Instance.Resolve(); if (service is FormReportOrders form) { form.ShowDialog(); @@ -181,7 +174,7 @@ namespace SushiBarView private void ClientsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormClients)); + var service = DependencyManager.Instance.Resolve(); if (service is FormClients form) { form.ShowDialog(); @@ -190,7 +183,7 @@ namespace SushiBarView private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + var service = DependencyManager.Instance.Resolve(); if (service is FormImplementers form) { form.ShowDialog(); @@ -200,7 +193,7 @@ namespace SushiBarView private void DoWorkToolStripMenuItem_Click(object sender, EventArgs e) { _workProcess.DoWork(( - Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, + DependencyManager.Instance.Resolve() as IImplementerLogic)!, _orderLogic); MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); @@ -208,11 +201,36 @@ namespace SushiBarView private void MailsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormMails)); + var service = DependencyManager.Instance.Resolve(); if (service is FormMails form) { form.ShowDialog(); } } + + private void CreateBackUpToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + if (_backUpLogic != null) + { + var fbd = new FolderBrowserDialog(); + if (fbd.ShowDialog() == DialogResult.OK) + { + _backUpLogic.CreateBackUp(new BackUpSaveBinidngModel + { + FolderName = fbd.SelectedPath + }); + MessageBox.Show("Бекап создан", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } } } \ No newline at end of file diff --git a/SushiBar/SushiBar/FormSushi.cs b/SushiBar/SushiBar/FormSushi.cs index 515011f..9cc303e 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,7 +71,7 @@ namespace SushiBarView } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormSushiIngredients)); + var service = DependencyManager.Instance.Resolve(); if (service is FormSushiIngredients form) { if (form.ShowDialog() == DialogResult.OK) @@ -96,7 +97,7 @@ namespace SushiBarView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormSushiIngredients)); + var service = DependencyManager.Instance.Resolve(); if (service is FormSushiIngredients form) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); diff --git a/SushiBar/SushiBar/Program.cs b/SushiBar/SushiBar/Program.cs index 79f031c..8405ac9 100644 --- a/SushiBar/SushiBar/Program.cs +++ b/SushiBar/SushiBar/Program.cs @@ -9,29 +9,26 @@ using SushiBarContracts.StoragesContracts; using SushiBarDatabaseImplement.Implements; 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. /// [STAThread] static void Main() { - // To customize application configuration such as set high DPI settings or default font, + // To customize application configuration such as set high DPIsettings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); + InitDependency(); - var services = new ServiceCollection(); - ConfigureServices(services); - _serviceProvider = services.BuildServiceProvider(); try { - var mailSender = _serviceProvider.GetService(); + var mailSender = DependencyManager.Instance.Resolve(); mailSender?.MailConfig(new MailConfigBindingModel { MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, @@ -47,56 +44,53 @@ namespace SushiBarView } catch (Exception ex) { - var logger = _serviceProvider.GetService(); + var logger = DependencyManager.Instance.Resolve(); logger?.LogError(ex, " "); } - Application.Run(_serviceProvider.GetRequiredService()); - } - private static void ConfigureServices(ServiceCollection services) + Application.Run(DependencyManager.Instance.Resolve()); + } + 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(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(true); - services.AddTransient(); - services.AddSingleton(); + 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(); - 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(); + 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) => ServiceProvider?.GetService()?.MailCheck(); + 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..3d0cd11 --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/BackUpLogic.cs @@ -0,0 +1,98 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.StoragesContracts; +using SushiBarDataModels; +using Microsoft.Extensions.Logging; +using System.IO.Compression; +using System.Reflection; +using System.Runtime.Serialization.Json; + +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(BackUpSaveBinidngModel 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); + } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/Attributes/ColumnAttribute.cs b/SushiBar/SushiBarContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..6f9c44b --- /dev/null +++ b/SushiBar/SushiBarContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,25 @@ +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; + } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/Attributes/GridViewAutoSize.cs b/SushiBar/SushiBarContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..abe4f32 --- /dev/null +++ b/SushiBar/SushiBarContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,21 @@ +namespace SushiBarContracts.Attributes +{ + public enum GridViewAutoSize + { + NotSet = 0, + + None = 1, + + ColumnHeader = 2, + + AllCellsExceptHeader = 4, + + AllCells = 6, + + DisplayedCellsExceptHeader = 8, + + DisplayedCells = 10, + + Fill = 16 + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/BindingModels/BackUpSaveBinidngModel.cs b/SushiBar/SushiBarContracts/BindingModels/BackUpSaveBinidngModel.cs new file mode 100644 index 0000000..fe2ca2d --- /dev/null +++ b/SushiBar/SushiBarContracts/BindingModels/BackUpSaveBinidngModel.cs @@ -0,0 +1,7 @@ +namespace SushiBarContracts.BindingModels +{ + public class BackUpSaveBinidngModel + { + public string FolderName { get; set; } = string.Empty; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/BindingModels/MessageInfoBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/MessageInfoBindingModel.cs index 453ceb5..23e2789 100644 --- a/SushiBar/SushiBarContracts/BindingModels/MessageInfoBindingModel.cs +++ b/SushiBar/SushiBarContracts/BindingModels/MessageInfoBindingModel.cs @@ -15,5 +15,7 @@ namespace SushiBarContracts.BindingModels public string Body { get; set; } = string.Empty; public DateTime DateDelivery { get; set; } + + public int Id => throw new NotImplementedException(); } } \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IBackUpLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..91ae4a0 --- /dev/null +++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -0,0 +1,9 @@ +using SushiBarContracts.BindingModels; + +namespace SushiBarContracts.BusinessLogicsContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBinidngModel model); + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/DI/DependencyManager.cs b/SushiBar/SushiBarContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..b791e60 --- /dev/null +++ b/SushiBar/SushiBarContracts/DI/DependencyManager.cs @@ -0,0 +1,61 @@ +using Microsoft.Extensions.Logging; + +namespace SushiBarContracts.DI +{ + public class DependencyManager + { + private readonly IDependencyContainer _dependencyManager; + + private static DependencyManager? _manager; + + private static readonly object _locjObject = new(); + + private DependencyManager() + { + _dependencyManager = new UnityDependencyContainer(); + } + + 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(); + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/DI/IDependencyContainer.cs b/SushiBar/SushiBarContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..7421027 --- /dev/null +++ b/SushiBar/SushiBarContracts/DI/IDependencyContainer.cs @@ -0,0 +1,35 @@ +using Microsoft.Extensions.Logging; + +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..7973eab --- /dev/null +++ b/SushiBar/SushiBarContracts/DI/IImplementationExtension.cs @@ -0,0 +1,11 @@ +namespace SushiBarContracts.DI +{ + public interface IImplementationExtension + { + public int Priority { get; } + /// + /// Регистрация сервисов + /// + public void RegisterServices(); + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/DI/ServiceDependencyContainer.cs b/SushiBar/SushiBarContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..9ffd5f2 --- /dev/null +++ b/SushiBar/SushiBarContracts/DI/ServiceDependencyContainer.cs @@ -0,0 +1,57 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +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()!; + } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/DI/ServiceProviderLoader.cs b/SushiBar/SushiBarContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..8c1e02f --- /dev/null +++ b/SushiBar/SushiBarContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,50 @@ +using System.Reflection; + +namespace SushiBarContracts.DI +{ + public class ServiceProviderLoader + { + /// + /// Загрузка всех классов-реализаций IImplementationExtension + /// + /// + 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"; + } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/DI/UnityDependencyContainer.cs b/SushiBar/SushiBarContracts/DI/UnityDependencyContainer.cs new file mode 100644 index 0000000..9b971ee --- /dev/null +++ b/SushiBar/SushiBarContracts/DI/UnityDependencyContainer.cs @@ -0,0 +1,50 @@ +using Microsoft.Extensions.Logging; +using Unity; +using Unity.Microsoft.Logging; + +namespace SushiBarContracts.DI +{ + public class UnityDependencyContainer : IDependencyContainer + { + private readonly UnityContainer _container; + + public UnityDependencyContainer() + { + _container = new UnityContainer(); + } + + public void AddLogging(Action configure) + { + _container.AddExtension(new LoggingExtension(LoggerFactory.Create(configure))); + } + + public void RegisterType(bool isSingle) where U : class, T where T : class + { + if (isSingle) + { + _container.RegisterSingleton(); + } + else + { + _container.RegisterType(); + } + } + + public void RegisterType(bool isSingle) where T : class + { + if (isSingle) + { + _container.RegisterSingleton(); + } + else + { + _container.RegisterType(); + } + } + + public T Resolve() + { + return _container.Resolve(); + } + } +} diff --git a/SushiBar/SushiBarContracts/StoragesContracts/IBackUpInfo.cs b/SushiBar/SushiBarContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..7e18631 --- /dev/null +++ b/SushiBar/SushiBarContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,9 @@ +namespace SushiBarContracts.StoragesContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/SushiBarContracts.csproj b/SushiBar/SushiBarContracts/SushiBarContracts.csproj index 3794008..b943900 100644 --- a/SushiBar/SushiBarContracts/SushiBarContracts.csproj +++ b/SushiBar/SushiBarContracts/SushiBarContracts.csproj @@ -14,6 +14,8 @@ + + diff --git a/SushiBar/SushiBarContracts/ViewModels/ClientViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/ClientViewModel.cs index ca155f5..af0be8c 100644 --- a/SushiBar/SushiBarContracts/ViewModels/ClientViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/ClientViewModel.cs @@ -1,19 +1,20 @@ -using SushiBarDataModels.Models; -using System.ComponentModel; +using SushiBarContracts.Attributes; +using SushiBarDataModels.Models; namespace SushiBarContracts.ViewModels { public class ClientViewModel : IClientModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Клиент")] + [Column(title: "Клиент", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Логин (эл. почта)")] + [Column(title: "Логин (эл. почта)", width: 150)] public string Email { get; set; } = string.Empty; - [DisplayName("Пароль")] + [Column(title: "Пароль", width: 150)] public string Password { get; set; } = string.Empty; } } \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/ViewModels/ImplementerViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/ImplementerViewModel.cs index 943aa6d..66f6537 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.ComponentModel; namespace SushiBarContracts.ViewModels @@ -8,18 +9,19 @@ namespace SushiBarContracts.ViewModels /// public class ImplementerViewModel : IImplementerModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("ФИО исполнителя")] + [Column(title: "ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Пароль")] + [Column(title: "Пароль", width: 100)] public string Password { get; set; } = string.Empty; - [DisplayName("Стаж работы")] + [Column(title: "Стаж работы", width: 50)] public int WorkExperience { get; set; } - [DisplayName("Квалификация")] + [Column(title: "Квалификация", width: 50)] public int Qualification { get; set; } } } \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/ViewModels/IngredientViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/IngredientViewModel.cs index eada9d4..1f3da5c 100644 --- a/SushiBar/SushiBarContracts/ViewModels/IngredientViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/IngredientViewModel.cs @@ -1,14 +1,15 @@ -using SushiBarDataModels.Models; -using System.ComponentModel; +using SushiBarContracts.Attributes; +using SushiBarDataModels.Models; namespace SushiBarContracts.ViewModels { public class IngredientViewModel : IIngredientModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название ингредиента")] + [Column(title: "Ингредиент", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string IngredientName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column(title: "Цена", width: 150)] public double Cost { get; set; } } } diff --git a/SushiBar/SushiBarContracts/ViewModels/MessageInfoViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/MessageInfoViewModel.cs index ba77305..9ce1768 100644 --- a/SushiBar/SushiBarContracts/ViewModels/MessageInfoViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/MessageInfoViewModel.cs @@ -1,24 +1,29 @@ -using SushiBarDataModels.Models; -using System.ComponentModel; +using SushiBarContracts.Attributes; +using SushiBarDataModels.Models; namespace SushiBarContracts.ViewModels { public class MessageInfoViewModel : IMessageInfoModel { + [Column(visible: false)] public string MessageId { get; set; } = string.Empty; + [Column(visible: false)] public int? ClientId { get; set; } - [DisplayName("Отправитель")] + [Column(title: "Отправитель", width: 150)] public string SenderName { get; set; } = string.Empty; - [DisplayName("Дата письма")] + [Column(title: "Дата письма", width: 150)] public DateTime DateDelivery { get; set; } - [DisplayName("Заголовок")] + [Column(title: "Заголовок", width: 150)] public string Subject { get; set; } = string.Empty; - [DisplayName("Текст")] + [Column(title: "Текст", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string Body { get; set; } = string.Empty; + + [Column(visible: false)] + public int Id => throw new NotImplementedException(); } } \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs index c22a7a9..14d3cd8 100644 --- a/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs @@ -1,31 +1,34 @@ -using SushiBarDataModels.Enums; +using SushiBarContracts.Attributes; +using SushiBarDataModels.Enums; using SushiBarDataModels.Models; -using System.ComponentModel; namespace SushiBarContracts.ViewModels { public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] + [Column(title: "Номер", width: 50)] public int Id { get; set; } + [Column(visible: false)] public int SushiId { get; set; } + [Column(visible: false)] public int ClientId { get; set; } + [Column(visible: false)] public int? ImplementerId { get; set; } - [DisplayName("Суши")] + [Column(title: "Суши", width: 100)] public string SushiName { get; set; } = string.Empty; - [DisplayName("Клиент")] - public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Исполнитель")] + [Column(title: "Клиент", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ClientFIO { get; set; } = string.Empty; + [Column(title: "Исполнитель", width: 130)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Количество")] + [Column(title: "Количество", width: 100)] public int Count { get; set; } - [DisplayName("Сумма")] + [Column(title: "Сумма", width: 50)] public double Sum { get; set; } - [DisplayName("Статус")] + [Column(title: "Статус", width: 50)] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] + [Column(title: "Дата создания", width: 100)] public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] + [Column(title: "Дата выполнения", 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 12c51a0..9863d16 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(title: "Суши", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string SushiName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column(title: "Цена", width: 150)] public double Price { get; set; } + [Column(visible: false)] public Dictionary SushiIngredients { get; diff --git a/SushiBar/SushiBarDataModels/Models/IMessageInfoModel.cs b/SushiBar/SushiBarDataModels/Models/IMessageInfoModel.cs index 0443646..13a8eeb 100644 --- a/SushiBar/SushiBarDataModels/Models/IMessageInfoModel.cs +++ b/SushiBar/SushiBarDataModels/Models/IMessageInfoModel.cs @@ -1,6 +1,6 @@ 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..6bc0a58 --- /dev/null +++ b/SushiBar/SushiBarDatabaseImplement/DatabaseImplementationExtension.cs @@ -0,0 +1,22 @@ +using SushiBarContracts.DI; +using SushiBarContracts.StoragesContracts; +using SushiBarDatabaseImplement.Implements; + +namespace SushiBarDatabaseImplement +{ + public 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/Implements/BackUpInfo.cs b/SushiBar/SushiBarDatabaseImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..c9ed4db --- /dev/null +++ b/SushiBar/SushiBarDatabaseImplement/Implements/BackUpInfo.cs @@ -0,0 +1,27 @@ +using SushiBarContracts.StoragesContracts; + +namespace SushiBarDatabaseImplement.Implements +{ + 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; + } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Client.cs b/SushiBar/SushiBarDatabaseImplement/Models/Client.cs index 28ee46e..49fc9b8 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Client.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Client.cs @@ -3,16 +3,22 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace SushiBarDatabaseImplement.Models { - public class Client : IClientModel + [DataContract] + public class Client : IClientModel { + [DataMember] public int Id { get; private set; } + [DataMember] [Required] - public string ClientFIO { get; set; } = string.Empty; + public string ClientFIO { get; set; } = string.Empty; + [DataMember] [Required] - public string Email { get; set; } = string.Empty; + public string Email { get; set; } = string.Empty; + [DataMember] [Required] public string Password { get; set; } = string.Empty; diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Implementer.cs b/SushiBar/SushiBarDatabaseImplement/Models/Implementer.cs index b63d057..4392901 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Implementer.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Implementer.cs @@ -3,18 +3,25 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace SushiBarDatabaseImplement.Models { + [DataContract] public class Implementer : IImplementerModel { + [DataMember] public int Id { get; private set; } + [DataMember] [Required] - public string ImplementerFIO { get; private set; } = string.Empty; + public string ImplementerFIO { get; private set; } = string.Empty; + [DataMember] [Required] public string Password { get; private set; } = string.Empty; + [DataMember] [Required] public int WorkExperience { get; private set; } + [DataMember] [Required] public int Qualification { get; private set; } [ForeignKey("ImplementerId")] diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Ingredient.cs b/SushiBar/SushiBarDatabaseImplement/Models/Ingredient.cs index 37d313f..f6cfb41 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Ingredient.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Ingredient.cs @@ -3,19 +3,21 @@ 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; } - + [DataMember] [Required] public string IngredientName { get; private set; } = string.Empty; - + [DataMember] [Required] public double Cost { get; set; } - [ForeignKey("IngredientId")] public virtual List SushiIngredients { get; set; } = new(); diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Message.cs b/SushiBar/SushiBarDatabaseImplement/Models/Message.cs index f6b7173..f574d8e 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Message.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Message.cs @@ -2,20 +2,28 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace SushiBarDatabaseImplement.Models { + [DataContract] public class Message : IMessageInfoModel { + [DataMember] [Key] - public string MessageId { get; private set; } = string.Empty; + public string MessageId { get; private set; } = string.Empty; + [DataMember] public int? ClientId { get; private set; } + [DataMember] [Required] public string SenderName { get; private set; } = string.Empty; + [DataMember] [Required] public DateTime DateDelivery { get; private set; } = DateTime.Now; + [DataMember] [Required] public string Subject { get; private set; } = string.Empty; + [DataMember] [Required] public string Body { get; private set; } = string.Empty; @@ -45,5 +53,7 @@ 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 f15634f..1bba7c8 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Order.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Order.cs @@ -3,25 +3,36 @@ 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] [Required] public int SushiId { get; set; } + [DataMember] [Required] public int ClientId { get; set; } + [DataMember] public int? ImplementerId { get; private set; } + [DataMember] [Required] public int Count { get; set; } + [DataMember] [Required] public double Sum { get; set; } + [DataMember] [Required] public OrderStatus Status { get; set; } + [DataMember] [Required] public DateTime DateCreate { get; set; } + [DataMember] public DateTime? DateImplement { get; set; } + [DataMember] public int Id { get; set; } public Sushi Sushi { get; set; } public Client Client { get; set; } diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Sushi.cs b/SushiBar/SushiBarDatabaseImplement/Models/Sushi.cs index 009329f..e195fdc 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Sushi.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Sushi.cs @@ -3,21 +3,24 @@ 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; } - + [DataMember] [Required] public string SushiName { get; set; } = string.Empty; - + [DataMember] [Required] public double Price { get; set; } private Dictionary? _sushiIngredients = null; - + [DataMember] [NotMapped] public Dictionary SushiIngredients { diff --git a/SushiBar/SushiBarDatabaseImplement/SushiBarDatabaseImplement.csproj b/SushiBar/SushiBarDatabaseImplement/SushiBarDatabaseImplement.csproj index 1211e5e..b04acdd 100644 --- a/SushiBar/SushiBarDatabaseImplement/SushiBarDatabaseImplement.csproj +++ b/SushiBar/SushiBarDatabaseImplement/SushiBarDatabaseImplement.csproj @@ -20,4 +20,8 @@ + + + + diff --git a/SushiBar/SushiBarFileImplement/FileImplementationExtension.cs b/SushiBar/SushiBarFileImplement/FileImplementationExtension.cs new file mode 100644 index 0000000..2bcad25 --- /dev/null +++ b/SushiBar/SushiBarFileImplement/FileImplementationExtension.cs @@ -0,0 +1,22 @@ +using SushiBarContracts.DI; +using SushiBarContracts.StoragesContracts; +using SushiBarFileImplement.Implements; + +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..248c84b --- /dev/null +++ b/SushiBar/SushiBarFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,29 @@ +using SushiBarContracts.StoragesContracts; + +namespace SushiBarFileImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + 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/Models/Client.cs b/SushiBar/SushiBarFileImplement/Models/Client.cs index feb71c4..2da6c39 100644 --- a/SushiBar/SushiBarFileImplement/Models/Client.cs +++ b/SushiBar/SushiBarFileImplement/Models/Client.cs @@ -1,15 +1,21 @@ using SushiBarContracts.BindingModels; using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; +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; + [DataMember] + public string ClientFIO { get; private set; } = string.Empty; + [DataMember] public string Email { get; set; } = string.Empty; + [DataMember] public string Password { get; set; } = string.Empty; public static Client? Create(ClientBindingModel model) { diff --git a/SushiBar/SushiBarFileImplement/Models/Implementer.cs b/SushiBar/SushiBarFileImplement/Models/Implementer.cs index 0537bcd..648f80c 100644 --- a/SushiBar/SushiBarFileImplement/Models/Implementer.cs +++ b/SushiBar/SushiBarFileImplement/Models/Implementer.cs @@ -1,20 +1,23 @@ using SushiBarContracts.BindingModels; using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; +using System.Runtime.Serialization; 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(ImplementerBindingModel? model) diff --git a/SushiBar/SushiBarFileImplement/Models/Ingredient.cs b/SushiBar/SushiBarFileImplement/Models/Ingredient.cs index d940c5a..5079484 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; } - public string IngredientName { get; private set; } = string.Empty; + [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/Message.cs b/SushiBar/SushiBarFileImplement/Models/Message.cs index 2fdb025..ee7437d 100644 --- a/SushiBar/SushiBarFileImplement/Models/Message.cs +++ b/SushiBar/SushiBarFileImplement/Models/Message.cs @@ -2,22 +2,25 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; using System.Reflection; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SushiBarFileImplement.Models { + [DataContract] public class Message : 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 Message? Create(MessageInfoBindingModel model) @@ -72,5 +75,7 @@ namespace SushiBarFileImplement.Models 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 a52d7fa..36160e1 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 ClientId { get; private set; } + [DataMember] public int? ImplementerId { get; private set; } + [DataMember] public int SushiId { get; private set; } + [DataMember] public int Count { get; private set; } + [DataMember] public double Sum { get; private set; } - public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - public DateTime DateCreate { get; private set; } = DateTime.Now; + [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 ec3518c..f2497ce 100644 --- a/SushiBar/SushiBarFileImplement/Models/Sushi.cs +++ b/SushiBar/SushiBarFileImplement/Models/Sushi.cs @@ -1,17 +1,23 @@ 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? _sushiIngredients = null; + [DataMember] public Dictionary SushiIngredients { get diff --git a/SushiBar/SushiBarFileImplement/SushiBarFileImplement.csproj b/SushiBar/SushiBarFileImplement/SushiBarFileImplement.csproj index 428ac20..7e4bebe 100644 --- a/SushiBar/SushiBarFileImplement/SushiBarFileImplement.csproj +++ b/SushiBar/SushiBarFileImplement/SushiBarFileImplement.csproj @@ -18,4 +18,8 @@ + + + + diff --git a/SushiBar/SushiBarListImplement/Implements/BackUpInfo.cs b/SushiBar/SushiBarListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..93f3057 --- /dev/null +++ b/SushiBar/SushiBarListImplement/Implements/BackUpInfo.cs @@ -0,0 +1,17 @@ +using SushiBarContracts.StoragesContracts; + +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(); + } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarListImplement/ListImplementationExtension.cs b/SushiBar/SushiBarListImplement/ListImplementationExtension.cs new file mode 100644 index 0000000..c737e3e --- /dev/null +++ b/SushiBar/SushiBarListImplement/ListImplementationExtension.cs @@ -0,0 +1,22 @@ +using SushiBarContracts.DI; +using SushiBarContracts.StoragesContracts; +using SushiBarListImplement.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(); + } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarListImplement/Models/Message.cs b/SushiBar/SushiBarListImplement/Models/Message.cs index e6a08d4..185f1e9 100644 --- a/SushiBar/SushiBarListImplement/Models/Message.cs +++ b/SushiBar/SushiBarListImplement/Models/Message.cs @@ -44,5 +44,7 @@ namespace SushiBarListImplement.Models ClientId = ClientId, MessageId = MessageId }; + + public int Id => throw new NotImplementedException(); } } diff --git a/SushiBar/SushiBarListImplement/SushiBarListImplement.csproj b/SushiBar/SushiBarListImplement/SushiBarListImplement.csproj index 6a2b0ac..d77cc96 100644 --- a/SushiBar/SushiBarListImplement/SushiBarListImplement.csproj +++ b/SushiBar/SushiBarListImplement/SushiBarListImplement.csproj @@ -21,4 +21,8 @@ + + + + From 9af64109dd1c8893f8b9cbaccef841b6145cc6ff Mon Sep 17 00:00:00 2001 From: dasha Date: Tue, 2 May 2023 21:23:58 +0400 Subject: [PATCH 9/9] =?UTF-8?q?=D1=80=D1=83=D0=B8=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .gitignore.bak | 401 ++++++++++++++++++ SushiBar/SushiBar/FormMain.cs | 2 +- .../BusinessLogics/BackUpLogic.cs | 2 +- ...idngModel.cs => BackUpSaveBindingModel.cs} | 2 +- .../BusinessLogicsContracts/IBackUpLogic.cs | 2 +- 6 files changed, 406 insertions(+), 4 deletions(-) create mode 100644 .gitignore.bak rename SushiBar/SushiBarContracts/BindingModels/{BackUpSaveBinidngModel.cs => BackUpSaveBindingModel.cs} (74%) diff --git a/.gitignore b/.gitignore index 7ccc4e3..359c4db 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs ImplementationExtensions +BusinessLogicExtensions # Mono auto generated files mono_crash.* diff --git a/.gitignore.bak b/.gitignore.bak new file mode 100644 index 0000000..7ccc4e3 --- /dev/null +++ b/.gitignore.bak @@ -0,0 +1,401 @@ +# ---> VisualStudio +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs +ImplementationExtensions + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml + diff --git a/SushiBar/SushiBar/FormMain.cs b/SushiBar/SushiBar/FormMain.cs index ab6b906..0f15099 100644 --- a/SushiBar/SushiBar/FormMain.cs +++ b/SushiBar/SushiBar/FormMain.cs @@ -217,7 +217,7 @@ namespace SushiBarView var fbd = new FolderBrowserDialog(); if (fbd.ShowDialog() == DialogResult.OK) { - _backUpLogic.CreateBackUp(new BackUpSaveBinidngModel + _backUpLogic.CreateBackUp(new BackUpSaveBindingModel { FolderName = fbd.SelectedPath }); diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/BackUpLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/BackUpLogic.cs index 3d0cd11..735f7e5 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/BackUpLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/BackUpLogic.cs @@ -21,7 +21,7 @@ namespace SushiBarBusinessLogic.BusinessLogics _backUpInfo = backUpInfo; } - public void CreateBackUp(BackUpSaveBinidngModel model) + public void CreateBackUp(BackUpSaveBindingModel model) { if (_backUpInfo == null) { diff --git a/SushiBar/SushiBarContracts/BindingModels/BackUpSaveBinidngModel.cs b/SushiBar/SushiBarContracts/BindingModels/BackUpSaveBindingModel.cs similarity index 74% rename from SushiBar/SushiBarContracts/BindingModels/BackUpSaveBinidngModel.cs rename to SushiBar/SushiBarContracts/BindingModels/BackUpSaveBindingModel.cs index fe2ca2d..2bc0a99 100644 --- a/SushiBar/SushiBarContracts/BindingModels/BackUpSaveBinidngModel.cs +++ b/SushiBar/SushiBarContracts/BindingModels/BackUpSaveBindingModel.cs @@ -1,6 +1,6 @@ namespace SushiBarContracts.BindingModels { - public class BackUpSaveBinidngModel + public class BackUpSaveBindingModel { public string FolderName { get; set; } = string.Empty; } diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IBackUpLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IBackUpLogic.cs index 91ae4a0..2420c0a 100644 --- a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IBackUpLogic.cs +++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -4,6 +4,6 @@ namespace SushiBarContracts.BusinessLogicsContracts { public interface IBackUpLogic { - void CreateBackUp(BackUpSaveBinidngModel model); + void CreateBackUp(BackUpSaveBindingModel model); } } \ No newline at end of file