начало 7 усложненки

This commit is contained in:
Ino 2023-05-03 14:05:03 +04:00
parent e81bb5f092
commit 4cf40944f5
18 changed files with 695 additions and 220 deletions

View File

@ -27,6 +27,27 @@ namespace IceCreamBusinessLogic.BusinessLogics
return true; return true;
} }
public MessageInfoViewModel? ReadElement(MessageInfoSearchModel model)
{
var res = _messageInfoStorage.GetElement(model);
if (res == null)
{
_logger.LogWarning("Read element operation failed");
return null;
}
return res;
}
public bool Update(MessageInfoBindingModel model)
{
if (_messageInfoStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model) public List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model)
{ {
_logger.LogInformation("ReadList. MessageId:{MessageId}.ClientId:{ClientId} ", model?.MessageId, model?.ClientId); _logger.LogInformation("ReadList. MessageId:{MessageId}.ClientId:{ClientId} ", model?.MessageId, model?.ClientId);

View File

@ -25,19 +25,15 @@ namespace IceCreamBusinessLogic.BusinessLogics
private readonly IShopLogic _shopLogic; private readonly IShopLogic _shopLogic;
private readonly IIceCreamStorage _iceCreamStorage; private readonly IIceCreamStorage _iceCreamStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, AbstractMailWorker mailWorker, IClientLogic clientLogic) public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IIceCreamStorage icecreamStorage, IShopLogic shopLogic, IClientLogic clientLogic, AbstractMailWorker mailWorker)
{ {
public OrderLogic(IOrderStorage orderStorage, IShopStorage shopStorage, IShopLogic shopLogic, IIceCreamStorage iceCreamStorage, ILogger<OrderLogic> logger)
{
_orderStorage = orderStorage;
_shopStorage = shopStorage;
_logger = logger; _logger = logger;
_shopLogic = shopLogic;
_iceCreamStorage = icecreamStorage;
_orderStorage = orderStorage;
_mailWorker = mailWorker; _mailWorker = mailWorker;
_clientLogic = clientLogic; _clientLogic = clientLogic;
} }
_shopLogic = shopLogic;
_iceCreamStorage = iceCreamStorage;
}
public bool CreateOrder(OrderBindingModel model) public bool CreateOrder(OrderBindingModel model)
{ {
@ -139,25 +135,6 @@ namespace IceCreamBusinessLogic.BusinessLogics
{ {
model.ImplementerId = rawModel.ImplementerId; model.ImplementerId = rawModel.ImplementerId;
} }
model.Status = orderStatus;
model.DateCreate = vmodel.DateCreate;
if (model.DateImplement == null)
model.DateImplement = vmodel.DateImplement;
if (vmodel.ImplementerId.HasValue)
model.ImplementerId = vmodel.ImplementerId;
model.IceCreamId = vmodel.IceCreamId;
model.Sum = vmodel.Sum;
model.Count = vmodel.Count;
var result = _orderStorage.Update(model);
if (result == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
SendOrderStatusMail(result.ClientId, $"Изменен статус заказа #{result.Id}", $"Заказ #{model.Id} изменен статус на {result.Status}");
return true;
}
CheckModel(model); CheckModel(model);
if (model.Status + 1 != newStatus && model.Status != OrderStatus.Ожидается) if (model.Status + 1 != newStatus && model.Status != OrderStatus.Ожидается)
@ -185,12 +162,14 @@ namespace IceCreamBusinessLogic.BusinessLogics
model.Status = newStatus; model.Status = newStatus;
if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now;
if (_orderStorage.Update(model) == null) var result = _orderStorage.Update(model);
if (result == null)
{ {
model.Status--; model.Status--;
_logger.LogWarning("Update operation failed"); _logger.LogWarning("Update operation failed");
return false; return false;
} }
SendOrderStatusMail(result.ClientId, $"Изменен статус заказа #{result.Id}", $"Заказ #{result.Id} изменен статус на {result.Status}");
return true; return true;
} }

