начало 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,7 +27,28 @@ namespace IceCreamBusinessLogic.BusinessLogics
return true;
}
public List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model)
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)
{
_logger.LogInformation("ReadList. MessageId:{MessageId}.ClientId:{ClientId} ", model?.MessageId, model?.ClientId);
var list = (model == null) ? _messageInfoStorage.GetFullList() : _messageInfoStorage.GetFilteredList(model);

View File

@ -25,21 +25,17 @@ namespace IceCreamBusinessLogic.BusinessLogics
private readonly IShopLogic _shopLogic;
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;
_clientLogic = clientLogic;
}
_shopLogic = shopLogic;
_iceCreamStorage = iceCreamStorage;
}
public bool CreateOrder(OrderBindingModel model)
public bool CreateOrder(OrderBindingModel model)
{
CheckModel(model);
if(model.Status != OrderStatus.Неизвестен)
@ -111,149 +107,132 @@ namespace IceCreamBusinessLogic.BusinessLogics
_logger.LogInformation("Order. OrderID:{Id}.Sum:{ Sum}. DocumentId: { DocumentId}", model.Id, model.Sum, model.IceCreamId);
}
public bool SetNewStatus(OrderBindingModel rawModel, OrderStatus newStatus)
{
var viewModel = _orderStorage.GetElement(new OrderSearchModel
{
Id = rawModel.Id
});
public bool SetNewStatus(OrderBindingModel rawModel, OrderStatus newStatus)
{
var viewModel = _orderStorage.GetElement(new OrderSearchModel
{
Id = rawModel.Id
});
if (viewModel == null)
{
_logger.LogWarning("Order model not found");
return false;
}
if (viewModel == null)
{
_logger.LogWarning("Order model not found");
return false;
}
OrderBindingModel model = new OrderBindingModel
{
Id = viewModel.Id,
IceCreamId = viewModel.IceCreamId,
Status = viewModel.Status,
DateCreate = viewModel.DateCreate,
DateImplement = viewModel.DateImplement,
Count = viewModel.Count,
Sum = viewModel.Sum,
ImplementerId = viewModel.ImplementerId
};
if (rawModel.ImplementerId.HasValue)
{
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;
OrderBindingModel model = new OrderBindingModel
{
Id = viewModel.Id,
IceCreamId = viewModel.IceCreamId,
Status = viewModel.Status,
DateCreate = viewModel.DateCreate,
DateImplement = viewModel.DateImplement,
Count = viewModel.Count,
Sum = viewModel.Sum,
ImplementerId = viewModel.ImplementerId
};
if (rawModel.ImplementerId.HasValue)
{
model.ImplementerId = rawModel.ImplementerId;
}
CheckModel(model);
if (model.Status + 1 != newStatus && model.Status != OrderStatus.Ожидается)
{
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
return false;
}
if (newStatus == OrderStatus.Готов)
{
var icecream = _iceCreamStorage.GetElement(new IceCreamSearchModel() { Id = model.IceCreamId });
if (icecream == null)
{
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Icecream not found.");
return false;
}
if (CheckSupply(icecream, model.Count) == false)
{
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Shop supply error.");
model.Status = OrderStatus.Ожидается;
_orderStorage.Update(model);
return false;
}
}
model.Status = newStatus;
if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now;
var result = _orderStorage.Update(model);
if (result == null)
{
model.Status--;
_logger.LogWarning("Update operation failed");
return false;
}
SendOrderStatusMail(result.ClientId, $"Изменен статус заказа #{result.Id}", $"Заказ #{model.Id} изменен статус на {result.Status}");
SendOrderStatusMail(result.ClientId, $"Изменен статус заказа #{result.Id}", $"Заказ #{result.Id} изменен статус на {result.Status}");
return true;
}
CheckModel(model);
if (model.Status + 1 != newStatus && model.Status != OrderStatus.Ожидается)
{
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
return false;
}
public bool CheckSupply(IIceCreamModel model, int count)
{
if (count <= 0)
{
_logger.LogWarning("Check then supply operation error. icecream count < 0.");
return false;
}
if (newStatus == OrderStatus.Готов)
{
var icecream = _iceCreamStorage.GetElement(new IceCreamSearchModel() { Id = model.IceCreamId });
if (icecream == null)
{
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Icecream not found.");
return false;
}
if (CheckSupply(icecream, model.Count) == false)
{
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Shop supply error.");
model.Status = OrderStatus.Ожидается;
_orderStorage.Update(model);
return false;
}
}
int freeSpace = 0;
foreach (var shop in _shopStorage.GetFullList())
{
freeSpace += shop.IceCreamMaxCount;
foreach (var icecream in shop.ShopIceCreams)
{
freeSpace -= icecream.Value.Item2;
}
}
model.Status = newStatus;
if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now;
if (_orderStorage.Update(model) == null)
{
model.Status--;
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
if (freeSpace - count < 0)
{
_logger.LogWarning("Check then supply operation error. There's no place for new icecreams in shops.");
return false;
}
public bool CheckSupply(IIceCreamModel model, int count)
{
if (count <= 0)
{
_logger.LogWarning("Check then supply operation error. icecream count < 0.");
return false;
}
int freeSpace = 0;
foreach (var shop in _shopStorage.GetFullList())
{
freeSpace += shop.IceCreamMaxCount;
foreach (var icecream in shop.ShopIceCreams)
{
freeSpace -= icecream.Value.Item2;
}
}
if (freeSpace - count < 0)
{
_logger.LogWarning("Check then supply operation error. There's no place for new icecreams in shops.");
return false;
}
foreach (var shop in _shopStorage.GetFullList())
{
freeSpace = shop.IceCreamMaxCount;
foreach (var icecream in shop.ShopIceCreams)
{
freeSpace -= icecream.Value.Item2;
}
if (freeSpace == 0)
{
continue;
}
if (freeSpace - count >= 0)
{
if (_shopLogic.SupplyIceCreams(new() { Id = shop.Id }, model, count)) count = 0;
else
{
_logger.LogWarning("Supply error");
return false;
}
}
if (freeSpace - count < 0)
{
if (_shopLogic.SupplyIceCreams(new() { Id = shop.Id }, model, freeSpace)) count -= freeSpace;
else
{
_logger.LogWarning("Supply error");
return false;
}
}
if (count <= 0)
{
return true;
}
}
return false;
}
foreach (var shop in _shopStorage.GetFullList())
{
freeSpace = shop.IceCreamMaxCount;
foreach (var icecream in shop.ShopIceCreams)
{
freeSpace -= icecream.Value.Item2;
}
if (freeSpace == 0)
{
continue;
}
if (freeSpace - count >= 0)
{
if (_shopLogic.SupplyIceCreams(new() { Id = shop.Id }, model, count)) count = 0;
else
{
_logger.LogWarning("Supply error");
return false;
}
}
if (freeSpace - count < 0)
{
if (_shopLogic.SupplyIceCreams(new() { Id = shop.Id }, model, freeSpace)) count -= freeSpace;
else
{
_logger.LogWarning("Supply error");
return false;
}
}
if (count <= 0)
{
return true;
}
}
return false;
}
public OrderViewModel? ReadElement(OrderSearchModel model)
{

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>
private void InitializeComponent()
{
labelInfoPages = new Label();
buttonNextPage = new Button();
buttonPrevPage = new Button();
dataGridView = new DataGridView();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
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.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Dock = DockStyle.Fill;
dataGridView.Location = new Point(0, 0);
dataGridView.Location = new Point(12, 12);
dataGridView.Name = "dataGridView";
dataGridView.RowTemplate.Height = 25;
dataGridView.Size = new Size(800, 450);
dataGridView.TabIndex = 1;
dataGridView.Size = new Size(872, 463);
dataGridView.TabIndex = 4;
dataGridView.RowHeaderMouseClick += dataGridView_RowHeaderMouseClick;
//
// FormViewMail
//
AutoScaleDimensions = new SizeF(7F, 15F);
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);
Name = "FormViewMail";
Text = "Письма";
@ -57,6 +96,9 @@
#endregion
private Label labelInfoPages;
private Button buttonNextPage;
private Button buttonPrevPage;
private DataGridView dataGridView;
}
}

View File

@ -1,4 +1,6 @@
using IceCreamShopContracts.BusinessLogicsContracts;
using IceCreamShop;
using IceCreamShopContracts.BusinessLogicsContracts;
using IceCreamShopContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace IceCreamShopView
@ -7,19 +9,31 @@ namespace IceCreamShopView
{
private readonly ILogger _logger;
private readonly IMessageInfoLogic _logic;
private int currentPage = 1;
public int pageSize = 5;
public FormViewMail(ILogger<FormViewMail> logger, IMessageInfoLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
buttonPrevPage.Enabled = false;
}
private void FormViewMail_Load(object sender, EventArgs e)
{
MailLoad();
}
private bool MailLoad()
{
try
{
var list = _logic.ReadList(null);
var list = _logic.ReadList(new()
{
Page = currentPage,
PageSize = pageSize,
});
if (list != null)
{
dataGridView.DataSource = list;
@ -28,12 +42,56 @@ namespace IceCreamShopView
dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка списка писем");
labelInfoPages.Text = $"{currentPage} страница";
return true;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки писем");
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 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);
bool Create(MessageInfoBindingModel model);
}
bool Update(MessageInfoBindingModel model);
MessageInfoViewModel? ReadElement(MessageInfoSearchModel model);
}
}

View File

@ -5,5 +5,9 @@
public int? ClientId { 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? Insert(MessageInfoBindingModel model);
}
MessageInfoViewModel? Update(MessageInfoBindingModel model);
}
}

