diff --git a/SushiBar/SushiBar/FormMails.Designer.cs b/SushiBar/SushiBar/FormMails.Designer.cs index 610f011..237a5cd 100644 --- a/SushiBar/SushiBar/FormMails.Designer.cs +++ b/SushiBar/SushiBar/FormMails.Designer.cs @@ -29,6 +29,8 @@ private void InitializeComponent() { this.dataGridView = new System.Windows.Forms.DataGridView(); + this.PrevButton = new System.Windows.Forms.Button(); + this.NextButton = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); // @@ -40,12 +42,35 @@ this.dataGridView.RowTemplate.Height = 25; this.dataGridView.Size = new System.Drawing.Size(776, 426); this.dataGridView.TabIndex = 0; + this.dataGridView.RowHeaderMouseDoubleClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.DataGridView_RowHeaderMouseDoubleClick); + // + // PrevButton + // + this.PrevButton.Location = new System.Drawing.Point(794, 415); + this.PrevButton.Name = "PrevButton"; + this.PrevButton.Size = new System.Drawing.Size(75, 23); + this.PrevButton.TabIndex = 1; + this.PrevButton.Text = "<"; + this.PrevButton.UseVisualStyleBackColor = true; + this.PrevButton.Click += new System.EventHandler(this.PrevButton_Click); + // + // NextButton + // + this.NextButton.Location = new System.Drawing.Point(794, 386); + this.NextButton.Name = "NextButton"; + this.NextButton.Size = new System.Drawing.Size(75, 23); + this.NextButton.TabIndex = 2; + this.NextButton.Text = ">"; + this.NextButton.UseVisualStyleBackColor = true; + this.NextButton.Click += new System.EventHandler(this.NextButton_Click); // // FormMails // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); + this.ClientSize = new System.Drawing.Size(882, 450); + this.Controls.Add(this.NextButton); + this.Controls.Add(this.PrevButton); this.Controls.Add(this.dataGridView); this.Name = "FormMails"; this.Text = "FormMails"; @@ -58,5 +83,7 @@ #endregion private DataGridView dataGridView; + private Button PrevButton; + private Button NextButton; } } \ No newline at end of file diff --git a/SushiBar/SushiBar/FormMails.cs b/SushiBar/SushiBar/FormMails.cs index 28ec5f7..7c48986 100644 --- a/SushiBar/SushiBar/FormMails.cs +++ b/SushiBar/SushiBar/FormMails.cs @@ -1,5 +1,7 @@ using Microsoft.Extensions.Logging; using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; namespace SushiBar { @@ -7,6 +9,8 @@ namespace SushiBar { private readonly ILogger _logger; private readonly IMessageInfoLogic _logic; + private int page = 1; + private int pageSize = 3; public FormMails(ILogger logger, IMessageInfoLogic logic) { @@ -14,18 +18,25 @@ namespace SushiBar _logger = logger; _logic = logic; LoadData(); + PrevButton.Enabled = false; } private void LoadData() { try { - var list = _logic.ReadList(null); + var list = _logic.ReadList(new MessageInfoSearchModel + { + Page = page, + PageSize = pageSize, + }); + if (list != null) { dataGridView.DataSource = list; dataGridView.Columns["ClientId"].Visible = false; dataGridView.Columns["MessageId"].Visible = false; + dataGridView.Columns["Reply"].Visible = false; dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Load mails"); @@ -41,5 +52,45 @@ namespace SushiBar { LoadData(); } + + private void NextButton_Click(object sender, EventArgs e) + { + page++; + LoadData(); + if (((List)dataGridView.DataSource).Count == 0) + { + _logger.LogWarning("Out of range messages"); + page--; + NextButton.Enabled = false; + } + else + { + PrevButton.Enabled = true; + } + } + + private void PrevButton_Click(object sender, EventArgs e) + { + if (page == 1) + { + return; + } + page--; + LoadData(); + NextButton.Enabled = true; + if (page == 1) + { + PrevButton.Enabled = false; + } + } + + private void DataGridView_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReplyMail)); + if (service is not FormReplyMail form) return; + form.MessageId = (string)dataGridView.Rows[e.RowIndex].Cells["MessageId"].Value; + form.ShowDialog(); + LoadData(); + } } } diff --git a/SushiBar/SushiBar/FormReplyMail.Designer.cs b/SushiBar/SushiBar/FormReplyMail.Designer.cs new file mode 100644 index 0000000..15f0fb4 --- /dev/null +++ b/SushiBar/SushiBar/FormReplyMail.Designer.cs @@ -0,0 +1,122 @@ +namespace SushiBar +{ + partial class FormReplyMail + { + /// + /// 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() + { + this.labelClient = new System.Windows.Forms.Label(); + this.labelOrder = new System.Windows.Forms.Label(); + this.ReplyText = new System.Windows.Forms.RichTextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.buttonReply = new System.Windows.Forms.Button(); + this.buttonClose = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelClient + // + this.labelClient.AutoSize = true; + this.labelClient.Location = new System.Drawing.Point(12, 9); + this.labelClient.Name = "labelClient"; + this.labelClient.Size = new System.Drawing.Size(38, 15); + this.labelClient.TabIndex = 0; + this.labelClient.Text = "label1"; + // + // labelOrder + // + this.labelOrder.AutoSize = true; + this.labelOrder.Location = new System.Drawing.Point(12, 38); + this.labelOrder.Name = "labelOrder"; + this.labelOrder.Size = new System.Drawing.Size(38, 15); + this.labelOrder.TabIndex = 1; + this.labelOrder.Text = "label2"; + // + // ReplyText + // + this.ReplyText.Location = new System.Drawing.Point(12, 88); + this.ReplyText.Name = "ReplyText"; + this.ReplyText.Size = new System.Drawing.Size(776, 315); + this.ReplyText.TabIndex = 2; + this.ReplyText.Text = ""; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(12, 70); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(59, 15); + this.label3.TabIndex = 3; + this.label3.Text = "Reply text"; + // + // buttonReply + // + this.buttonReply.Location = new System.Drawing.Point(12, 415); + this.buttonReply.Name = "buttonReply"; + this.buttonReply.Size = new System.Drawing.Size(75, 23); + this.buttonReply.TabIndex = 4; + this.buttonReply.Text = "Reply"; + this.buttonReply.UseVisualStyleBackColor = true; + this.buttonReply.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonClose + // + this.buttonClose.Location = new System.Drawing.Point(93, 415); + this.buttonClose.Name = "buttonClose"; + this.buttonClose.Size = new System.Drawing.Size(75, 23); + this.buttonClose.TabIndex = 5; + this.buttonClose.Text = "Close"; + this.buttonClose.UseVisualStyleBackColor = true; + this.buttonClose.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormReplyMail + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonClose); + this.Controls.Add(this.buttonReply); + this.Controls.Add(this.label3); + this.Controls.Add(this.ReplyText); + this.Controls.Add(this.labelOrder); + this.Controls.Add(this.labelClient); + this.Name = "FormReplyMail"; + this.Text = "FormReplyMail"; + this.Load += new System.EventHandler(this.FormReplyMail_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelClient; + private Label labelOrder; + private RichTextBox ReplyText; + private Label label3; + private Button buttonReply; + private Button buttonClose; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBar/FormReplyMail.cs b/SushiBar/SushiBar/FormReplyMail.cs new file mode 100644 index 0000000..0f4e98f --- /dev/null +++ b/SushiBar/SushiBar/FormReplyMail.cs @@ -0,0 +1,80 @@ +using Microsoft.Extensions.Logging; +using SushiBarBusinessLogic.MailWorker; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; +namespace SushiBar +{ + public partial class FormReplyMail : Form + { + private readonly ILogger _logger; + private readonly AbstractMailWorker _mailWorker; + private readonly IMessageInfoLogic _logic; + private MessageInfoViewModel? _message = null; + + public string MessageId { get; set; } = string.Empty; + + public FormReplyMail(ILogger logger, + AbstractMailWorker mailWorker, + IMessageInfoLogic logic) + { + InitializeComponent(); + _logger = logger; + _mailWorker = mailWorker; + _logic = logic; + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + _mailWorker.MailSendAsync(new MailSendInfoBindingModel + { + MailAddress = _message.SenderName, + Subject = _message.Subject, + Text = ReplyText.Text, + }); + _logic.Update(new MessageInfoBindingModel + { + MessageId = MessageId, + Reply = ReplyText.Text, + IsRead = true, + }); + MessageBox.Show("Mail sended", "Sending mail", MessageBoxButtons.OK); + DialogResult = DialogResult.OK; + Close(); + } + + private void FormReplyMail_Load(object sender, EventArgs e) + { + try + { + _message = _logic.ReadElement(new MessageInfoSearchModel + { + MessageId = MessageId + }); + Text += $"For {_message.SenderName}"; + labelClient.Text = _message.Subject; + labelOrder.Text = _message.Body; + if (!_message.IsRead) + { + _logic.Update(new MessageInfoBindingModel + { + MessageId = MessageId, + IsRead = true, + Reply = _message.Reply + }); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/SushiBar/SushiBar/FormReplyMail.resx b/SushiBar/SushiBar/FormReplyMail.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SushiBar/SushiBar/FormReplyMail.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Program.cs b/SushiBar/SushiBar/Program.cs index c4ca272..d5beaf2 100644 --- a/SushiBar/SushiBar/Program.cs +++ b/SushiBar/SushiBar/Program.cs @@ -10,102 +10,102 @@ using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.StoragesContracts; using SushiBarDatabaseImplement.Implements; -namespace SushiBar +namespace SushiBar; + +internal static class Program { - internal static class Program + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + + [STAThread] + static void Main() { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; - - [STAThread] - static void Main() + ApplicationConfiguration.Initialize(); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + try { - ApplicationConfiguration.Initialize(); - var services = new ServiceCollection(); - ConfigureServices(services); - _serviceProvider = services.BuildServiceProvider(); - try + var mailSender = _serviceProvider.GetService(); + mailSender?.MailConfig(new MailConfigBindingModel { - 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(MailCheck!, null, 0, 100000); - } - catch(Exception ex) - { - var logger = _serviceProvider.GetService(); - logger?.LogError(ex, "Error on working w/ email"); - } - - Application.Run(_serviceProvider.GetRequiredService()); - } - private static void ConfigureServices(IServiceCollection services) - { - services.AddLogging(option => - { - option.SetMinimumLevel(LogLevel.Information); - option.AddNLog("nlog.config"); + 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"]) }); - 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.AddSingleton(); - - 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(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + var timer = new System.Threading.Timer(MailCheck!, null, 0, 100000); } - - private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); + catch(Exception ex) + { + var logger = _serviceProvider.GetService(); + logger?.LogError(ex, "Error on working w/ email"); + } + + Application.Run(_serviceProvider.GetRequiredService()); } + private static void ConfigureServices(IServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + 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.AddSingleton(); + + 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(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + } + + private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); } \ No newline at end of file diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/MessageInfoLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/MessageInfoLogic.cs index 0abf566..6f2f978 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/MessageInfoLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/MessageInfoLogic.cs @@ -28,13 +28,29 @@ public class MessageInfoLogic : IMessageInfoLogic public List? ReadList(MessageInfoSearchModel? model) { - _logger.LogInformation("ReadList. MessageId:{MessageId}.ClientId:{ClientId} ", + _logger.LogInformation("ReadList. MessageId:{MessageId} .ClientId:{ClientId} .Page:{Page}", model?.MessageId, - model?.ClientId); + model?.ClientId, + model.Page); var list = model == null ? _messageStorage.GetFullList() : _messageStorage.GetFilteredList(model); _logger.LogInformation("ReadList. Count: {Count}", list.Count); return list; } + + public bool Update(MessageInfoBindingModel model) + { + if (_messageStorage.Update(model) != null) return true; + _logger.LogWarning("Update operation failed"); + return false; + } + + public MessageInfoViewModel? ReadElement(MessageInfoSearchModel model) + { + var res = _messageStorage.GetElement(model); + if (res != null) return res; + _logger.LogWarning("Read element operation failed"); + return null; + } } \ No newline at end of file diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs index 7459de1..03c37c3 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs @@ -1,5 +1,5 @@ -using DocumentFormat.OpenXml.EMMA; using Microsoft.Extensions.Logging; +using SushiBarBusinessLogic.MailWorker; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.SearchModels; @@ -18,8 +18,7 @@ namespace SushiBarBusinessLogic.BusinessLogics private readonly AbstractMailWorker _mailWorker; private readonly IClientLogic _clientLogic; - public OrderLogic(ILogger logger, - IOrderStorage orderStorage, + public OrderLogic(ILogger logger, IStoreLogic storeLogic, ISushiStorage sushiStorage, IOrderStorage orderStorage, diff --git a/SushiBar/SushiBarClientApi/Controllers/HomeController.cs b/SushiBar/SushiBarClientApi/Controllers/HomeController.cs index 6063620..05c339a 100644 --- a/SushiBar/SushiBarClientApi/Controllers/HomeController.cs +++ b/SushiBar/SushiBarClientApi/Controllers/HomeController.cs @@ -151,13 +151,16 @@ namespace SushiBarClientApi.Controllers } [HttpGet] - public IActionResult Mails() + public IActionResult Mails(int page=1) { if (APIClient.Client == null) { return Redirect("~/Home/Enter"); } - return View(APIClient.GetRequest>($"api/client/GetMessages?clientId={APIClient.Client.Id}")); + return View(APIClient + .GetRequest>( + $"api/client/GetMessages?clientId={APIClient.Client.Id}&page={page}" + )); } } } \ No newline at end of file diff --git a/SushiBar/SushiBarClientApi/Views/Home/Mails.cshtml b/SushiBar/SushiBarClientApi/Views/Home/Mails.cshtml index a84f13a..b0ecd74 100644 --- a/SushiBar/SushiBarClientApi/Views/Home/Mails.cshtml +++ b/SushiBar/SushiBarClientApi/Views/Home/Mails.cshtml @@ -3,7 +3,7 @@ ViewData["Title"] = "Mails"; }
-