View File

@ -0,0 +1,149 @@
namespace IceCreamShopView
{
partial class FormReplyMail
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
textBoxReply = new TextBox();
textBoxMainText = new TextBox();
textBoxTitle = new TextBox();
labelReply = new Label();
labelMainText = new Label();
labelTitle = new Label();
buttonCancel = new Button();
buttonSave = new Button();
SuspendLayout();
//
// textBoxReply
//
textBoxReply.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
textBoxReply.Location = new Point(137, 114);
textBoxReply.Multiline = true;
textBoxReply.Name = "textBoxReply";
textBoxReply.Size = new Size(494, 182);
textBoxReply.TabIndex = 15;
//
// textBoxMainText
//
textBoxMainText.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
textBoxMainText.Location = new Point(137, 32);
textBoxMainText.Multiline = true;
textBoxMainText.Name = "textBoxMainText";
textBoxMainText.ReadOnly = true;
textBoxMainText.Size = new Size(494, 76);
textBoxMainText.TabIndex = 14;
//
// textBoxTitle
//
textBoxTitle.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
textBoxTitle.Location = new Point(137, 2);
textBoxTitle.Name = "textBoxTitle";
textBoxTitle.ReadOnly = true;
textBoxTitle.Size = new Size(494, 23);
textBoxTitle.TabIndex = 13;
//
// labelReply
//
labelReply.Location = new Point(14, 114);
labelReply.Name = "labelReply";
labelReply.Size = new Size(117, 31);
labelReply.TabIndex = 12;
labelReply.Text = "Ответ на письмо:";
labelReply.TextAlign = ContentAlignment.TopRight;
//
// labelMainText
//
labelMainText.Location = new Point(14, 35);
labelMainText.Name = "labelMainText";
labelMainText.Size = new Size(117, 23);
labelMainText.TabIndex = 11;
labelMainText.Text = "Текст письма:";
labelMainText.TextAlign = ContentAlignment.TopRight;
//
// labelTitle
//
labelTitle.Location = new Point(14, 6);
labelTitle.Name = "labelTitle";
labelTitle.Size = new Size(117, 23);
labelTitle.TabIndex = 10;
labelTitle.Text = "Заголовок письма:";
labelTitle.TextAlign = ContentAlignment.TopRight;
//
// buttonCancel
//
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Location = new Point(175, 302);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(117, 30);
buttonCancel.TabIndex = 9;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// buttonSave
//
buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonSave.Location = new Point(298, 302);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(117, 30);
buttonSave.TabIndex = 8;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += ButtonSave_Click;
//
// FormReplyMail
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(636, 344);
Controls.Add(textBoxReply);
Controls.Add(textBoxMainText);
Controls.Add(textBoxTitle);
Controls.Add(labelReply);
Controls.Add(labelMainText);
Controls.Add(labelTitle);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Name = "FormReplyMail";
Text = "Ответ на письмо";
Load += FormReplyMail_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
private TextBox textBoxReply;
private TextBox textBoxMainText;
private TextBox textBoxTitle;
private Label labelReply;
private Label labelMainText;
private Label labelTitle;
private Button buttonCancel;
private Button buttonSave;
}
}

View File