View File

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

View File

@ -19,16 +19,20 @@ namespace IceCreamShopDatabaseImplement.Implements
return null;
}
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
{
using var context = new IceCreamShopDatabase();
return context.Messages
.Where(x => x.ClientId == model.ClientId)
.Select(x => x.GetViewModel)
.ToList();
}
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
{
using var context = new IceCreamShopDatabase();
var res = context.Messages
.Where(x => !model.ClientId.HasValue || x.ClientId == model.ClientId)
.Select(x => x.GetViewModel);
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()
{
using var context = new IceCreamShopDatabase();
return context.Messages
@ -48,5 +52,17 @@ namespace IceCreamShopDatabaseImplement.Implements
context.SaveChanges();
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,8 +320,9 @@ namespace IceCreamShopDatabaseImplement.Migrations
b.Navigation("Client");
b.Navigation("IceCream");
});
modelBuilder.Entity("IceCreamShopDatabaseImplement.Models.ShopIcecream", b =>
modelBuilder.Entity("IceCreamShopDatabaseImplement.Models.ShopIcecream", b =>
{
b.HasOne("IceCreamShopDatabaseImplement.Models.IceCream", "IceCream")
.WithMany()

View File

@ -22,7 +22,11 @@ namespace IceCreamShopDatabaseImplement.Models
public Client? Client { get; private set; }
public static MessageInfo? Create(MessageInfoBindingModel model)
public bool HasRead { get; private set; }
public string? Reply { get; private set; }
public static MessageInfo? Create(MessageInfoBindingModel model)
{
if (model == null)
{
@ -30,23 +34,37 @@ namespace IceCreamShopDatabaseImplement.Models
}
return new()
{
Body = model.Body,
Subject = model.Subject,
ClientId = model.ClientId,
MessageId = model.MessageId,
SenderName = model.SenderName,
DateDelivery = model.DateDelivery,
};
Body = model.Body,
Reply = model.Reply,
HasRead = model.HasRead,
Subject = model.Subject,
ClientId = model.ClientId,
MessageId = model.MessageId,
SenderName = model.SenderName,
DateDelivery = model.DateDelivery,
};
}
public MessageInfoViewModel GetViewModel => new()
public void Update(MessageInfoBindingModel model)
{
if (model == null)
{
return;
}
Reply = model.Reply;
HasRead = model.HasRead;
}
public MessageInfoViewModel GetViewModel => new()
{
Body = Body,
Subject = Subject,
ClientId = ClientId,
MessageId = MessageId,
SenderName = SenderName,
DateDelivery = DateDelivery,
};
Body = Body,
Reply = Reply,
HasRead = HasRead,
Subject = Subject,
ClientId = ClientId,
MessageId = MessageId,
SenderName = SenderName,
DateDelivery = DateDelivery,
};
}
}