Заказы

+

Mail

@{ @@ -16,13 +16,13 @@ - Дата письма + Date - Заголовок + Title - Текст + Text @@ -47,4 +47,48 @@ } -
\ No newline at end of file + + + \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/BindingModels/MessageInfoBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/MessageInfoBindingModel.cs index 8ceba17..fddc936 100644 --- a/SushiBar/SushiBarContracts/BindingModels/MessageInfoBindingModel.cs +++ b/SushiBar/SushiBarContracts/BindingModels/MessageInfoBindingModel.cs @@ -10,4 +10,6 @@ public class MessageInfoBindingModel : IMessageInfoModel public DateTime DateDelivery { get; set; } public string Subject { get; set; } = string.Empty; public string Body { get; set; } = string.Empty; + public bool IsRead { get; set; } + public string? Reply { get; set; } } \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IMessageInfoLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IMessageInfoLogic.cs index 963886c..590303a 100644 --- a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IMessageInfoLogic.cs +++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IMessageInfoLogic.cs @@ -8,4 +8,6 @@ public interface IMessageInfoLogic { List? ReadList(MessageInfoSearchModel? model); bool Create(MessageInfoBindingModel model); + bool Update(MessageInfoBindingModel model); + MessageInfoViewModel? ReadElement(MessageInfoSearchModel model); } \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/SearchModels/MessageInfoSearchModel.cs b/SushiBar/SushiBarContracts/SearchModels/MessageInfoSearchModel.cs index 10351bd..063bcbb 100644 --- a/SushiBar/SushiBarContracts/SearchModels/MessageInfoSearchModel.cs +++ b/SushiBar/SushiBarContracts/SearchModels/MessageInfoSearchModel.cs @@ -4,4 +4,6 @@ public class MessageInfoSearchModel { public string? MessageId { get; set; } public int? ClientId { get; set; } + public int? Page { get; set; } + public int? PageSize { get; set; } } \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/StoragesContracts/IMessageInfoStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/IMessageInfoStorage.cs index 42b700a..bd39244 100644 --- a/SushiBar/SushiBarContracts/StoragesContracts/IMessageInfoStorage.cs +++ b/SushiBar/SushiBarContracts/StoragesContracts/IMessageInfoStorage.cs @@ -10,4 +10,5 @@ public interface IMessageInfoStorage List GetFilteredList(MessageInfoSearchModel model); MessageInfoViewModel? GetElement(MessageInfoSearchModel model); MessageInfoViewModel? Insert(MessageInfoBindingModel model); + MessageInfoViewModel? Update(MessageInfoBindingModel model); } \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/ViewModels/MessageInfoViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/MessageInfoViewModel.cs index 5ec60fb..da00573 100644 --- a/SushiBar/SushiBarContracts/ViewModels/MessageInfoViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/MessageInfoViewModel.cs @@ -13,4 +13,6 @@ public class MessageInfoViewModel : IMessageInfoModel public DateTime DateDelivery { get; set; } public string Subject { get; set; } public string Body { get; set; } + public bool IsRead { get; set; } + public string? Reply { get; set; } } \ No newline at end of file diff --git a/SushiBar/SushiBarDatabaseImplement/Implements/MessageStorage.cs b/SushiBar/SushiBarDatabaseImplement/Implements/MessageStorage.cs index 765b11e..87040f0 100644 --- a/SushiBar/SushiBarDatabaseImplement/Implements/MessageStorage.cs +++ b/SushiBar/SushiBarDatabaseImplement/Implements/MessageStorage.cs @@ -18,13 +18,14 @@ public class MessageStorage : IMessageInfoStorage public List GetFilteredList(MessageInfoSearchModel model) { - if (!model.ClientId.HasValue) - return new List(); using var context = new SushiBarDatabase(); - return context.Messages - .Where(x => x.ClientId == model.ClientId) + var res = context.Messages + .Where(x => !model.ClientId.HasValue || x.ClientId == model.ClientId) .Select(x => x.GetViewModel) .ToList(); + return model is not { Page: { }, PageSize: { } } ? + res.ToList() : + res.Skip((model.Page.Value - 1) * model.PageSize.Value).Take(model.PageSize.Value).ToList(); } public List GetFullList() @@ -47,4 +48,14 @@ public class MessageStorage : IMessageInfoStorage context.SaveChanges(); return newMessage.GetViewModel; } + + public MessageInfoViewModel? Update(MessageInfoBindingModel model) + { + using var context = new SushiBarDatabase(); + var res = context.Messages.FirstOrDefault(x => x.MessageId.Equals(model.MessageId)); + if (res == null) return res?.GetViewModel; + res.Update(model); + context.SaveChanges(); + return res?.GetViewModel; + } } \ No newline at end of file diff --git a/SushiBar/SushiBarDatabaseImplement/Migrations/20230410100751_lab6.Designer.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/20230410100751_lab6.Designer.cs deleted file mode 100644 index 88a6326..0000000 --- a/SushiBar/SushiBarDatabaseImplement/Migrations/20230410100751_lab6.Designer.cs +++ /dev/null @@ -1,251 +0,0 @@ -// -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("20230410100751_lab6")] - partial class lab6 - { - /// - 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.Component", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComponentName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Cost") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.ToTable("Components"); - }); - - 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.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.Property("SushiName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - 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("Sushi"); - }); - - modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiComponent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComponentId") - .HasColumnType("int"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("SushiId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ComponentId"); - - b.HasIndex("SushiId"); - - b.ToTable("SushiComponents"); - }); - - modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b => - { - b.HasOne("SushiBarDatabaseImplement.Models.Client", "Client") - .WithMany() - .HasForeignKey("ClientId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("SushiBarDatabaseImplement.Models.Implementer", "Implementer") - .WithMany() - .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.SushiComponent", b => - { - b.HasOne("SushiBarDatabaseImplement.Models.Component", "Component") - .WithMany("SushiComponent") - .HasForeignKey("ComponentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi") - .WithMany("Components") - .HasForeignKey("SushiId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Component"); - - b.Navigation("Sushi"); - }); - - modelBuilder.Entity("SushiBarDatabaseImplement.Models.Component", b => - { - b.Navigation("SushiComponent"); - }); - - modelBuilder.Entity("SushiBarDatabaseImplement.Models.Sushi", b => - { - b.Navigation("Components"); - - b.Navigation("Orders"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/SushiBar/SushiBarDatabaseImplement/Migrations/20230410100751_lab6.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/20230410100751_lab6.cs deleted file mode 100644 index 4bde589..0000000 --- a/SushiBar/SushiBarDatabaseImplement/Migrations/20230410100751_lab6.cs +++ /dev/null @@ -1,67 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace SushiBarDatabaseImplement.Migrations -{ - /// - public partial class lab6 : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "ImplementerId", - table: "Orders", - type: "int", - nullable: true); - - migrationBuilder.CreateTable( - name: "Implementers", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ImplementerFio = table.Column(type: "nvarchar(max)", nullable: false), - Password = table.Column(type: "nvarchar(max)", nullable: false), - WorkExperience = table.Column(type: "int", nullable: false), - Qualification = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Implementers", x => x.Id); - }); - - migrationBuilder.CreateIndex( - name: "IX_Orders_ImplementerId", - table: "Orders", - column: "ImplementerId"); - - migrationBuilder.AddForeignKey( - name: "FK_Orders_Implementers_ImplementerId", - table: "Orders", - column: "ImplementerId", - principalTable: "Implementers", - principalColumn: "Id"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Orders_Implementers_ImplementerId", - table: "Orders"); - - migrationBuilder.DropTable( - name: "Implementers"); - - migrationBuilder.DropIndex( - name: "IX_Orders_ImplementerId", - table: "Orders"); - - migrationBuilder.DropColumn( - name: "ImplementerId", - table: "Orders"); - } - } -} diff --git a/SushiBar/SushiBarDatabaseImplement/Migrations/20230423155623_lab7.Designer.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/20230423155623_lab7.Designer.cs deleted file mode 100644 index 1537609..0000000 --- a/SushiBar/SushiBarDatabaseImplement/Migrations/20230423155623_lab7.Designer.cs +++ /dev/null @@ -1,290 +0,0 @@ -// -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("20230423155623_lab7")] - partial class lab7 - { - /// - 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.Component", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComponentName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Cost") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.ToTable("Components"); - }); - - 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.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.Property("SushiName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - 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("Sushi"); - }); - - modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiComponent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComponentId") - .HasColumnType("int"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("SushiId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ComponentId"); - - b.HasIndex("SushiId"); - - b.ToTable("SushiComponents"); - }); - - modelBuilder.Entity("SushiBarDatabaseImplement.Models.Message", b => - { - b.HasOne("SushiBarDatabaseImplement.Models.Client", "Client") - .WithMany() - .HasForeignKey("ClientId"); - - b.Navigation("Client"); - }); - - modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b => - { - b.HasOne("SushiBarDatabaseImplement.Models.Client", "Client") - .WithMany() - .HasForeignKey("ClientId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("SushiBarDatabaseImplement.Models.Implementer", "Implementer") - .WithMany() - .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.SushiComponent", b => - { - b.HasOne("SushiBarDatabaseImplement.Models.Component", "Component") - .WithMany("SushiComponent") - .HasForeignKey("ComponentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi") - .WithMany("Components") - .HasForeignKey("SushiId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Component"); - - b.Navigation("Sushi"); - }); - - modelBuilder.Entity("SushiBarDatabaseImplement.Models.Component", b => - { - b.Navigation("SushiComponent"); - }); - - modelBuilder.Entity("SushiBarDatabaseImplement.Models.Sushi", b => - { - b.Navigation("Components"); - - b.Navigation("Orders"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/SushiBar/SushiBarDatabaseImplement/Migrations/20230423155623_lab7.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/20230423155623_lab7.cs deleted file mode 100644 index e07a88d..0000000 --- a/SushiBar/SushiBarDatabaseImplement/Migrations/20230423155623_lab7.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace SushiBarDatabaseImplement.Migrations -{ - /// - public partial class lab7 : 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); - table.ForeignKey( - name: "FK_Messages_Clients_ClientId", - column: x => x.ClientId, - principalTable: "Clients", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_Messages_ClientId", - table: "Messages", - column: "ClientId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Messages"); - } - } -} diff --git a/SushiBar/SushiBarDatabaseImplement/Migrations/20230425050030_lab5hard.Designer.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/20230504200506_lab7Hard.Designer.cs similarity index 86% rename from SushiBar/SushiBarDatabaseImplement/Migrations/20230425050030_lab5hard.Designer.cs rename to SushiBar/SushiBarDatabaseImplement/Migrations/20230504200506_lab7Hard.Designer.cs index 8a0d768..27080bc 100644 --- a/SushiBar/SushiBarDatabaseImplement/Migrations/20230425050030_lab5hard.Designer.cs +++ b/SushiBar/SushiBarDatabaseImplement/Migrations/20230504200506_lab7Hard.Designer.cs @@ -12,8 +12,8 @@ using SushiBarDatabaseImplement; namespace SushiBarDatabaseImplement.Migrations { [DbContext(typeof(SushiBarDatabase))] - [Migration("20230425050030_lab5hard")] - partial class lab5hard + [Migration("20230504200506_lab7Hard")] + partial class lab7Hard { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -97,6 +97,42 @@ namespace SushiBarDatabaseImplement.Migrations b.ToTable("Implementers"); }); + 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("IsRead") + .HasColumnType("bit"); + + b.Property("Reply") + .HasColumnType("nvarchar(max)"); + + 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") @@ -117,6 +153,9 @@ namespace SushiBarDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("Status") .HasColumnType("int"); @@ -134,6 +173,8 @@ namespace SushiBarDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("SushiId"); b.ToTable("Orders"); @@ -209,7 +250,7 @@ namespace SushiBarDatabaseImplement.Migrations b.HasKey("Id"); - b.ToTable("Sushi"); + b.ToTable("Sushis"); }); modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiComponent", b => @@ -255,6 +296,10 @@ namespace SushiBarDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("SushiBarDatabaseImplement.Models.Implementer", "Implementer") + .WithMany() + .HasForeignKey("ImplementerId"); + b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi") .WithMany("Orders") .HasForeignKey("SushiId") @@ -263,6 +308,8 @@ namespace SushiBarDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Sushi"); }); diff --git a/SushiBar/SushiBarDatabaseImplement/Migrations/20230425050030_lab5hard.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/20230504200506_lab7Hard.cs similarity index 71% rename from SushiBar/SushiBarDatabaseImplement/Migrations/20230425050030_lab5hard.cs rename to SushiBar/SushiBarDatabaseImplement/Migrations/20230504200506_lab7Hard.cs index dc00d16..c2c015a 100644 --- a/SushiBar/SushiBarDatabaseImplement/Migrations/20230425050030_lab5hard.cs +++ b/SushiBar/SushiBarDatabaseImplement/Migrations/20230504200506_lab7Hard.cs @@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace SushiBarDatabaseImplement.Migrations { /// - public partial class lab5hard : Migration + public partial class lab7Hard : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -40,6 +40,22 @@ namespace SushiBarDatabaseImplement.Migrations table.PrimaryKey("PK_Components", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Implementers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ImplementerFio = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + WorkExperience = table.Column(type: "int", nullable: false), + Qualification = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implementers", x => x.Id); + }); + migrationBuilder.CreateTable( name: "Stores", columns: table => new @@ -57,7 +73,7 @@ namespace SushiBarDatabaseImplement.Migrations }); migrationBuilder.CreateTable( - name: "Sushi", + name: "Sushis", columns: table => new { Id = table.Column(type: "int", nullable: false) @@ -67,7 +83,30 @@ namespace SushiBarDatabaseImplement.Migrations }, constraints: table => { - table.PrimaryKey("PK_Sushi", x => x.Id); + table.PrimaryKey("PK_Sushis", x => x.Id); + }); + + 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), + IsRead = table.Column(type: "bit", nullable: false), + Reply = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Messages", x => x.MessageId); + table.ForeignKey( + name: "FK_Messages_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id"); }); migrationBuilder.CreateTable( @@ -78,6 +117,7 @@ namespace SushiBarDatabaseImplement.Migrations .Annotation("SqlServer:Identity", "1, 1"), SushiId = table.Column(type: "int", nullable: false), ClientId = table.Column(type: "int", nullable: false), + ImplementerId = table.Column(type: "int", nullable: true), SushiName = table.Column(type: "nvarchar(max)", nullable: false), Count = table.Column(type: "int", nullable: false), Sum = table.Column(type: "float", nullable: false), @@ -95,9 +135,14 @@ namespace SushiBarDatabaseImplement.Migrations principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( - name: "FK_Orders_Sushi_SushiId", + name: "FK_Orders_Implementers_ImplementerId", + column: x => x.ImplementerId, + principalTable: "Implementers", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_Orders_Sushis_SushiId", column: x => x.SushiId, - principalTable: "Sushi", + principalTable: "Sushis", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); @@ -122,9 +167,9 @@ namespace SushiBarDatabaseImplement.Migrations principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( - name: "FK_StoreSushis_Sushi_SushiId", + name: "FK_StoreSushis_Sushis_SushiId", column: x => x.SushiId, - principalTable: "Sushi", + principalTable: "Sushis", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); @@ -149,18 +194,28 @@ namespace SushiBarDatabaseImplement.Migrations principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( - name: "FK_SushiComponents_Sushi_SushiId", + name: "FK_SushiComponents_Sushis_SushiId", column: x => x.SushiId, - principalTable: "Sushi", + principalTable: "Sushis", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateIndex( + name: "IX_Messages_ClientId", + table: "Messages", + column: "ClientId"); + migrationBuilder.CreateIndex( name: "IX_Orders_ClientId", table: "Orders", column: "ClientId"); + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); + migrationBuilder.CreateIndex( name: "IX_Orders_SushiId", table: "Orders", @@ -190,6 +245,9 @@ namespace SushiBarDatabaseImplement.Migrations /// protected override void Down(MigrationBuilder migrationBuilder) { + migrationBuilder.DropTable( + name: "Messages"); + migrationBuilder.DropTable( name: "Orders"); @@ -202,6 +260,9 @@ namespace SushiBarDatabaseImplement.Migrations migrationBuilder.DropTable( name: "Clients"); + migrationBuilder.DropTable( + name: "Implementers"); + migrationBuilder.DropTable( name: "Stores"); @@ -209,7 +270,7 @@ namespace SushiBarDatabaseImplement.Migrations name: "Components"); migrationBuilder.DropTable( - name: "Sushi"); + name: "Sushis"); } } } diff --git a/SushiBar/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs index 5d8c03b..6bc4610 100644 --- a/SushiBar/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs +++ b/SushiBar/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs @@ -94,6 +94,42 @@ namespace SushiBarDatabaseImplement.Migrations b.ToTable("Implementers"); }); + 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("IsRead") + .HasColumnType("bit"); + + b.Property("Reply") + .HasColumnType("nvarchar(max)"); + + 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") @@ -240,6 +276,15 @@ namespace SushiBarDatabaseImplement.Migrations b.ToTable("SushiComponents"); }); + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Message", b => + { + b.HasOne("SushiBarDatabaseImplement.Models.Client", "Client") + .WithMany() + .HasForeignKey("ClientId"); + + b.Navigation("Client"); + }); + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b => { b.HasOne("SushiBarDatabaseImplement.Models.Client", "Client") diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Message.cs b/SushiBar/SushiBarDatabaseImplement/Models/Message.cs index 8f70c2e..b942e3e 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Message.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Message.cs @@ -18,6 +18,8 @@ public class Message : IMessageInfoModel public string Subject { get; private set; } = string.Empty; [Required] public string Body { get; private set; } = string.Empty; + public bool IsRead { get; private set; } + public string? Reply { get; private set; } public virtual Client Client { get; set; } @@ -38,6 +40,16 @@ public class Message : IMessageInfoModel }; } + public void Update(MessageInfoBindingModel model) + { + if (model == null) + { + return; + } + Reply = model.Reply; + IsRead = model.IsRead; + } + public MessageInfoViewModel GetViewModel => new() { Body = Body, diff --git a/SushiBar/SushiBarFileImplement/Implements/MessageInfoStorage.cs b/SushiBar/SushiBarFileImplement/Implements/MessageInfoStorage.cs index a108445..fa9f829 100644 --- a/SushiBar/SushiBarFileImplement/Implements/MessageInfoStorage.cs +++ b/SushiBar/SushiBarFileImplement/Implements/MessageInfoStorage.cs @@ -50,4 +50,9 @@ public class MessageInfoStorage : IMessageInfoStorage source.SaveMessages(); return newMessage.GetViewModel; } + + public MessageInfoViewModel? Update(MessageInfoBindingModel model) + { + throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/SushiBar/SushiBarFileImplement/Models/Message.cs b/SushiBar/SushiBarFileImplement/Models/Message.cs index 3f2314f..e7ea397 100644 --- a/SushiBar/SushiBarFileImplement/Models/Message.cs +++ b/SushiBar/SushiBarFileImplement/Models/Message.cs @@ -66,4 +66,8 @@ public class Message : IMessageInfoModel new XAttribute("SenderName", SenderName), new XAttribute("DateDelivery", DateDelivery) ); + + public bool IsRead => throw new NotImplementedException(); + + public string? Reply => throw new NotImplementedException(); } \ No newline at end of file diff --git a/SushiBar/SushiBarModels/Models/IMessageInfoModel.cs b/SushiBar/SushiBarModels/Models/IMessageInfoModel.cs index 360e36d..f362bd1 100644 --- a/SushiBar/SushiBarModels/Models/IMessageInfoModel.cs +++ b/SushiBar/SushiBarModels/Models/IMessageInfoModel.cs @@ -8,4 +8,6 @@ public interface IMessageInfoModel DateTime DateDelivery { get; } string Subject { get; } string Body { get; } + bool IsRead { get; } + string? Reply { get; } } \ No newline at end of file diff --git a/SushiBar/SushiBarRestApi/Controllers/ClientController.cs b/SushiBar/SushiBarRestApi/Controllers/ClientController.cs index 41dba3f..5048a73 100644 --- a/SushiBar/SushiBarRestApi/Controllers/ClientController.cs +++ b/SushiBar/SushiBarRestApi/Controllers/ClientController.cs @@ -69,13 +69,15 @@ public class ClientController : Controller } [HttpGet] - public List? GetMessages(int clientId) + public List? GetMessages(int clientId, int page) { try { return _mailLogic.ReadList(new MessageInfoSearchModel { - ClientId = clientId + ClientId = clientId, + Page = page, + PageSize = 3 }); } catch (Exception ex) diff --git a/SushiBar/SushibarListImplement/Implements/MessageInfoStorage.cs b/SushiBar/SushibarListImplement/Implements/MessageInfoStorage.cs index 27f4802..c6f4a26 100644 --- a/SushiBar/SushibarListImplement/Implements/MessageInfoStorage.cs +++ b/SushiBar/SushibarListImplement/Implements/MessageInfoStorage.cs @@ -59,4 +59,9 @@ public class MessageInfoStorage : IMessageInfoStorage _source.Messages.Add(newMessage); return newMessage.GetViewModel; } + + public MessageInfoViewModel? Update(MessageInfoBindingModel model) + { + throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/SushiBar/SushibarListImplement/Models/Message.cs b/SushiBar/SushibarListImplement/Models/Message.cs index 2f2ce2d..3e611b8 100644 --- a/SushiBar/SushibarListImplement/Models/Message.cs +++ b/SushiBar/SushibarListImplement/Models/Message.cs @@ -39,4 +39,8 @@ public class Message : IMessageInfoModel ClientId = ClientId, MessageId = MessageId }; + + public bool IsRead => throw new NotImplementedException(); + + public string? Reply => throw new NotImplementedException(); } \ No newline at end of file