@ -0,0 +1,73 @@
using IceCreamBusinessLogic.MailWorker;
using IceCreamShopContracts.BusinessLogicsContracts;
using IceCreamShopContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace IceCreamShopView
{
public partial class FormReplyMail : Form
{
private readonly ILogger _logger;
private readonly AbstractMailWorker _mailWorker;
private readonly IMessageInfoLogic _logic;
private MessageInfoViewModel _message;
public string MessageId { get; set; } = string.Empty;
public FormReplyMail(ILogger<FormReplyMail> 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()
{
MailAddress = _message.SenderName,
Subject = _message.Subject,
Text = textBoxReply.Text,
});
_logic.Update(new()
{
MessageId = MessageId,
Reply = textBoxReply.Text,
HasRead = true,
});
MessageBox.Show("Успешно отправлено письмо", "Отправка письма", MessageBoxButtons.OK);
DialogResult = DialogResult.OK;
Close();
}
private void FormReplyMail_Load(object sender, EventArgs e)
{
try
{
_message = _logic.ReadElement(new() { MessageId = MessageId });
if (_message == null)
throw new ArgumentNullException("Письма с таким id не существует");
Text += $"для {_message.SenderName}";
textBoxTitle.Text = _message.Subject;
textBoxMainText.Text = _message.Body;
if (_message.HasRead is false)
{
_logic.Update(new() { MessageId = MessageId, HasRead = true, Reply = _message.Reply });
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения собщения");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -28,25 +28,64 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
labelInfoPages = new Label();
buttonNextPage = new Button();
buttonPrevPage = new Button();
dataGridView = new DataGridView(); dataGridView = new DataGridView();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout(); SuspendLayout();
// //
// labelInfoPages
//
labelInfoPages.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
labelInfoPages.Location = new Point(99, 485);
labelInfoPages.Name = "labelInfoPages";
labelInfoPages.Size = new Size(104, 19);
labelInfoPages.TabIndex = 7;
labelInfoPages.Text = "{0} страница";
labelInfoPages.TextAlign = ContentAlignment.MiddleCenter;
//
// buttonNextPage
//
buttonNextPage.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonNextPage.Location = new Point(209, 481);
buttonNextPage.Name = "buttonNextPage";
buttonNextPage.Size = new Size(75, 23);
buttonNextPage.TabIndex = 6;
buttonNextPage.Text = ">>>";
buttonNextPage.UseVisualStyleBackColor = true;
buttonNextPage.Click += ButtonNextPage_Click;
//
// buttonPrevPage
//
buttonPrevPage.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonPrevPage.Location = new Point(18, 481);
buttonPrevPage.Name = "buttonPrevPage";
buttonPrevPage.Size = new Size(75, 23);
buttonPrevPage.TabIndex = 5;
buttonPrevPage.Text = "<<<";
buttonPrevPage.UseVisualStyleBackColor = true;
buttonPrevPage.Click += ButtonPrevPage_Click;
//
// dataGridView // dataGridView
// //
dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Dock = DockStyle.Fill; dataGridView.Location = new Point(12, 12);
dataGridView.Location = new Point(0, 0);
dataGridView.Name = "dataGridView"; dataGridView.Name = "dataGridView";
dataGridView.RowTemplate.Height = 25; dataGridView.RowTemplate.Height = 25;
dataGridView.Size = new Size(800, 450); dataGridView.Size = new Size(872, 463);
dataGridView.TabIndex = 1; dataGridView.TabIndex = 4;
dataGridView.RowHeaderMouseClick += dataGridView_RowHeaderMouseClick;
// //
// FormViewMail // FormViewMail
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450); ClientSize = new Size(896, 513);
Controls.Add(labelInfoPages);
Controls.Add(buttonNextPage);
Controls.Add(buttonPrevPage);
Controls.Add(dataGridView); Controls.Add(dataGridView);
Name = "FormViewMail"; Name = "FormViewMail";
Text = "Письма"; Text = "Письма";
@ -57,6 +96,9 @@
#endregion #endregion
private Label labelInfoPages;
private Button buttonNextPage;
private Button buttonPrevPage;
private DataGridView dataGridView; private DataGridView dataGridView;
} }
} }

View File

