начало 7 усложненки
This commit is contained in:
parent
e81bb5f092
commit
4cf40944f5
@ -27,7 +27,28 @@ namespace IceCreamBusinessLogic.BusinessLogics
|
|||||||
return true;
|
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);
|
_logger.LogInformation("ReadList. MessageId:{MessageId}.ClientId:{ClientId} ", model?.MessageId, model?.ClientId);
|
||||||
var list = (model == null) ? _messageInfoStorage.GetFullList() : _messageInfoStorage.GetFilteredList(model);
|
var list = (model == null) ? _messageInfoStorage.GetFullList() : _messageInfoStorage.GetFilteredList(model);
|
||||||
|
@ -25,21 +25,17 @@ 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)
|
_logger = logger;
|
||||||
{
|
_shopLogic = shopLogic;
|
||||||
_orderStorage = orderStorage;
|
_iceCreamStorage = icecreamStorage;
|
||||||
_shopStorage = shopStorage;
|
_orderStorage = orderStorage;
|
||||||
_logger = logger;
|
|
||||||
_mailWorker = mailWorker;
|
_mailWorker = mailWorker;
|
||||||
_clientLogic = clientLogic;
|
_clientLogic = clientLogic;
|
||||||
}
|
}
|
||||||
_shopLogic = shopLogic;
|
|
||||||
_iceCreamStorage = iceCreamStorage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool CreateOrder(OrderBindingModel model)
|
public bool CreateOrder(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
if(model.Status != OrderStatus.Неизвестен)
|
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);
|
_logger.LogInformation("Order. OrderID:{Id}.Sum:{ Sum}. DocumentId: { DocumentId}", model.Id, model.Sum, model.IceCreamId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool SetNewStatus(OrderBindingModel rawModel, OrderStatus newStatus)
|
public bool SetNewStatus(OrderBindingModel rawModel, OrderStatus newStatus)
|
||||||
{
|
{
|
||||||
var viewModel = _orderStorage.GetElement(new OrderSearchModel
|
var viewModel = _orderStorage.GetElement(new OrderSearchModel
|
||||||
{
|
{
|
||||||
Id = rawModel.Id
|
Id = rawModel.Id
|
||||||
});
|
});
|
||||||
|
|
||||||
if (viewModel == null)
|
if (viewModel == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Order model not found");
|
_logger.LogWarning("Order model not found");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
OrderBindingModel model = new OrderBindingModel
|
OrderBindingModel model = new OrderBindingModel
|
||||||
{
|
{
|
||||||
Id = viewModel.Id,
|
Id = viewModel.Id,
|
||||||
IceCreamId = viewModel.IceCreamId,
|
IceCreamId = viewModel.IceCreamId,
|
||||||
Status = viewModel.Status,
|
Status = viewModel.Status,
|
||||||
DateCreate = viewModel.DateCreate,
|
DateCreate = viewModel.DateCreate,
|
||||||
DateImplement = viewModel.DateImplement,
|
DateImplement = viewModel.DateImplement,
|
||||||
Count = viewModel.Count,
|
Count = viewModel.Count,
|
||||||
Sum = viewModel.Sum,
|
Sum = viewModel.Sum,
|
||||||
ImplementerId = viewModel.ImplementerId
|
ImplementerId = viewModel.ImplementerId
|
||||||
};
|
};
|
||||||
if (rawModel.ImplementerId.HasValue)
|
if (rawModel.ImplementerId.HasValue)
|
||||||
{
|
{
|
||||||
model.ImplementerId = rawModel.ImplementerId;
|
model.ImplementerId = rawModel.ImplementerId;
|
||||||
}
|
}
|
||||||
model.Status = orderStatus;
|
|
||||||
model.DateCreate = vmodel.DateCreate;
|
CheckModel(model);
|
||||||
if (model.DateImplement == null)
|
if (model.Status + 1 != newStatus && model.Status != OrderStatus.Ожидается)
|
||||||
model.DateImplement = vmodel.DateImplement;
|
{
|
||||||
if (vmodel.ImplementerId.HasValue)
|
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
|
||||||
model.ImplementerId = vmodel.ImplementerId;
|
return false;
|
||||||
model.IceCreamId = vmodel.IceCreamId;
|
}
|
||||||
model.Sum = vmodel.Sum;
|
|
||||||
model.Count = vmodel.Count;
|
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);
|
var result = _orderStorage.Update(model);
|
||||||
if (result == null)
|
if (result == null)
|
||||||
{
|
{
|
||||||
|
model.Status--;
|
||||||
_logger.LogWarning("Update operation failed");
|
_logger.LogWarning("Update operation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
SendOrderStatusMail(result.ClientId, $"Изменен статус заказа #{result.Id}", $"Заказ #{model.Id} изменен статус на {result.Status}");
|
SendOrderStatusMail(result.ClientId, $"Изменен статус заказа #{result.Id}", $"Заказ #{result.Id} изменен статус на {result.Status}");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CheckModel(model);
|
public bool CheckSupply(IIceCreamModel model, int count)
|
||||||
if (model.Status + 1 != newStatus && model.Status != OrderStatus.Ожидается)
|
{
|
||||||
{
|
if (count <= 0)
|
||||||
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
|
{
|
||||||
return false;
|
_logger.LogWarning("Check then supply operation error. icecream count < 0.");
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (newStatus == OrderStatus.Готов)
|
int freeSpace = 0;
|
||||||
{
|
foreach (var shop in _shopStorage.GetFullList())
|
||||||
var icecream = _iceCreamStorage.GetElement(new IceCreamSearchModel() { Id = model.IceCreamId });
|
{
|
||||||
if (icecream == null)
|
freeSpace += shop.IceCreamMaxCount;
|
||||||
{
|
foreach (var icecream in shop.ShopIceCreams)
|
||||||
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Icecream not found.");
|
{
|
||||||
return false;
|
freeSpace -= icecream.Value.Item2;
|
||||||
}
|
}
|
||||||
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 (freeSpace - count < 0)
|
||||||
if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now;
|
{
|
||||||
if (_orderStorage.Update(model) == null)
|
_logger.LogWarning("Check then supply operation error. There's no place for new icecreams in shops.");
|
||||||
{
|
return false;
|
||||||
model.Status--;
|
}
|
||||||
_logger.LogWarning("Update operation failed");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool CheckSupply(IIceCreamModel model, int count)
|
foreach (var shop in _shopStorage.GetFullList())
|
||||||
{
|
{
|
||||||
if (count <= 0)
|
freeSpace = shop.IceCreamMaxCount;
|
||||||
{
|
foreach (var icecream in shop.ShopIceCreams)
|
||||||
_logger.LogWarning("Check then supply operation error. icecream count < 0.");
|
{
|
||||||
return false;
|
freeSpace -= icecream.Value.Item2;
|
||||||
}
|
}
|
||||||
|
if (freeSpace == 0)
|
||||||
int freeSpace = 0;
|
{
|
||||||
foreach (var shop in _shopStorage.GetFullList())
|
continue;
|
||||||
{
|
}
|
||||||
freeSpace += shop.IceCreamMaxCount;
|
if (freeSpace - count >= 0)
|
||||||
foreach (var icecream in shop.ShopIceCreams)
|
{
|
||||||
{
|
if (_shopLogic.SupplyIceCreams(new() { Id = shop.Id }, model, count)) count = 0;
|
||||||
freeSpace -= icecream.Value.Item2;
|
else
|
||||||
}
|
{
|
||||||
}
|
_logger.LogWarning("Supply error");
|
||||||
|
return false;
|
||||||
if (freeSpace - count < 0)
|
}
|
||||||
{
|
}
|
||||||
_logger.LogWarning("Check then supply operation error. There's no place for new icecreams in shops.");
|
if (freeSpace - count < 0)
|
||||||
return false;
|
{
|
||||||
}
|
if (_shopLogic.SupplyIceCreams(new() { Id = shop.Id }, model, freeSpace)) count -= freeSpace;
|
||||||
|
else
|
||||||
foreach (var shop in _shopStorage.GetFullList())
|
{
|
||||||
{
|
_logger.LogWarning("Supply error");
|
||||||
freeSpace = shop.IceCreamMaxCount;
|
return false;
|
||||||
foreach (var icecream in shop.ShopIceCreams)
|
}
|
||||||
{
|
}
|
||||||
freeSpace -= icecream.Value.Item2;
|
if (count <= 0)
|
||||||
}
|
{
|
||||||
if (freeSpace == 0)
|
return true;
|
||||||
{
|
}
|
||||||
continue;
|
}
|
||||||
}
|
return false;
|
||||||
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)
|
public OrderViewModel? ReadElement(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
|
149
IceCreamShop/IceCreamShop/FormReplyMail.Designer.cs
generated
Normal file
149
IceCreamShop/IceCreamShop/FormReplyMail.Designer.cs
generated
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
73
IceCreamShop/IceCreamShop/FormReplyMail.cs
Normal file
73
IceCreamShop/IceCreamShop/FormReplyMail.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
IceCreamShop/IceCreamShop/FormReplyMail.resx
Normal file
60
IceCreamShop/IceCreamShop/FormReplyMail.resx
Normal 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>
|
52
IceCreamShop/IceCreamShop/FormViewMail.Designer.cs
generated
52
IceCreamShop/IceCreamShop/FormViewMail.Designer.cs
generated
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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; }
|
||||||
|
}
|
||||||
}
|
}
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
@ -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; }
|
||||||
|
}
|
||||||
}
|
}
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
@ -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; }
|
||||||
|
}
|
||||||
}
|
}
|
@ -19,16 +19,20 @@ namespace IceCreamShopDatabaseImplement.Implements
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
||||||
{
|
{
|
||||||
using var context = new IceCreamShopDatabase();
|
using var context = new IceCreamShopDatabase();
|
||||||
return context.Messages
|
return context.Messages
|
||||||
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -320,8 +320,9 @@ 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 =>
|
||||||
{
|
{
|
||||||
b.HasOne("IceCreamShopDatabaseImplement.Models.IceCream", "IceCream")
|
b.HasOne("IceCreamShopDatabaseImplement.Models.IceCream", "IceCream")
|
||||||
.WithMany()
|
.WithMany()
|
||||||
|
@ -22,7 +22,11 @@ namespace IceCreamShopDatabaseImplement.Models
|
|||||||
|
|
||||||
public Client? Client { get; private set; }
|
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)
|
if (model == null)
|
||||||
{
|
{
|
||||||
@ -30,23 +34,37 @@ namespace IceCreamShopDatabaseImplement.Models
|
|||||||
}
|
}
|
||||||
return new()
|
return new()
|
||||||
{
|
{
|
||||||
Body = model.Body,
|
Body = model.Body,
|
||||||
Subject = model.Subject,
|
Reply = model.Reply,
|
||||||
ClientId = model.ClientId,
|
HasRead = model.HasRead,
|
||||||
MessageId = model.MessageId,
|
Subject = model.Subject,
|
||||||
SenderName = model.SenderName,
|
ClientId = model.ClientId,
|
||||||
DateDelivery = model.DateDelivery,
|
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,
|
Body = Body,
|
||||||
Subject = Subject,
|
Reply = Reply,
|
||||||
ClientId = ClientId,
|
HasRead = HasRead,
|
||||||
MessageId = MessageId,
|
Subject = Subject,
|
||||||
SenderName = SenderName,
|
ClientId = ClientId,
|
||||||
DateDelivery = DateDelivery,
|
MessageId = MessageId,
|
||||||
};
|
SenderName = SenderName,
|
||||||
|
DateDelivery = DateDelivery,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,11 +25,15 @@ 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,11 @@ namespace IceCreamShopFileImplement.Models
|
|||||||
|
|
||||||
public string Body { get; private set; } = string.Empty;
|
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)
|
if (model == null)
|
||||||
{
|
{
|
||||||
@ -27,13 +31,15 @@ namespace IceCreamShopFileImplement.Models
|
|||||||
}
|
}
|
||||||
return new()
|
return new()
|
||||||
{
|
{
|
||||||
Body = model.Body,
|
Body = model.Body,
|
||||||
Subject = model.Subject,
|
Reply = model.Reply,
|
||||||
ClientId = model.ClientId,
|
HasRead = model.HasRead,
|
||||||
MessageId = model.MessageId,
|
Subject = model.Subject,
|
||||||
SenderName = model.SenderName,
|
ClientId = model.ClientId,
|
||||||
DateDelivery = model.DateDelivery,
|
MessageId = model.MessageId,
|
||||||
};
|
SenderName = model.SenderName,
|
||||||
|
DateDelivery = model.DateDelivery,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MessageInfo? Create(XElement element)
|
public static MessageInfo? Create(XElement element)
|
||||||
@ -44,32 +50,48 @@ namespace IceCreamShopFileImplement.Models
|
|||||||
}
|
}
|
||||||
return new()
|
return new()
|
||||||
{
|
{
|
||||||
Body = element.Attribute("Body")!.Value,
|
Body = element.Attribute("Body")!.Value,
|
||||||
Subject = element.Attribute("Subject")!.Value,
|
Reply = element.Attribute("Reply")!.Value,
|
||||||
ClientId = Convert.ToInt32(element.Attribute("ClientId")!.Value),
|
HasRead = Convert.ToBoolean(element.Attribute("HasRead")!.Value),
|
||||||
MessageId = element.Attribute("MessageId")!.Value,
|
Subject = element.Attribute("Subject")!.Value,
|
||||||
SenderName = element.Attribute("SenderName")!.Value,
|
ClientId = Convert.ToInt32(element.Attribute("ClientId")!.Value),
|
||||||
DateDelivery = Convert.ToDateTime(element.Attribute("DateDelivery")!.Value),
|
MessageId = element.Attribute("MessageId")!.Value,
|
||||||
};
|
SenderName = element.Attribute("SenderName")!.Value,
|
||||||
|
DateDelivery = Convert.ToDateTime(element.Attribute("DateDelivery")!.Value),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageInfoViewModel GetViewModel => new()
|
public void Update(MessageInfoBindingModel model)
|
||||||
{
|
{
|
||||||
Body = Body,
|
if (model == null)
|
||||||
Subject = Subject,
|
{
|
||||||
ClientId = ClientId,
|
return;
|
||||||
MessageId = MessageId,
|
}
|
||||||
SenderName = SenderName,
|
Reply = model.Reply;
|
||||||
DateDelivery = DateDelivery,
|
HasRead = model.HasRead;
|
||||||
};
|
}
|
||||||
|
|
||||||
public XElement GetXElement => new("MessageInfo",
|
public MessageInfoViewModel GetViewModel => new()
|
||||||
new XAttribute("Body", Body),
|
{
|
||||||
new XAttribute("Subject", Subject),
|
Body = Body,
|
||||||
new XAttribute("ClientId", ClientId),
|
Reply = Reply,
|
||||||
new XAttribute("MessageId", MessageId),
|
HasRead = HasRead,
|
||||||
new XAttribute("SenderName", SenderName),
|
Subject = Subject,
|
||||||
new XAttribute("DateDelivery", DateDelivery)
|
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)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
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;
|
||||||
|
|
||||||
namespace IceCreamShopListImplement.Implements
|
namespace IceCreamShopListImplement.Implements
|
||||||
{
|
{
|
||||||
public class MessageInfoStorage
|
public class MessageInfoStorage
|
||||||
{
|
{
|
||||||
private readonly DataListSingleton _source;
|
private readonly DataListSingleton _source;
|
||||||
public MessageInfoStorage()
|
public MessageInfoStorage()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user