diff --git a/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/MessageLogicInfo.cs b/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/MessageLogicInfo.cs new file mode 100644 index 0000000..626ec49 --- /dev/null +++ b/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/MessageLogicInfo.cs @@ -0,0 +1,51 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopContracts.ViewModels; +using CarRepairShopDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopBusinessLogic.BusinessLogics +{ + public class MessageLogicInfo : IMessageInfoLogic + { + private readonly ILogger _logger; + private readonly IMessageInfoStorage _storage; + + public MessageLogicInfo(ILogger logger, IMessageInfoStorage storage) + { + _logger = logger; + _storage = storage; + } + + public List? ReadList(MessageInfoSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{Id}", model?.MessageId); + var list = model == null ? _storage.GetFullList() : _storage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool Create(MessageInfoBindingModel model) + { + if (_storage.Insert(model) == null) + { + _logger.LogInformation("Create operation failed"); + return false; + } + + return true; + } + } +} diff --git a/CarRepairShop/CarRepairShopContracts/BindingModels/MessageInfoBindingModel.cs b/CarRepairShop/CarRepairShopContracts/BindingModels/MessageInfoBindingModel.cs new file mode 100644 index 0000000..c78da34 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/BindingModels/MessageInfoBindingModel.cs @@ -0,0 +1,24 @@ +using CarRepairShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.BindingModels +{ + public class MessageInfoBindingModel : IMessageInfoModel + { + public string MessageId { get; set; } = string.Empty; + + public int? ClientId { get; set; } + + public string SenderName { get; set; } = string.Empty; + + public DateTime DateDelivery { get; set; } + + public string Subject { get; set; } = string.Empty; + + public string Body { get; set; } = string.Empty; + } +} diff --git a/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IMessageInfoLogic.cs b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IMessageInfoLogic.cs new file mode 100644 index 0000000..eef46f7 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IMessageInfoLogic.cs @@ -0,0 +1,17 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.BusinessLogicsContracts +{ + public interface IMessageInfoLogic + { + List? ReadList(MessageInfoSearchModel? model); + bool Create(MessageInfoBindingModel model); + } +} diff --git a/CarRepairShop/CarRepairShopContracts/SearchModels/MessageInfoSearchModel.cs b/CarRepairShop/CarRepairShopContracts/SearchModels/MessageInfoSearchModel.cs new file mode 100644 index 0000000..3733a65 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/SearchModels/MessageInfoSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.SearchModels +{ + public class MessageInfoSearchModel + { + public string? MessageId { get; set; } + public int? ClientId { get; set; } + } +} diff --git a/CarRepairShop/CarRepairShopContracts/StoragesContracts/IMessageInfoStorage.cs b/CarRepairShop/CarRepairShopContracts/StoragesContracts/IMessageInfoStorage.cs new file mode 100644 index 0000000..0b6774d --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/StoragesContracts/IMessageInfoStorage.cs @@ -0,0 +1,20 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.StoragesContracts +{ + public interface IMessageInfoStorage + { + List GetFullList(); + List GetFilteredList(MessageInfoSearchModel model); + MessageInfoViewModel? GetElement(MessageInfoSearchModel model); + MessageInfoViewModel? Insert(MessageInfoBindingModel model); + + } +} diff --git a/CarRepairShop/CarRepairShopContracts/ViewModels/MessageInfoViewModel.cs b/CarRepairShop/CarRepairShopContracts/ViewModels/MessageInfoViewModel.cs new file mode 100644 index 0000000..6c4745a --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/ViewModels/MessageInfoViewModel.cs @@ -0,0 +1,29 @@ +using CarRepairShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.ViewModels +{ + public class MessageInfoViewModel : IMessageInfoModel + { + public string MessageId { get; set; } = string.Empty; + + public int? ClientId { get; set; } + + [DisplayName("Почта отправителя")] + public string SenderName { get; set; } = string.Empty; + + [DisplayName("Дата получения")] + public DateTime DateDelivery { get; set; } + + [DisplayName("Заголовок")] + public string Subject { get; set; } = string.Empty; + + [DisplayName("Текст письма")] + public string Body { get; set; } = string.Empty; + } +} diff --git a/CarRepairShop/CarRepairShopDataModels/Models/IMessageInfoModel.cs b/CarRepairShop/CarRepairShopDataModels/Models/IMessageInfoModel.cs new file mode 100644 index 0000000..8d85ee6 --- /dev/null +++ b/CarRepairShop/CarRepairShopDataModels/Models/IMessageInfoModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopDataModels.Models +{ + public interface IMessageInfoModel + { + string MessageId { get; } + int? ClientId { get; } + string SenderName { get; } + DateTime DateDelivery { get; } + string Subject { get; } + string Body { get; } + } +} diff --git a/CarRepairShop/CarRepairShopDatabaseImplement/CarRepairShopDatabase.cs b/CarRepairShop/CarRepairShopDatabaseImplement/CarRepairShopDatabase.cs index ab5d3e2..26d529d 100644 --- a/CarRepairShop/CarRepairShopDatabaseImplement/CarRepairShopDatabase.cs +++ b/CarRepairShop/CarRepairShopDatabaseImplement/CarRepairShopDatabase.cs @@ -28,5 +28,6 @@ namespace CarRepairShopDatabaseImplement public virtual DbSet Orders { get; set; } public virtual DbSet Clients { get; set; } public virtual DbSet Implementers { get; set; } + public virtual DbSet Messages { get; set; } } } \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopDatabaseImplement/Implements/MessageInfoStorage.cs b/CarRepairShop/CarRepairShopDatabaseImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..bed8a70 --- /dev/null +++ b/CarRepairShop/CarRepairShopDatabaseImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,47 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopContracts.ViewModels; +using CarRepairShopDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopDatabaseImplement.Implements +{ + public class MessageInfoStorage : IMessageInfoStorage + { + public List GetFullList() + { + using var context = new CarRepairShopDatabase(); + return context.Messages.Include(x => x.Client).Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(MessageInfoSearchModel model) + { + if (!model.ClientId.HasValue) return new(); + using var context = new CarRepairShopDatabase(); + return context.Messages.Include(x => x.Client).Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList(); + } + + public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) + { + if(string.IsNullOrEmpty(model.MessageId)) return null; + using var context = new CarRepairShopDatabase(); + return context.Messages.Include(x => x.Client).FirstOrDefault(x => x.MessageId.Equals(model.MessageId))?.GetViewModel; + } + public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + { + using var context = new CarRepairShopDatabase(); + model.ClientId = context.Clients.FirstOrDefault(x => x.Email.Equals(model.SenderName))?.Id; + var message = MessageInfo.Create(model); + if(message == null) return null; + context.Messages.Add(message); + context.SaveChanges(); + return message.GetViewModel; + } + } +} diff --git a/CarRepairShop/CarRepairShopDatabaseImplement/Models/MessageInfo.cs b/CarRepairShop/CarRepairShopDatabaseImplement/Models/MessageInfo.cs new file mode 100644 index 0000000..c5a83c4 --- /dev/null +++ b/CarRepairShop/CarRepairShopDatabaseImplement/Models/MessageInfo.cs @@ -0,0 +1,55 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.ViewModels; +using CarRepairShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopDatabaseImplement.Models +{ + public class MessageInfo : IMessageInfoModel + { + [Key] + public string MessageId { get; set; } = string.Empty; + + public int? ClientId { get; set; } + + [Required] + public string SenderName { get; set; } = string.Empty; + [Required] + public DateTime DateDelivery { get; set; } + [Required] + public string Subject { get; set; } = string.Empty; + [Required] + public string Body { get; set; } = string.Empty; + + public virtual Client Client { get; private set; } + + public static MessageInfo? Create(MessageInfoBindingModel model) + { + if (model == null) return null; + return new MessageInfo + { + MessageId = model.MessageId, + ClientId = model.ClientId, + SenderName = model.SenderName, + Body = model.Body, + Subject = model.Subject, + DateDelivery = model.DateDelivery, + }; + } + + public MessageInfoViewModel GetViewModel => new() + { + MessageId = MessageId, + ClientId = ClientId, + SenderName = SenderName, + Body = Body, + Subject = Subject, + DateDelivery = DateDelivery, + }; + } +} diff --git a/CarRepairShop/CarRepairShopFileImplement/DataFileSingleton.cs b/CarRepairShop/CarRepairShopFileImplement/DataFileSingleton.cs index a93d5c3..992bbf9 100644 --- a/CarRepairShop/CarRepairShopFileImplement/DataFileSingleton.cs +++ b/CarRepairShop/CarRepairShopFileImplement/DataFileSingleton.cs @@ -16,11 +16,13 @@ namespace CarRepairShopFileImplement private readonly string RepairFileName = "Repair.xml"; private readonly string ClientFileName = "Client.xml"; private readonly string ImplementerFileName = "Implementer.xml"; + private readonly string MessagesFileName = "MessageInfo.xml"; public List Components { get; private set; } public List Orders { get; private set; } public List Repairs { get; private set; } public List Clients { get; private set; } public List Implementers { get; private set; } + public List Messages { get; private set; } public static DataFileSingleton GetInstance() { if(instance == null) @@ -34,6 +36,7 @@ namespace CarRepairShopFileImplement public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement); + public void SaveMessages() => SaveData(Messages, MessagesFileName, "Messages", x => x.GetXElement); private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; @@ -41,6 +44,7 @@ namespace CarRepairShopFileImplement Orders = LoadData(OrderFileName, "Order", x=> Order.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x=> Client.Create(x)!)!; Implementers = LoadData(ImplementerFileName, "Implementer", x=> Implementer.Create(x)!)!; + Messages = LoadData(MessagesFileName, "MessageInfo", x => MessageInfo.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) { diff --git a/CarRepairShop/CarRepairShopFileImplement/Implements/MessageInfoStorage.cs b/CarRepairShop/CarRepairShopFileImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..dda4033 --- /dev/null +++ b/CarRepairShop/CarRepairShopFileImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,47 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopContracts.ViewModels; +using CarRepairShopFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopFileImplement.Implements +{ + public class MessageInfoStorage : IMessageInfoStorage + { + private readonly DataFileSingleton _source; + + public MessageInfoStorage() + { + _source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() + { + return _source.Messages.Select(x => x.GetViewModel).ToList(); + } + public List GetFilteredList(MessageInfoSearchModel model) + { + if (model == null) return new(); + return _source.Messages.Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList(); + } + public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) + { + if(model == null) return null; + return _source.Messages.FirstOrDefault(x => x.MessageId.Equals(model.MessageId))?.GetViewModel; + } + public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + { + if (model == null) return null; + var newMessage = MessageInfo.Create(model); + if(newMessage == null) return null; + _source.Messages.Add(newMessage); + _source.SaveMessages(); + return newMessage.GetViewModel; + } + } +} diff --git a/CarRepairShop/CarRepairShopFileImplement/Models/MessageInfo.cs b/CarRepairShop/CarRepairShopFileImplement/Models/MessageInfo.cs new file mode 100644 index 0000000..bd25770 --- /dev/null +++ b/CarRepairShop/CarRepairShopFileImplement/Models/MessageInfo.cs @@ -0,0 +1,74 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.ViewModels; +using CarRepairShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace CarRepairShopFileImplement.Models +{ + public class MessageInfo : IMessageInfoModel + { + public string MessageId { get; set; } = string.Empty; + + public int? ClientId { get; set; } + + public string SenderName { get; set; } = string.Empty; + + public DateTime DateDelivery { get; set; } + + public string Subject { get; set; } = string.Empty; + + public string Body { get; set; } = string.Empty; + + public static MessageInfo? Create(MessageInfoBindingModel? model) + { + if (model == null) return null; + return new MessageInfo() + { + MessageId = model.MessageId, + ClientId = model.ClientId, + SenderName = model.SenderName, + DateDelivery = model.DateDelivery, + Subject = model.Subject, + Body = model.Body, + }; + } + + public static MessageInfo? Create(XElement element) + { + if (element == null) return null; + return new MessageInfo() + { + MessageId = element.Attribute("MessageId")!.Value, + ClientId = Convert.ToInt32(element.Attribute("ClientId")!.Value), + SenderName = element.Element("SenderName")!.Value, + DateDelivery = Convert.ToDateTime(element.Element("DateDelivery")!.Value), + Subject = element.Attribute("Subject")!.Value, + Body = element.Attribute("Body")!.Value, + }; + } + + public MessageInfoViewModel GetViewModel => new() + { + MessageId = MessageId, + ClientId = ClientId, + SenderName = SenderName, + DateDelivery = DateDelivery, + Subject = Subject, + Body = Body, + }; + + public XElement GetXElement => new("MessageInfo", + new XAttribute("MessageId", MessageId.ToString()), + new XElement("ClientId", ClientId.ToString()), + new XElement("SenderName", SenderName), + new XElement("DateDelivery", DateDelivery), + new XElement("Subject", Subject), + new XElement("Body", Body), + new XElement("SenderName", SenderName)); + } +} diff --git a/CarRepairShop/CarRepairShopListImplement/DataListSingleton.cs b/CarRepairShop/CarRepairShopListImplement/DataListSingleton.cs index 6f61107..f55f44b 100644 --- a/CarRepairShop/CarRepairShopListImplement/DataListSingleton.cs +++ b/CarRepairShop/CarRepairShopListImplement/DataListSingleton.cs @@ -10,6 +10,7 @@ namespace CarRepairShopListImplement public List Orders { get; set; } public List Clients { get; set; } public List Implementers { get; set; } + public List Messages { get; set; } private DataListSingleton() { @@ -18,6 +19,7 @@ namespace CarRepairShopListImplement Orders = new List(); Clients = new List(); Implementers = new List(); + Messages = new List(); } public static DataListSingleton GetInstance() diff --git a/CarRepairShop/CarRepairShopListImplement/Implements/MessageInfoStorage.cs b/CarRepairShop/CarRepairShopListImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..2f8be11 --- /dev/null +++ b/CarRepairShop/CarRepairShopListImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,67 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopContracts.ViewModels; +using CarRepairShopListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopListImplement.Implements +{ + public class MessageInfoStorage : IMessageInfoStorage + { + + private readonly DataListSingleton _source; + + public MessageInfoStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var list = new List(); + foreach(var message in _source.Messages) + { + list.Add(message.GetViewModel); + } + return list; + } + public List GetFilteredList(MessageInfoSearchModel model) + { + var list = new List(); + if(!model.ClientId.HasValue) return list; + foreach(var message in _source.Messages) + { + if(model.ClientId == message.ClientId) + { + list.Add(message.GetViewModel); + } + } + return list; + } + public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) + { + if(string.IsNullOrEmpty(model.MessageId)) return null; + + foreach(var message in _source.Messages) + { + if (model.MessageId.Equals(model.MessageId)) + { + return message.GetViewModel; + } + } + return null; + } + public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + { + var newMessage = MessageInfo.Create(model); + if(newMessage == null) return null; + _source.Messages.Add(newMessage); + return newMessage.GetViewModel; + } + } +} diff --git a/CarRepairShop/CarRepairShopListImplement/Models/MessageInfo.cs b/CarRepairShop/CarRepairShopListImplement/Models/MessageInfo.cs new file mode 100644 index 0000000..8e0d346 --- /dev/null +++ b/CarRepairShop/CarRepairShopListImplement/Models/MessageInfo.cs @@ -0,0 +1,50 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.ViewModels; +using CarRepairShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopListImplement.Models +{ + public class MessageInfo : IMessageInfoModel + { + public string MessageId { get; set; } = string.Empty; + + public int? ClientId { get; set; } + + public string SenderName { get; set; } = string.Empty; + + public DateTime DateDelivery { get; set; } + + public string Subject { get; set; } = string.Empty; + + public string Body { get; set; } = string.Empty; + + public static MessageInfo? Create(MessageInfoBindingModel model) + { + if (model == null) return null; + return new MessageInfo() + { + MessageId = model.MessageId, + ClientId = model.ClientId, + SenderName = model.SenderName, + DateDelivery = model.DateDelivery, + Subject = model.Subject, + Body = model.Body, + }; + } + + public MessageInfoViewModel GetViewModel => new() + { + MessageId = MessageId, + ClientId = ClientId, + SenderName = SenderName, + DateDelivery = DateDelivery, + Subject = Subject, + Body = Body, + }; + } +} diff --git a/CarRepairShop/CarRepairShopRestApi/appsettings.json b/CarRepairShop/CarRepairShopRestApi/appsettings.json index 10f68b8..0578777 100644 --- a/CarRepairShop/CarRepairShopRestApi/appsettings.json +++ b/CarRepairShop/CarRepairShopRestApi/appsettings.json @@ -5,5 +5,13 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + + "SmtpClientHost": "smtp.gmail.com", + "SmtpClientPort": "587", + "PopHost": "pop.gmail.com", + "PopPort": "995", + "MailLogin": "labwork7@mail.com", + "MailPassword": "#eoxSyN1aJS1" + } diff --git a/CarRepairShop/CarRepairShopView/App.config b/CarRepairShop/CarRepairShopView/App.config new file mode 100644 index 0000000..e2d0651 --- /dev/null +++ b/CarRepairShop/CarRepairShopView/App.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file