@ -1,4 +1,6 @@
using IceCreamShopContracts.BusinessLogicsContracts; using IceCreamShop;
using IceCreamShopContracts.BusinessLogicsContracts;
using IceCreamShopContracts.ViewModels;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace IceCreamShopView namespace IceCreamShopView
@ -7,19 +9,31 @@ namespace IceCreamShopView
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IMessageInfoLogic _logic; private readonly IMessageInfoLogic _logic;
private int currentPage = 1;
public int pageSize = 5;
public FormViewMail(ILogger<FormViewMail> logger, IMessageInfoLogic logic) public FormViewMail(ILogger<FormViewMail> logger, IMessageInfoLogic logic)
{ {
InitializeComponent(); InitializeComponent();
_logger = logger; _logger = logger;
_logic = logic; _logic = logic;
buttonPrevPage.Enabled = false;
} }
private void FormViewMail_Load(object sender, EventArgs e) private void FormViewMail_Load(object sender, EventArgs e)
{
MailLoad();
}
private bool MailLoad()
{ {
try try
{ {
var list = _logic.ReadList(null); var list = _logic.ReadList(new()
{
Page = currentPage,
PageSize = pageSize,
});
if (list != null) if (list != null)
{ {
dataGridView.DataSource = list; dataGridView.DataSource = list;
@ -28,12 +42,56 @@ namespace IceCreamShopView
dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
} }
_logger.LogInformation("Загрузка списка писем"); _logger.LogInformation("Загрузка списка писем");
labelInfoPages.Text = $"{currentPage} страница";
return true;
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка загрузки писем"); _logger.LogError(ex, "Ошибка загрузки писем");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error); MessageBoxIcon.Error);
return false;
}
}
private void ButtonPrevPage_Click(object sender, EventArgs e)
{
if (currentPage == 1)
{
_logger.LogWarning("Неккоректный номер страницы {page}", currentPage - 1);
return;
}
currentPage--;
if (MailLoad())
{
buttonNextPage.Enabled = true;
if (currentPage == 1)
buttonPrevPage.Enabled = false;
}
}
private void ButtonNextPage_Click(object sender, EventArgs e)
{
currentPage++;
if (!MailLoad() || ((List<MessageInfoViewModel>)dataGridView.DataSource).Count == 0)
{
_logger.LogWarning("Out of range messages");
currentPage--;
MailLoad();
buttonNextPage.Enabled = false;
}
else
buttonPrevPage.Enabled = true;
}
private void dataGridView_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReplyMail));
if (service is FormReplyMail form)
{
form.MessageId = (string)dataGridView.Rows[e.RowIndex].Cells["MessageId"].Value;
form.ShowDialog();
MailLoad();
} }
} }
} }

View File

@ -15,5 +15,9 @@ namespace IceCreamShopContracts.BindingModels
public string Body { get; set; } = string.Empty; public string Body { get; set; } = string.Empty;
public DateTime DateDelivery { get; set; } public DateTime DateDelivery { get; set; }
public bool HasRead { get; set; }
public string? Reply { get; set; }
} }
} }

View File

@ -9,5 +9,9 @@ namespace IceCreamShopContracts.BusinessLogicsContracts
List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model); List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model);
bool Create(MessageInfoBindingModel model); bool Create(MessageInfoBindingModel model);
bool Update(MessageInfoBindingModel model);
MessageInfoViewModel? ReadElement(MessageInfoSearchModel model);
} }
} }

View File

@ -5,5 +5,9 @@
public int? ClientId { get; set; } public int? ClientId { get; set; }
public string? MessageId { get; set; } public string? MessageId { get; set; }
public int? Page { get; set; }
public int? PageSize { get; set; }
} }
} }

View File

@ -13,5 +13,7 @@ namespace IceCreamShopContracts.StoragesContracts
MessageInfoViewModel? GetElement(MessageInfoSearchModel model); MessageInfoViewModel? GetElement(MessageInfoSearchModel model);
MessageInfoViewModel? Insert(MessageInfoBindingModel model); MessageInfoViewModel? Insert(MessageInfoBindingModel model);
MessageInfoViewModel? Update(MessageInfoBindingModel model);
} }
} }

View File