View File

@ -25,11 +25,15 @@ namespace IceCreamShopFileImplement.Implements
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
{
return _source.Messages
.Where(x => x.ClientId == model.ClientId)
.Select(x => x.GetViewModel)
.ToList();
}
var res = _source.Messages
.Where(x => !model.ClientId.HasValue || x.ClientId == model.ClientId)
.Select(x => x.GetViewModel);
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()
{
@ -49,5 +53,16 @@ namespace IceCreamShopFileImplement.Implements
_source.SaveMessages();
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,7 +19,11 @@ namespace IceCreamShopFileImplement.Models
public string Body { get; private set; } = string.Empty;
public static MessageInfo? Create(MessageInfoBindingModel model)
public bool HasRead { get; private set; }
public string? Reply { get; private set; }
public static MessageInfo? Create(MessageInfoBindingModel model)
{
if (model == null)
{
@ -27,13 +31,15 @@ namespace IceCreamShopFileImplement.Models
}
return new()
{
Body = model.Body,
Subject = model.Subject,
ClientId = model.ClientId,
MessageId = model.MessageId,
SenderName = model.SenderName,
DateDelivery = model.DateDelivery,
};
Body = model.Body,
Reply = model.Reply,
HasRead = model.HasRead,
Subject = model.Subject,
ClientId = model.ClientId,
MessageId = model.MessageId,
SenderName = model.SenderName,
DateDelivery = model.DateDelivery,
};
}
public static MessageInfo? Create(XElement element)
@ -44,32 +50,48 @@ namespace IceCreamShopFileImplement.Models
}
return new()
{
Body = element.Attribute("Body")!.Value,
Subject = element.Attribute("Subject")!.Value,
ClientId = Convert.ToInt32(element.Attribute("ClientId")!.Value),
MessageId = element.Attribute("MessageId")!.Value,
SenderName = element.Attribute("SenderName")!.Value,
DateDelivery = Convert.ToDateTime(element.Attribute("DateDelivery")!.Value),
};
Body = element.Attribute("Body")!.Value,
Reply = element.Attribute("Reply")!.Value,
HasRead = Convert.ToBoolean(element.Attribute("HasRead")!.Value),
Subject = element.Attribute("Subject")!.Value,
ClientId = Convert.ToInt32(element.Attribute("ClientId")!.Value),
MessageId = element.Attribute("MessageId")!.Value,
SenderName = element.Attribute("SenderName")!.Value,
DateDelivery = Convert.ToDateTime(element.Attribute("DateDelivery")!.Value),
};
}
public MessageInfoViewModel GetViewModel => new()
{
Body = Body,
Subject = Subject,
ClientId = ClientId,
MessageId = MessageId,
SenderName = SenderName,
DateDelivery = DateDelivery,
};
public void Update(MessageInfoBindingModel model)
{
if (model == null)
{
return;
}
Reply = model.Reply;
HasRead = model.HasRead;
}
public XElement GetXElement => new("MessageInfo",
new XAttribute("Body", Body),
new XAttribute("Subject", Subject),
new XAttribute("ClientId", ClientId),
new XAttribute("MessageId", MessageId),
new XAttribute("SenderName", SenderName),
new XAttribute("DateDelivery", DateDelivery)
);
}
public MessageInfoViewModel GetViewModel => new()
{
Body = Body,
Reply = Reply,
HasRead = HasRead,
Subject = Subject,
ClientId = ClientId,
MessageId = MessageId,
SenderName = SenderName,
DateDelivery = DateDelivery,
};
public XElement GetXElement => new("MessageInfo",
new XAttribute("Body", Body),
new XAttribute("Reply", Reply),
new XAttribute("HasRead", HasRead),
new XAttribute("Subject", Subject),
new XAttribute("ClientId", ClientId),
new XAttribute("MessageId", MessageId),
new XAttribute("SenderName", SenderName),
new XAttribute("DateDelivery", DateDelivery)
);
}
}

View File

@ -1,12 +1,13 @@
using IceCreamShopContracts.BindingModels;
using IceCreamShopContracts.SearchModels;
using IceCreamShopContracts.StoragesContracts;
using IceCreamShopContracts.ViewModels;
using IceCreamShopListImplement.Models;
namespace IceCreamShopListImplement.Implements
{
public class MessageInfoStorage
{
{
private readonly DataListSingleton _source;
public MessageInfoStorage()
{