diff --git a/.gitignore b/.gitignore index ca1c7a3..f9f8206 100644 --- a/.gitignore +++ b/.gitignore @@ -69,6 +69,8 @@ ScaffoldingReadMe.txt # StyleCop StyleCopReport.xml +/TravelCompany/ImplementationExtensions + # Files built by Visual Studio *_i.c *_p.c diff --git a/TravelCompany/TravelCompany/FormClients.cs b/TravelCompany/TravelCompany/FormClients.cs index 5e4c35e..b3c7a34 100644 --- a/TravelCompany/TravelCompany/FormClients.cs +++ b/TravelCompany/TravelCompany/FormClients.cs @@ -28,18 +28,7 @@ namespace TravelCompany.Forms { try { - var list = _logic.ReadList(null); - if (list != null) - { - DataGridView.DataSource = list; - DataGridView.Columns["Id"].Visible = false; - DataGridView.Columns["ClientFIO"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - DataGridView.Columns["Email"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - DataGridView.Columns["Password"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } + DataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка клиентов"); } catch (Exception ex) diff --git a/TravelCompany/TravelCompany/FormComponents.cs b/TravelCompany/TravelCompany/FormComponents.cs index 6fc3a44..39eafdd 100644 --- a/TravelCompany/TravelCompany/FormComponents.cs +++ b/TravelCompany/TravelCompany/FormComponents.cs @@ -10,6 +10,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using TravelCompanyContracts.DI; namespace TravelCompany.Forms { @@ -51,13 +52,10 @@ namespace TravelCompany.Forms private void buttonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } @@ -65,14 +63,12 @@ namespace TravelCompany.Forms { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) + var form = DependencyManager.Instance.Resolve(); + + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } } diff --git a/TravelCompany/TravelCompany/FormTravel.cs b/TravelCompany/TravelCompany/FormTravel.cs index 2dd37b9..6b26778 100644 --- a/TravelCompany/TravelCompany/FormTravel.cs +++ b/TravelCompany/TravelCompany/FormTravel.cs @@ -12,6 +12,8 @@ using System.Windows.Forms; using TravelCompanyContracts.BusinessLogicsContracts; using TravelCompanyContracts.SearchModels; using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.DI; +using TravelCompanyDatabaseImplement.Models; namespace TravelCompany.Forms { @@ -20,14 +22,14 @@ namespace TravelCompany.Forms private readonly ILogger _logger; private readonly ITravelLogic _logic; private int? _id; - private Dictionary _productComponents; + private Dictionary _travelComponents; public int Id { set { _id = value; } } public FormTravel(ILogger logger, ITravelLogic logic) { InitializeComponent(); _logger = logger; _logic = logic; - _productComponents = new Dictionary(); + _travelComponents = new Dictionary(); } private void FormTravel_Load(object sender, EventArgs e) { @@ -44,7 +46,7 @@ namespace TravelCompany.Forms { textBoxName.Text = view.TravelName; textBoxPrice.Text = view.Price.ToString(); - _productComponents = view.TravelComponents ?? new Dictionary(); + _travelComponents = view.TravelComponents ?? new Dictionary(); LoadData(); } } @@ -59,10 +61,10 @@ namespace TravelCompany.Forms _logger.LogInformation("Загрузка компонент изделия"); try { - if (_productComponents != null) + if (_travelComponents != null) { dataGridView.Rows.Clear(); - foreach (var pc in _productComponents) + foreach (var pc in _travelComponents) { dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); } @@ -76,51 +78,44 @@ namespace TravelCompany.Forms } private void buttonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormTravelComponent)); - if (service is FormTravelComponent form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { + return; + } + _logger.LogInformation("Добавление нового ингридиента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count); + if (_travelComponents.ContainsKey(form.Id)) + { + _travelComponents[form.Id] = (form.ComponentModel, + form.Count); + } + else + { + _travelComponents.Add(form.Id, (form.ComponentModel, + form.Count)); + } + LoadData(); + } + private void buttonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var form = DependencyManager.Instance.Resolve(); + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _travelComponents[id].Item2; if (form.ShowDialog() == DialogResult.OK) { if (form.ComponentModel == null) { return; } - _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count} ", form.ComponentModel.ComponentName, form.Count); - if (_productComponents.ContainsKey(form.Id)) - { - _productComponents[form.Id] = (form.ComponentModel, form.Count); - } - else - { - _productComponents.Add(form.Id, (form.ComponentModel, form.Count)); - } + _logger.LogInformation("Изменение ингридиента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count); + _travelComponents[form.Id] = (form.ComponentModel, form.Count); LoadData(); } } } - private void buttonUpd_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - var service = Program.ServiceProvider?.GetService(typeof(FormTravelComponent)); - if (service is FormTravelComponent form) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); - form.Id = id; - form.Count = _productComponents[id].Item2; - if (form.ShowDialog() == DialogResult.OK) - { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); - _productComponents[form.Id] = (form.ComponentModel, form.Count); - LoadData(); - } - } - } - } private void buttonDel_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) @@ -130,7 +125,7 @@ namespace TravelCompany.Forms try { _logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value); - _productComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + _travelComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); } catch (Exception ex) { @@ -156,7 +151,7 @@ namespace TravelCompany.Forms MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - if (_productComponents == null || _productComponents.Count == 0) + if (_travelComponents == null || _travelComponents.Count == 0) { MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; @@ -169,7 +164,7 @@ namespace TravelCompany.Forms Id = _id ?? 0, TravelName = textBoxName.Text, Price = Convert.ToDouble(textBoxPrice.Text), - TravelComponents = _productComponents + TravelComponents = _travelComponents }; var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); if (!operationResult) @@ -195,7 +190,7 @@ namespace TravelCompany.Forms private double CalcPrice() { double price = 0; - foreach (var elem in _productComponents) + foreach (var elem in _travelComponents) { price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); } diff --git a/TravelCompany/TravelCompany/FormTravels.cs b/TravelCompany/TravelCompany/FormTravels.cs index b772ffd..cbf0703 100644 --- a/TravelCompany/TravelCompany/FormTravels.cs +++ b/TravelCompany/TravelCompany/FormTravels.cs @@ -11,6 +11,7 @@ using TravelCompany; using TravelCompanyContracts.BindingModels; using TravelCompanyContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; +using TravelCompanyContracts.DI; namespace TravelCompany.Forms { @@ -34,14 +35,7 @@ namespace TravelCompany.Forms { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["TravelComponents"].Visible = false; - dataGridView.Columns["TravelName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка путёвок"); } catch (Exception ex) @@ -52,13 +46,10 @@ namespace TravelCompany.Forms private void buttonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormTravel)); - if (service is FormTravel form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } @@ -66,14 +57,11 @@ namespace TravelCompany.Forms { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormTravel)); - if (service is FormTravel form) + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } } diff --git a/TravelCompany/TravelCompany/FormViewMail.cs b/TravelCompany/TravelCompany/FormViewMail.cs index 278477b..9862810 100644 --- a/TravelCompany/TravelCompany/FormViewMail.cs +++ b/TravelCompany/TravelCompany/FormViewMail.cs @@ -27,15 +27,8 @@ namespace TravelCompany.Forms { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["MessageId"].Visible = false; - dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка списка писем"); + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка списка писем"); } catch (Exception ex) { diff --git a/TravelCompany/TravelCompany/ImplementersForm.cs b/TravelCompany/TravelCompany/ImplementersForm.cs index bcef90a..f5d947e 100644 --- a/TravelCompany/TravelCompany/ImplementersForm.cs +++ b/TravelCompany/TravelCompany/ImplementersForm.cs @@ -33,22 +33,9 @@ namespace TravelCompany.Forms { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView1.DataSource = list; - dataGridView1.Columns["Id"].Visible = false; - dataGridView1.Columns["ImplementerFIO"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - dataGridView1.Columns["Password"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - dataGridView1.Columns["Qualification"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - dataGridView1.Columns["WorkExperience"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка компонентов"); - } + dataGridView1.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка исполнителей"); + } catch (Exception ex) { _logger.LogError(ex, "Ошибка загрузки исполнителей"); diff --git a/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDatabaseImplement.csproj b/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDatabaseImplement.csproj index f023f35..196f97c 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDatabaseImplement.csproj +++ b/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDatabaseImplement.csproj @@ -19,4 +19,8 @@ + + + + diff --git a/TravelCompany/TravelCompanyFileImplement/DataFileSingleton.cs b/TravelCompany/TravelCompanyFileImplement/DataFileSingleton.cs index 34021a5..eecd3a9 100644 --- a/TravelCompany/TravelCompanyFileImplement/DataFileSingleton.cs +++ b/TravelCompany/TravelCompanyFileImplement/DataFileSingleton.cs @@ -16,12 +16,15 @@ namespace TravelCompanyFileImplement private readonly string TravelFileName = "Travel.xml"; private readonly string ClientFileName = "Client.xml"; private readonly string ImplementerFileName = "Implementer.xml"; + private readonly string MessageInfoFileName = "MessageInfo.xml"; public List Components { get; private set; } public List Orders { get; private set; } public List Travels { 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() { @@ -38,6 +41,8 @@ namespace TravelCompanyFileImplement "Clients", x => x.GetXElement); public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement); + public void SaveMessages() => SaveData(Orders, ImplementerFileName, "Messages", x => x.GetXElement); + private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; @@ -47,6 +52,8 @@ namespace TravelCompanyFileImplement Client.Create(x)!)!; Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!; + Messages = LoadData(MessageInfoFileName, "MessageInfo", x => MessageInfo.Create(x)!)!; + } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) { diff --git a/TravelCompany/TravelCompanyFileImplement/ImplementationExtension.cs b/TravelCompany/TravelCompanyFileImplement/ImplementationExtension.cs new file mode 100644 index 0000000..a9d45d9 --- /dev/null +++ b/TravelCompany/TravelCompanyFileImplement/ImplementationExtension.cs @@ -0,0 +1,22 @@ +using TravelCompanyContracts.DI; +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyFileImplement.Implements; + +namespace TravelCompanyFileImplement +{ + public class ImplementationExtension : IImplementationExtension + { + public int Priority => 1; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/TravelCompany/TravelCompanyFileImplement/Implements/BackUpInfo.cs b/TravelCompany/TravelCompanyFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..d9d396f --- /dev/null +++ b/TravelCompany/TravelCompanyFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,39 @@ +using TravelCompanyContracts.StoragesContracts; +using System.Reflection; + +namespace TravelCompanyFileImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + private readonly DataFileSingleton source; + private readonly PropertyInfo[] sourceProperties; + + public BackUpInfo() + { + source = DataFileSingleton.GetInstance(); + sourceProperties = source.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); + } + + public List? GetList() where T : class, new() + { + var requredType = typeof(T); + return (List?)sourceProperties.FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == requredType) + ?.GetValue(source); + + } + + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + var assembly = typeof(BackUpInfo).Assembly; + var types = assembly.GetTypes(); + foreach (var type in types) + { + if (type.IsClass && type.GetInterface(modelInterfaceName) != null) + { + return type; + } + } + return null; + } + } +} diff --git a/TravelCompany/TravelCompanyFileImplement/Implements/MessageInfoStorage.cs b/TravelCompany/TravelCompanyFileImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..b9b3b33 --- /dev/null +++ b/TravelCompany/TravelCompanyFileImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,58 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyContracts.ViewModels; +using TravelCompanyFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyFileImplement.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; + } + } +} diff --git a/TravelCompany/TravelCompanyFileImplement/Models/Client.cs b/TravelCompany/TravelCompanyFileImplement/Models/Client.cs index 226b29d..1e93e22 100644 --- a/TravelCompany/TravelCompanyFileImplement/Models/Client.cs +++ b/TravelCompany/TravelCompanyFileImplement/Models/Client.cs @@ -9,14 +9,21 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; +using System.Runtime.Serialization; namespace TravelCompanyFileImplement.Models { + [DataContract] + public class Client : IClientModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string ClientFIO { get; private set; } = string.Empty; + [DataMember] public string Email { get; set; } = string.Empty; + [DataMember] public string Password { get; set; } = string.Empty; public static Client? Create(ClientBindingModel model) { diff --git a/TravelCompany/TravelCompanyFileImplement/Models/Component.cs b/TravelCompany/TravelCompanyFileImplement/Models/Component.cs index 0a39648..4d778b1 100644 --- a/TravelCompany/TravelCompanyFileImplement/Models/Component.cs +++ b/TravelCompany/TravelCompanyFileImplement/Models/Component.cs @@ -7,13 +7,18 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; +using System.Runtime.Serialization; namespace TravelCompanyFileImplement.Models { + [DataContract] public class Component : IComponentModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string ComponentName { get; private set; } = string.Empty; + [DataMember] public double Cost { get; set; } public static Component? Create(ComponentBindingModel model) { diff --git a/TravelCompany/TravelCompanyFileImplement/Models/Implementer.cs b/TravelCompany/TravelCompanyFileImplement/Models/Implementer.cs index f08719d..5b70e68 100644 --- a/TravelCompany/TravelCompanyFileImplement/Models/Implementer.cs +++ b/TravelCompany/TravelCompanyFileImplement/Models/Implementer.cs @@ -7,17 +7,24 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; +using System.Runtime.Serialization; namespace TravelCompanyFileImplement.Models { - public class Implementer : IImplementerModel + [DataContract] + public class Implementer : IImplementerModel { - public int Id { get; private set; } - public string ImplementerFIO { get; private set; } = string.Empty; - public string Password { get; set; } = string.Empty; - public int Qualification { get; set; } = 0; - public int WorkExperience { get; set; } = 0; - public static Implementer? Create(ImplementerBindingModel model) + [DataMember] + public int Id { get; private set; } + [DataMember] + public string ImplementerFIO { get; private set; } = string.Empty; + [DataMember] + public string Password { get; set; } = string.Empty; + [DataMember] + public int Qualification { get; set; } = 0; + [DataMember] + public int WorkExperience { get; set; } = 0; + public static Implementer? Create(ImplementerBindingModel model) { if (model == null) { diff --git a/TravelCompany/TravelCompanyFileImplement/Models/MessageInfo.cs b/TravelCompany/TravelCompanyFileImplement/Models/MessageInfo.cs new file mode 100644 index 0000000..9be812f --- /dev/null +++ b/TravelCompany/TravelCompanyFileImplement/Models/MessageInfo.cs @@ -0,0 +1,91 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.ViewModels; +using TravelCompanyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace TravelCompanyFileImplement.Models +{ + [DataContract] + public class MessageInfo : IMessageInfoModel + { + [DataMember] + public int Id { get; private set; } + + [DataMember] + public string MessageId { get; private set; } = string.Empty; + + [DataMember] + public int? ClientId { get; private set; } + + [DataMember] + public string SenderName { get; private set; } = string.Empty; + + [DataMember] + public DateTime DateDelivery { get; private set; } = DateTime.Now; + + [DataMember] + public string Subject { get; private set; } = string.Empty; + + [DataMember] + public string Body { get; private set; } = string.Empty; + + public static MessageInfo? Create(MessageInfoBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Body = model.Body, + Subject = model.Subject, + ClientId = model.ClientId, + MessageId = model.MessageId, + SenderName = model.SenderName, + DateDelivery = model.DateDelivery, + }; + } + + public static MessageInfo? Create(XElement element) + { + if (element == null) + { + return null; + } + 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), + }; + } + + public MessageInfoViewModel GetViewModel => new() + { + Body = Body, + Subject = Subject, + ClientId = ClientId, + MessageId = MessageId, + SenderName = SenderName, + DateDelivery = DateDelivery, + }; + + 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) + ); + } +} diff --git a/TravelCompany/TravelCompanyFileImplement/Models/Order.cs b/TravelCompany/TravelCompanyFileImplement/Models/Order.cs index 1bfed3e..51ce9ed 100644 --- a/TravelCompany/TravelCompanyFileImplement/Models/Order.cs +++ b/TravelCompany/TravelCompanyFileImplement/Models/Order.cs @@ -8,23 +8,34 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; +using System.Runtime.Serialization; namespace TravelCompanyFileImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int TravelId { get; private set; } + [DataMember] public int ClientId { get; private set; } + [DataMember] public int? ImplementerId { get; private set; } = null; + [DataMember] public int Count { get; private set; } + [DataMember] public double Sum { get; private set; } + [DataMember] - public OrderStatus Status { get; private set; } + public OrderStatus Status { get; private set; } + [DataMember] public DateTime DateCreate { get; private set; } + [DataMember] public DateTime? DateImplement { get; private set; } + [DataMember] public int Id { get; private set; } diff --git a/TravelCompany/TravelCompanyFileImplement/Models/Travel.cs b/TravelCompany/TravelCompanyFileImplement/Models/Travel.cs index a493ee4..14d2ea8 100644 --- a/TravelCompany/TravelCompanyFileImplement/Models/Travel.cs +++ b/TravelCompany/TravelCompanyFileImplement/Models/Travel.cs @@ -7,13 +7,18 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; +using System.Runtime.Serialization; namespace TravelCompanyFileImplement.Models { + [DataContract] public class Travel : ITravelModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string TravelName { get; private set; } = string.Empty; + [DataMember] public double Price { get; private set; } public Dictionary Components { get; private set; } = new(); private Dictionary? _TravelComponents = null; diff --git a/TravelCompany/TravelCompanyFileImplement/TravelCompanyFileImplement.csproj b/TravelCompany/TravelCompanyFileImplement/TravelCompanyFileImplement.csproj index 2cf28e6..b82f8d5 100644 --- a/TravelCompany/TravelCompanyFileImplement/TravelCompanyFileImplement.csproj +++ b/TravelCompany/TravelCompanyFileImplement/TravelCompanyFileImplement.csproj @@ -11,4 +11,9 @@ + + + + + diff --git a/TravelCompany/TravelCompanyListImplement/DataListSingleton.cs b/TravelCompany/TravelCompanyListImplement/DataListSingleton.cs index fff14df..cebcc42 100644 --- a/TravelCompany/TravelCompanyListImplement/DataListSingleton.cs +++ b/TravelCompany/TravelCompanyListImplement/DataListSingleton.cs @@ -15,6 +15,8 @@ namespace TravelCompanyListImplement public List Travels { get; set; } public List Clients { get; set; } public List Implementers { get; set; } + public List Messages { get; set; } + private DataListSingleton() { @@ -23,6 +25,8 @@ namespace TravelCompanyListImplement Travels = new List(); Clients = new List(); Implementers = new List(); + Messages = new List(); + } public static DataListSingleton GetInstance() diff --git a/TravelCompany/TravelCompanyListImplement/ImplementationExtension.cs b/TravelCompany/TravelCompanyListImplement/ImplementationExtension.cs new file mode 100644 index 0000000..95dcb49 --- /dev/null +++ b/TravelCompany/TravelCompanyListImplement/ImplementationExtension.cs @@ -0,0 +1,27 @@ +using TravelCompanyContracts.DI; +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyListImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyListImplement +{ + internal class ImplementationExtension : IImplementationExtension + { + public int Priority => 0; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/TravelCompany/TravelCompanyListImplement/Implements/BackUpInfo.cs b/TravelCompany/TravelCompanyListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..f7a7223 --- /dev/null +++ b/TravelCompany/TravelCompanyListImplement/Implements/BackUpInfo.cs @@ -0,0 +1,22 @@ +using TravelCompanyContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyListImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + throw new NotImplementedException(); + } + + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + throw new NotImplementedException(); + } + } +} diff --git a/TravelCompany/TravelCompanyListImplement/Implements/MessageInfoStorage.cs b/TravelCompany/TravelCompanyListImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..b72b775 --- /dev/null +++ b/TravelCompany/TravelCompanyListImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,68 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyContracts.ViewModels; +using TravelCompanyListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyListImplement.Implements +{ + public class MessageInfoStorage : IMessageInfoStorage + { + private readonly DataListSingleton _source; + public MessageInfoStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + List result = new(); + foreach (var item in _source.Messages) + { + result.Add(item.GetViewModel); + } + return result; + } + + public List GetFilteredList(MessageInfoSearchModel model) + { + List result = new(); + foreach (var item in _source.Messages) + { + if (item.ClientId.HasValue && item.ClientId == model.ClientId) + { + result.Add(item.GetViewModel); + } + } + return result; + } + + public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) + { + foreach (var message in _source.Messages) + { + if (model.MessageId != null && model.MessageId.Equals(message.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/TravelCompany/TravelCompanyListImplement/Models/MessageInfo.cs b/TravelCompany/TravelCompanyListImplement/Models/MessageInfo.cs new file mode 100644 index 0000000..13ba2f7 --- /dev/null +++ b/TravelCompany/TravelCompanyListImplement/Models/MessageInfo.cs @@ -0,0 +1,55 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.ViewModels; +using TravelCompanyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyListImplement.Models +{ + public class MessageInfo : IMessageInfoModel + { + public string MessageId { get; private set; } = string.Empty; + + public int? ClientId { get; private set; } + + public string SenderName { get; private set; } = string.Empty; + + public DateTime DateDelivery { get; private set; } = DateTime.Now; + + public string Subject { get; private set; } = string.Empty; + + public string Body { get; private set; } = string.Empty; + + public int Id => throw new NotImplementedException(); + + public static MessageInfo? Create(MessageInfoBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Body = model.Body, + Subject = model.Subject, + ClientId = model.ClientId, + MessageId = model.MessageId, + SenderName = model.SenderName, + DateDelivery = model.DateDelivery, + }; + } + + public MessageInfoViewModel GetViewModel => new() + { + Body = Body, + Subject = Subject, + ClientId = ClientId, + MessageId = MessageId, + SenderName = SenderName, + DateDelivery = DateDelivery, + }; + } +} diff --git a/TravelCompany/TravelCompanyListImplement/TravelCompanyListImplement.csproj b/TravelCompany/TravelCompanyListImplement/TravelCompanyListImplement.csproj index 9ba85b1..1a8d931 100644 --- a/TravelCompany/TravelCompanyListImplement/TravelCompanyListImplement.csproj +++ b/TravelCompany/TravelCompanyListImplement/TravelCompanyListImplement.csproj @@ -11,4 +11,8 @@ + + + +