@ -20,5 +20,11 @@ namespace IceCreamShopContracts.ViewModels
[DisplayName("Текст")] [DisplayName("Текст")]
public string Body { get; set; } = string.Empty; public string Body { get; set; } = string.Empty;
[DisplayName("Прочитано")]
public bool HasRead { get; set; }
[DisplayName("Ответ")]
public string? Reply { get; set; }
} }
} }

View File

@ -22,10 +22,14 @@ namespace IceCreamShopDatabaseImplement.Implements
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model) public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
{ {
using var context = new IceCreamShopDatabase(); using var context = new IceCreamShopDatabase();
return context.Messages var res = context.Messages
.Where(x => x.ClientId == model.ClientId) .Where(x => !model.ClientId.HasValue || x.ClientId == model.ClientId)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel);
.ToList(); if (!(model.Page.HasValue && model.PageSize.HasValue))
{
return res.ToList();
}
return res.Skip((model.Page.Value - 1) * model.PageSize.Value).Take(model.PageSize.Value).ToList();
} }
public List<MessageInfoViewModel> GetFullList() public List<MessageInfoViewModel> GetFullList()
@ -48,5 +52,17 @@ namespace IceCreamShopDatabaseImplement.Implements
context.SaveChanges(); context.SaveChanges();
return newMessage.GetViewModel; return newMessage.GetViewModel;
} }
public MessageInfoViewModel? Update(MessageInfoBindingModel model)
{
using var context = new IceCreamShopDatabase();
var res = context.Messages.FirstOrDefault(x => x.MessageId.Equals(model.MessageId));
if (res != null)
{
res.Update(model);
context.SaveChanges();
}
return res?.GetViewModel;
}
} }
} }

View File

@ -320,6 +320,7 @@ namespace IceCreamShopDatabaseImplement.Migrations
b.Navigation("Client"); b.Navigation("Client");
b.Navigation("IceCream"); b.Navigation("IceCream");
});
modelBuilder.Entity("IceCreamShopDatabaseImplement.Models.ShopIcecream", b => modelBuilder.Entity("IceCreamShopDatabaseImplement.Models.ShopIcecream", b =>
{ {

View File

@ -22,6 +22,10 @@ namespace IceCreamShopDatabaseImplement.Models
public Client? Client { get; private set; } public Client? Client { get; private set; }
public bool HasRead { get; private set; }
public string? Reply { get; private set; }
public static MessageInfo? Create(MessageInfoBindingModel model) public static MessageInfo? Create(MessageInfoBindingModel model)
{ {
if (model == null) if (model == null)
@ -31,6 +35,8 @@ namespace IceCreamShopDatabaseImplement.Models
return new() return new()
{ {
Body = model.Body, Body = model.Body,
Reply = model.Reply,
HasRead = model.HasRead,
Subject = model.Subject, Subject = model.Subject,
ClientId = model.ClientId, ClientId = model.ClientId,
MessageId = model.MessageId, MessageId = model.MessageId,
@ -39,9 +45,21 @@ namespace IceCreamShopDatabaseImplement.Models
}; };
} }
public void Update(MessageInfoBindingModel model)
{
if (model == null)
{
return;
}
Reply = model.Reply;
HasRead = model.HasRead;
}
public MessageInfoViewModel GetViewModel => new() public MessageInfoViewModel GetViewModel => new()
{ {
Body = Body, Body = Body,
Reply = Reply,
HasRead = HasRead,
Subject = Subject, Subject = Subject,
ClientId = ClientId, ClientId = ClientId,
MessageId = MessageId, MessageId = MessageId,

View File

@ -25,10 +25,14 @@ namespace IceCreamShopFileImplement.Implements
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model) public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
{ {
return _source.Messages var res = _source.Messages
.Where(x => x.ClientId == model.ClientId) .Where(x => !model.ClientId.HasValue || x.ClientId == model.ClientId)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel);
.ToList(); if (!(model.Page.HasValue && model.PageSize.HasValue))
{
return res.ToList();
}
return res.Skip((model.Page.Value - 1) * model.PageSize.Value).Take(model.PageSize.Value).ToList();
} }
public List<MessageInfoViewModel> GetFullList() public List<MessageInfoViewModel> GetFullList()
@ -49,5 +53,16 @@ namespace IceCreamShopFileImplement.Implements
_source.SaveMessages(); _source.SaveMessages();
return newMessage.GetViewModel; return newMessage.GetViewModel;
} }
public MessageInfoViewModel? Update(MessageInfoBindingModel model)
{
var res = _source.Messages.FirstOrDefault(x => x.MessageId.Equals(model.MessageId));
if (res != null)
{
res.Update(model);
_source.SaveMessages();
}
return res?.GetViewModel;
}
} }
} }

