From 1733ff3820a2eba91901c4f7c749ac465d0ed03c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D1=8F=D1=87=D0=B5=D1=81=D0=BB=D0=B0=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Tue, 2 Apr 2024 21:27:34 +0400 Subject: [PATCH] fix --- .../BusinessLogics/ClientLogic.cs | 6 +- .../BusinessLogics/OrderLogic.cs | 44 +-- .../Controllers/HomeController.cs | 258 +++++++++--------- .../PizzeriaClientApp.csproj | 1 + .../ViewModels/OrderViewModel.cs | 4 +- .../Implements/ClientStorage.cs | 8 +- .../PizzeriaDatabaseImplement/Models/Order.cs | 4 +- .../PizzeriaDatabase.cs | 4 +- .../Implements/ImplementerStorage.cs | 86 ++++-- .../Implements/MessageInfoStorage.cs | 58 ++++ 10 files changed, 294 insertions(+), 179 deletions(-) create mode 100644 Pizzeria/PizzeriaFileImplement/Implements/MessageInfoStorage.cs diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/ClientLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/ClientLogic.cs index ee80499..a668906 100644 --- a/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/ClientLogic.cs +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/ClientLogic.cs @@ -105,9 +105,9 @@ namespace PizzeriaBusinessLogic.BusinessLogics { throw new ArgumentNullException("Не указан правильный пароль", nameof(model.Password)); } - _logger.LogInformation("Client. ClientFIO:{ClientFIO}.Email:{Email}.Id:{Id}", - model.ClientFIO, model.Email, model.Id); - var element = _clientStorage.GetElement(new ClientSearchModel + _logger.LogInformation("Client. ClientFIO:{ClientFIO}.Email:{Email}.Id:{Id}", + model.ClientFIO, model.Email, model.Id); + var element = _clientStorage.GetElement(new ClientSearchModel { ClientFIO = model.ClientFIO }); diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/OrderLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/OrderLogic.cs index db89b12..ccf875c 100644 --- a/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/OrderLogic.cs @@ -14,14 +14,14 @@ namespace PizzeriaBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; - private readonly AbstractMailWorker _mailWorker; - static readonly object _locker = new object(); + private readonly AbstractMailWorker _mailWorker; + static readonly object _locker = new object(); public OrderLogic(ILogger logger, IOrderStorage orderStorage, AbstractMailWorker mailWorker) { _logger = logger; _orderStorage = orderStorage; - _mailWorker = mailWorker; - } + _mailWorker = mailWorker; + } public OrderViewModel? ReadElement(OrderSearchModel model) { @@ -61,19 +61,19 @@ namespace PizzeriaBusinessLogic.BusinessLogics if (model.Status != OrderStatus.Неизвестен) return false; model.Status = OrderStatus.Принят; - var element = _orderStorage.Insert(model); - if (element == null) - { + var element = _orderStorage.Insert(model); + if (element == null) + { _logger.LogWarning("Insert operation failed"); return false; } - Task.Run(() => _mailWorker.MailSendAsync(new MailSendInfoBindingModel - { - MailAddress = element.ClientEmail, - Subject = $"Изменение статуса заказа номер {element.Id}", - Text = $"Ваш заказ номер {element.Id} на пиццу {element.PizzaName} от {element.DateCreate} на сумму {element.Sum} принят." - })); - return true; + Task.Run(() => _mailWorker.MailSendAsync(new MailSendInfoBindingModel + { + MailAddress = element.ClientEmail, + Subject = $"Изменение статуса заказа номер {element.Id}", + Text = $"Ваш заказ номер {element.Id} на пиццу {element.PizzaName} от {element.DateCreate} на сумму {element.Sum} принят." + })); + return true; } public bool TakeOrderInWork(OrderBindingModel model) @@ -154,14 +154,14 @@ namespace PizzeriaBusinessLogic.BusinessLogics _logger.LogWarning("Update operation failed"); return false; } - string DateInfo = model.DateImplement.HasValue ? $"Дата выполнения {model.DateImplement}" : ""; - Task.Run(() => _mailWorker.MailSendAsync(new MailSendInfoBindingModel - { - MailAddress = element.ClientEmail, - Subject = $"Изменение статуса заказа номер {element.Id}", - Text = $"Ваш заказ номер {element.Id} на пиццу {element.PizzaName} от {element.DateCreate} на сумму {element.Sum} {model.Status}. {DateInfo}" - })); - return true; + string DateInfo = model.DateImplement.HasValue ? $"Дата выполнения {model.DateImplement}" : ""; + Task.Run(() => _mailWorker.MailSendAsync(new MailSendInfoBindingModel + { + MailAddress = element.ClientEmail, + Subject = $"Изменение статуса заказа номер {element.Id}", + Text = $"Ваш заказ номер {element.Id} на пиццу {element.PizzaName} от {element.DateCreate} на сумму {element.Sum} {model.Status}. {DateInfo}" + })); + return true; } _logger.LogWarning("Changing status operation faled: Current-{Status}:required-{requiredStatus}.", model.Status, requiredStatus); throw new InvalidOperationException($"Невозможно приствоить статус {requiredStatus} заказу с текущим статусом {model.Status}"); diff --git a/Pizzeria/PizzeriaClientApp/Controllers/HomeController.cs b/Pizzeria/PizzeriaClientApp/Controllers/HomeController.cs index a37d3b6..b14add9 100644 --- a/Pizzeria/PizzeriaClientApp/Controllers/HomeController.cs +++ b/Pizzeria/PizzeriaClientApp/Controllers/HomeController.cs @@ -1,158 +1,168 @@ -using Microsoft.AspNetCore.Mvc; -using PizzeriaClientApp.Models; +using PizzeriaDataModels.Enums; using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StoragesContracts; using PizzeriaContracts.ViewModels; -using System.Diagnostics; -using Microsoft.Extensions.Logging; +using PizzeriaBusinessLogic.MailWorker; -namespace PizzeriaClientApp.Controllers +namespace PizzeriaBusinessLogic.BusinessLogics { - public class HomeController : Controller + public class OrderLogic : IOrderLogic { - private readonly ILogger _logger; - - public HomeController(ILogger logger) + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + private readonly AbstractMailWorker _mailWorker; + static readonly object _locker = new object(); + public OrderLogic(ILogger logger, IOrderStorage orderStorage, AbstractMailWorker mailWorker) { _logger = logger; + _orderStorage = orderStorage; + _mailWorker = mailWorker; } - public IActionResult Index() + public OrderViewModel? ReadElement(OrderSearchModel model) { - if (APIClient.Client == null) + if (model == null) { - return Redirect("~/Home/Enter"); + throw new ArgumentNullException(nameof(model)); } - return View(APIClient.GetRequest>($"api/main/getorders?clientId={APIClient.Client.Id}")); + _logger.LogInformation("ReadElement. ClientId:{ClientId}.Status:{Status}.ImplementerId:{ImplementerId}.DateFrom:{DateFrom}.DateTo:{DateTo}OrderId:{Id}", + model.ClientId, model.Status, model.ImplementerId, model.DateFrom, model.DateTo, model.Id); + var element = _orderStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; } - [HttpGet] - public IActionResult Privacy() + public List? ReadList(OrderSearchModel? model) { - if (APIClient.Client == null) + _logger.LogInformation("ReadList. ClientId:{ClientId}.Status:{Status}.ImplementerId:{ImplementerId}.DateFrom:{DateFrom}.DateTo:{DateTo}OrderId:{Id}", + model?.ClientId, model?.Status, model?.ImplementerId, model?.DateFrom, model?.DateTo, model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) { - return Redirect("~/Home/Enter"); + _logger.LogWarning("ReadList return null list"); + return null; } - return View(APIClient.Client); + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; } - [HttpPost] - public void Privacy(string login, string password, string fio) + public bool CreateOrder(OrderBindingModel model) { - if (APIClient.Client == null) + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) + return false; + model.Status = OrderStatus.Принят; + var element = _orderStorage.Insert(model); + if (element == null) { - throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + _logger.LogWarning("Insert operation failed"); + return false; } - if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) + Task.Run(() => _mailWorker.MailSendAsync(new MailSendInfoBindingModel { - throw new Exception("Введите логин, пароль и ФИО"); + MailAddress = element.ClientEmail, + Subject = $"Изменение статуса заказа номер {element.Id}", + Text = $"Ваш заказ номер {element.Id} на пиццу {element.PizzaName} от {element.DateCreate} на сумму {element.Sum} принят." + })); + return true; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + lock (_locker) + { + return ChangeStatus(model, OrderStatus.Выполняется); } - APIClient.PostRequest("api/client/updatedata", new ClientBindingModel + } + + public bool FinishOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Готов); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выдан); + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) { - Id = APIClient.Client.Id, - ClientFIO = fio, - Email = login, - Password = password + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Count <= 0) + { + throw new ArgumentException("Колличество пиццы в заказе не может быть меньше 1", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentException("Стоимость заказа на может быть меньше 1", nameof(model.Sum)); + } + if (model.DateImplement.HasValue && model.DateImplement < model.DateCreate) + { + throw new ArithmeticException($"Дата выдачи заказа {model.DateImplement} не может быть раньше даты его создания {model.DateCreate}"); + } + _logger.LogInformation("Pizza. PizzaId:{PizzaId}.Count:{Count}.Sum:{Sum}Id:{Id}", + model.PizzaId, model.Count, model.Sum, model.Id); + } + + private bool ChangeStatus(OrderBindingModel model, OrderStatus requiredStatus) + { + CheckModel(model, false); + var element = _orderStorage.GetElement(new OrderSearchModel() + { + Id = model.Id }); - - APIClient.Client.ClientFIO = fio; - APIClient.Client.Email = login; - APIClient.Client.Password = password; - Response.Redirect("Index"); - } - - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] - public IActionResult Error() - { - return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); - } - - [HttpGet] - public IActionResult Enter() - { - return View(); - } - - [HttpPost] - public void Enter(string login, string password) - { - if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) + if (element == null) { - throw new Exception("Введите логин и пароль"); + throw new InvalidOperationException(nameof(element)); } - APIClient.Client = APIClient.GetRequest($"api/client/login?login={login}&password={password}"); - if (APIClient.Client == null) + model.DateCreate = element.DateCreate; + model.PizzaId = element.PizzaId; + model.DateImplement = element.DateImplement; + model.ClientId = element.ClientId; + if (!model.ImplementerId.HasValue) { - throw new Exception("Неверный логин/пароль"); + model.ImplementerId = element.ImplementerId; } - Response.Redirect("Index"); - } - - [HttpGet] - public IActionResult Register() - { - return View(); - } - - [HttpPost] - public void Register(string login, string password, string fio) - { - if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) + model.Status = element.Status; + model.Count = element.Count; + model.Sum = element.Sum; + if (requiredStatus - model.Status == 1) { - throw new Exception("Введите логин, пароль и ФИО"); + model.Status = requiredStatus; + if (model.Status == OrderStatus.Готов) + { + model.DateImplement = DateTime.Now; + } + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + string DateInfo = model.DateImplement.HasValue ? $"Дата выполнения {model.DateImplement}" : ""; + Task.Run(() => _mailWorker.MailSendAsync(new MailSendInfoBindingModel + { + MailAddress = element.ClientEmail, + Subject = $"Изменение статуса заказа номер {element.Id}", + Text = $"Ваш заказ номер {element.Id} на пиццу {element.PizzaName} от {element.DateCreate} на сумму {element.Sum} {model.Status}. {DateInfo}" + })); + return true; } - APIClient.PostRequest("api/client/register", new ClientBindingModel - { - ClientFIO = fio, - Email = login, - Password = password - }); - Response.Redirect("Enter"); - return; + _logger.LogWarning("Changing status operation faled: Current-{Status}:required-{requiredStatus}.", model.Status, requiredStatus); + throw new InvalidOperationException($"Невозможно приствоить статус {requiredStatus} заказу с текущим статусом {model.Status}"); } - - [HttpGet] - public IActionResult Create() - { - ViewBag.Pizzas = APIClient.GetRequest>("api/main/getpizzalist"); - return View(); - } - - [HttpPost] - public void Create(int pizza, int count) - { - if (APIClient.Client == null) - { - throw new Exception("Вы как суда попали? Суда вход только авторизованным"); - } - if (count <= 0) - { - throw new Exception("Количество и сумма должны быть больше 0"); - } - APIClient.PostRequest("api/main/createorder", new OrderBindingModel - { - ClientId = APIClient.Client.Id, - PizzaId = pizza, - Count = count, - Sum = Calc(count, pizza) - }); - Response.Redirect("Index"); - } - - [HttpPost] - public double Calc(int count, int pizza) - { - var piz = APIClient.GetRequest($"api/main/getpizza?pizzaId={pizza}"); - return count * (piz?.Price ?? 1); - } - - [HttpGet] - public IActionResult Mails() - { - if (APIClient.Client == null) - { - return Redirect("~/Home/Enter"); - } - return View(APIClient.GetRequest>($"api/client/getmessages?clientId={APIClient.Client.Id}")); - } - } + } } diff --git a/Pizzeria/PizzeriaClientApp/PizzeriaClientApp.csproj b/Pizzeria/PizzeriaClientApp/PizzeriaClientApp.csproj index 6eb2ec2..d10db06 100644 --- a/Pizzeria/PizzeriaClientApp/PizzeriaClientApp.csproj +++ b/Pizzeria/PizzeriaClientApp/PizzeriaClientApp.csproj @@ -11,6 +11,7 @@ + diff --git a/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs index 10916ea..4ba8a4e 100644 --- a/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs +++ b/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs @@ -19,9 +19,9 @@ namespace PizzeriaContracts.ViewModels [DisplayName("ФИО клиента")] public string ClientFIO { get; set; } = string.Empty; - public string ClientEmail { get; set; } = string.Empty; + public string ClientEmail { get; set; } = string.Empty; - public int? ImplementerId { get; set; } + public int? ImplementerId { get; set; } [DisplayName("Исполнитель")] public string? ImplementerFIO { get; set; } = null; diff --git a/Pizzeria/PizzeriaDatabaseImplement/Implements/ClientStorage.cs b/Pizzeria/PizzeriaDatabaseImplement/Implements/ClientStorage.cs index 435ebb0..58d313d 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Implements/ClientStorage.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Implements/ClientStorage.cs @@ -31,10 +31,10 @@ namespace PizzeriaDatabaseImplement.Implements return null; } using var context = new PizzeriaDatabase(); - return context.Clients.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) || - (!string.IsNullOrEmpty(model.ClientFIO) && x.ClientFIO == model.ClientFIO) || - (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email && (string.IsNullOrEmpty(model.Password) || x.Password == model.Password)))?.GetViewModel; - } + return context.Clients.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) || + (!string.IsNullOrEmpty(model.ClientFIO) && x.ClientFIO == model.ClientFIO) || + (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email && (string.IsNullOrEmpty(model.Password) || x.Password == model.Password)))?.GetViewModel; + } public ClientViewModel? Insert(ClientBindingModel model) { diff --git a/Pizzeria/PizzeriaDatabaseImplement/Models/Order.cs b/Pizzeria/PizzeriaDatabaseImplement/Models/Order.cs index 16804f7..bad7435 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Models/Order.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Models/Order.cs @@ -74,8 +74,8 @@ namespace PizzeriaDatabaseImplement.Models Id = Id, ClientId = ClientId, ClientFIO = Client.ClientFIO, - ClientEmail = Client.Email, - PizzaId = PizzaId, + ClientEmail = Client.Email, + PizzaId = PizzaId, PizzaName = Pizza.PizzaName, ImplementerId = ImplementerId, ImplementerFIO = Implementer != null ? Implementer.ImplementerFIO : null, diff --git a/Pizzeria/PizzeriaDatabaseImplement/PizzeriaDatabase.cs b/Pizzeria/PizzeriaDatabaseImplement/PizzeriaDatabase.cs index e75c1eb..744e762 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/PizzeriaDatabase.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/PizzeriaDatabase.cs @@ -19,6 +19,6 @@ namespace PizzeriaDatabaseImplement public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } public virtual DbSet Implementers { set; get; } - public virtual DbSet MessageInfos { set; get; } - } + public virtual DbSet MessageInfos { set; get; } + } } diff --git a/Pizzeria/PizzeriaFileImplement/Implements/ImplementerStorage.cs b/Pizzeria/PizzeriaFileImplement/Implements/ImplementerStorage.cs index 73fd311..4aed6f0 100644 --- a/Pizzeria/PizzeriaFileImplement/Implements/ImplementerStorage.cs +++ b/Pizzeria/PizzeriaFileImplement/Implements/ImplementerStorage.cs @@ -6,43 +6,89 @@ using PizzeriaFileImplement.Models; namespace PizzeriaFileImplement.Implements { - public class MessageInfoStorage : IMessageInfoStorage + public class ImplementerStorage : IImplementerStorage { private readonly DataFileSingleton _source; - public MessageInfoStorage() + public ImplementerStorage() { _source = DataFileSingleton.GetInstance(); } - public List GetFullList() + public List GetFullList() { - return _source.Messages.Select(x => x.GetViewModel).ToList(); + return _source.Implementers.Select(x => x.GetViewModel).ToList(); } - public List GetFilteredList(MessageInfoSearchModel model) + public List GetFilteredList(ImplementerSearchModel model) { - return _source.Messages.Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList(); - } - - public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) - { - if (model.MessageId != null) + if (model == null) { - return _source.Messages.FirstOrDefault(x => x.MessageId == model.MessageId)?.GetViewModel; + return new(); + } + if (model.Id.HasValue) + { + var res = GetElement(model); + return res != null ? new() { res } : new(); + } + if (model.ImplementerFIO != null) + { + return _source.Implementers + .Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (model.Id.HasValue) + { + return _source.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + } + if (model.ImplementerFIO != null && model.Password != null) + { + return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO) && x.Password.Equals(model.Password))?.GetViewModel; + } + if (model.ImplementerFIO != null) + { + return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel; } return null; } - public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + public ImplementerViewModel? Insert(ImplementerBindingModel model) { - var newMessage = MessageInfo.Create(model); - if (newMessage == null) + model.Id = _source.Implementers.Count > 0 ? _source.Implementers.Max(x => x.Id) + 1 : 1; + var res = Implementer.Create(model); + if (res != null) { - return null; + _source.Implementers.Add(res); + _source.SaveImplementers(); } - _source.Messages.Add(newMessage); - _source.SaveMessages(); - return newMessage.GetViewModel; + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + res.Update(model); + _source.SaveImplementers(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + _source.Implementers.Remove(res); + _source.SaveImplementers(); + } + return res?.GetViewModel; } } -} +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaFileImplement/Implements/MessageInfoStorage.cs b/Pizzeria/PizzeriaFileImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..dfffe5b --- /dev/null +++ b/Pizzeria/PizzeriaFileImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,58 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StoragesContracts; +using PizzeriaContracts.ViewModels; +using PizzeriaFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaFileImplement.Implements +{ + public class MessageInfoStorage : IMessageInfoStorage + { + private readonly DataFileSingleton _source; + public MessageInfoStorage() + { + _source = DataFileSingleton.GetInstance(); + } + + public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) + { + if (model.MessageId != null) + { + return _source.Messages.FirstOrDefault(x => x.MessageId == model.MessageId)?.GetViewModel; + } + return null; + } + + public List GetFilteredList(MessageInfoSearchModel model) + { + return _source.Messages + .Where(x => x.ClientId == model.ClientId) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + return _source.Messages + .Select(x => x.GetViewModel) + .ToList(); + } + + public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + { + var newMessage = MessageInfo.Create(model); + if (newMessage == null) + { + return null; + } + _source.Messages.Add(newMessage); + _source.SaveMessages(); + return newMessage.GetViewModel; + } + } +}