View File

@ -19,6 +19,10 @@ namespace IceCreamShopFileImplement.Models
public string Body { get; private set; } = string.Empty; public string Body { get; private set; } = string.Empty;
public bool HasRead { get; private set; }
public string? Reply { get; private set; }
public static MessageInfo? Create(MessageInfoBindingModel model) public static MessageInfo? Create(MessageInfoBindingModel model)
{ {
if (model == null) if (model == null)
@ -28,6 +32,8 @@ namespace IceCreamShopFileImplement.Models
return new() return new()
{ {
Body = model.Body, Body = model.Body,
Reply = model.Reply,
HasRead = model.HasRead,
Subject = model.Subject, Subject = model.Subject,
ClientId = model.ClientId, ClientId = model.ClientId,
MessageId = model.MessageId, MessageId = model.MessageId,
@ -45,6 +51,8 @@ namespace IceCreamShopFileImplement.Models
return new() return new()
{ {
Body = element.Attribute("Body")!.Value, Body = element.Attribute("Body")!.Value,
Reply = element.Attribute("Reply")!.Value,
HasRead = Convert.ToBoolean(element.Attribute("HasRead")!.Value),
Subject = element.Attribute("Subject")!.Value, Subject = element.Attribute("Subject")!.Value,
ClientId = Convert.ToInt32(element.Attribute("ClientId")!.Value), ClientId = Convert.ToInt32(element.Attribute("ClientId")!.Value),
MessageId = element.Attribute("MessageId")!.Value, MessageId = element.Attribute("MessageId")!.Value,
@ -53,9 +61,21 @@ namespace IceCreamShopFileImplement.Models
}; };
} }
public void Update(MessageInfoBindingModel model)
{
if (model == null)
{
return;
}
Reply = model.Reply;
HasRead = model.HasRead;
}
public MessageInfoViewModel GetViewModel => new() public MessageInfoViewModel GetViewModel => new()
{ {
Body = Body, Body = Body,
Reply = Reply,
HasRead = HasRead,
Subject = Subject, Subject = Subject,
ClientId = ClientId, ClientId = ClientId,
MessageId = MessageId, MessageId = MessageId,
@ -65,6 +85,8 @@ namespace IceCreamShopFileImplement.Models
public XElement GetXElement => new("MessageInfo", public XElement GetXElement => new("MessageInfo",
new XAttribute("Body", Body), new XAttribute("Body", Body),
new XAttribute("Reply", Reply),
new XAttribute("HasRead", HasRead),
new XAttribute("Subject", Subject), new XAttribute("Subject", Subject),
new XAttribute("ClientId", ClientId), new XAttribute("ClientId", ClientId),
new XAttribute("MessageId", MessageId), new XAttribute("MessageId", MessageId),

View File

@ -1,5 +1,6 @@
using IceCreamShopContracts.BindingModels; using IceCreamShopContracts.BindingModels;
using IceCreamShopContracts.SearchModels; using IceCreamShopContracts.SearchModels;
using IceCreamShopContracts.StoragesContracts;
using IceCreamShopContracts.ViewModels; using IceCreamShopContracts.ViewModels;
using IceCreamShopListImplement.Models; using IceCreamShopListImplement.Models;