diff --git a/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Models/IMessageInfoModel.cs b/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Models/IMessageInfoModel.cs new file mode 100644 index 0000000..729b46b --- /dev/null +++ b/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Models/IMessageInfoModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmDataModels.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/LawFirm/AbstractLawFirmFileImpliment/DataFileSingleton.cs b/LawFirm/AbstractLawFirmFileImpliment/DataFileSingleton.cs index 98e142b..4cfa47e 100644 --- a/LawFirm/AbstractLawFirmFileImpliment/DataFileSingleton.cs +++ b/LawFirm/AbstractLawFirmFileImpliment/DataFileSingleton.cs @@ -14,9 +14,11 @@ namespace AbstractLawFirmFileImpliment private readonly string ComponentFileName = "Component.xml"; private readonly string OrderFileName = "Order.xml"; private readonly string DocumentFileName = "Document.xml"; + private readonly string ImplementerFileName = "Implementer.xml"; public List Components { get; private set; } public List Orders { get; private set; } public List Documents { get; private set; } + public List Implementers { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -31,11 +33,14 @@ namespace AbstractLawFirmFileImpliment "Documents", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, + "Implementers", x => x.GetXElement); private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Documents = LoadData(DocumentFileName, "Document", x => Document.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, diff --git a/LawFirm/AbstractLawFirmFileImpliment/Implements/ImplementerStorage.cs b/LawFirm/AbstractLawFirmFileImpliment/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..b0f8be3 --- /dev/null +++ b/LawFirm/AbstractLawFirmFileImpliment/Implements/ImplementerStorage.cs @@ -0,0 +1,85 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.StoragesContracts; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmFileImplement.Models; +using AbstractLawFirmFileImpliment; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmFileImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataFileSingleton _source; + public ImplementerStorage() + { + _source = DataFileSingleton.GetInstance(); + } + 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 List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + if (model.ImplementerFIO != null) + { + return _source.Implementers + .Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); + } + + public List GetFullList() + { + return _source.Implementers.Select(x => x.GetViewModel).ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = _source.Implementers.Count > 0 ? _source.Implementers.Max(x => x.Id) + 1 : 1; + var res = Implementer.Create(model); + if (res != null) + { + _source.Implementers.Add(res); + _source.SaveImplementers(); + } + 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; + } + } +} diff --git a/LawFirm/AbstractLawFirmFileImpliment/Implements/OrderStorage.cs b/LawFirm/AbstractLawFirmFileImpliment/Implements/OrderStorage.cs index 2a873f3..936b857 100644 --- a/LawFirm/AbstractLawFirmFileImpliment/Implements/OrderStorage.cs +++ b/LawFirm/AbstractLawFirmFileImpliment/Implements/OrderStorage.cs @@ -27,16 +27,29 @@ namespace AbstractLawFirmFileImplement.Implements { return null; } - return GetViewModel(source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))); + return source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue) + if (model.ClientId.HasValue) { - return new(); + return source.Orders + .Where(x => x.ClientId == model.ClientId) + .Select(x => x.GetViewModel) + .ToList(); } - return source.Orders.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo).Select(x => x.GetViewModel).ToList(); + if (model.Status != null) + { + return source.Orders + .Where(x => model.Status.Equals(x.Status)) + .Select(x => x.GetViewModel) + .ToList(); + } + return source.Orders + .Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo) + .Select(x => x.GetViewModel) + .ToList(); } public List GetFullList() diff --git a/LawFirm/AbstractLawFirmFileImpliment/Models/Implementer.cs b/LawFirm/AbstractLawFirmFileImpliment/Models/Implementer.cs new file mode 100644 index 0000000..d93da70 --- /dev/null +++ b/LawFirm/AbstractLawFirmFileImpliment/Models/Implementer.cs @@ -0,0 +1,87 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace AbstractLawFirmFileImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + public static Implementer? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ImplementerFIO = element.Element("FIO")!.Value, + Password = element.Element("Password")!.Value, + Qualification = Convert.ToInt32(element.Element("Qualification")!.Value), + WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value), + }; + } + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + Qualification = model.Qualification, + WorkExperience = model.WorkExperience, + }; + } + + + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + Qualification = model.Qualification; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + Qualification = Qualification, + }; + + public XElement GetXElement => new("Client", + new XAttribute("Id", Id), + new XElement("FIO", ImplementerFIO), + new XElement("Password", Password), + new XElement("Qualification", Qualification), + new XElement("WorkExperience", WorkExperience) + ); + } +} diff --git a/LawFirm/AbstractLawFirmFileImpliment/Models/Order.cs b/LawFirm/AbstractLawFirmFileImpliment/Models/Order.cs index cfb1552..4e8fbbe 100644 --- a/LawFirm/AbstractLawFirmFileImpliment/Models/Order.cs +++ b/LawFirm/AbstractLawFirmFileImpliment/Models/Order.cs @@ -2,6 +2,7 @@ using AbstractLawFirmContracts.ViewModels; using AbstractLawFirmDataModels.Enums; using AbstractLawFirmDataModels.Models; +using AbstractLawFirmFileImpliment; using System; using System.Collections.Generic; using System.Diagnostics; @@ -17,6 +18,7 @@ namespace AbstractLawFirmFileImplement.Models public int Id { get; private set; } public int DocumentId { get; private set; } public int ClientId { get; private set; } + public int? ImplementerId { get; set; } public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; @@ -32,6 +34,8 @@ namespace AbstractLawFirmFileImplement.Models { Id = model.Id, DocumentId = model.DocumentId, + ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -49,6 +53,8 @@ namespace AbstractLawFirmFileImplement.Models { Id = Convert.ToInt32(element.Attribute("Id")!.Value), DocumentId = Convert.ToInt32(element.Element("DocumentId")!.Value), + ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), + ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value), Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), @@ -64,6 +70,7 @@ namespace AbstractLawFirmFileImplement.Models } Id = model.Id; DocumentId = model.DocumentId; + ImplementerId = model.ImplementerId; Count = model.Count; Sum = model.Sum; Status = model.Status; @@ -74,6 +81,8 @@ namespace AbstractLawFirmFileImplement.Models { Id = Id, DocumentId = DocumentId, + ClientId = ClientId, + ImplementerId = ImplementerId, Count = Count, Sum = Sum, Status = Status, @@ -85,6 +94,8 @@ namespace AbstractLawFirmFileImplement.Models "Order", new XAttribute("Id", Id), new XElement("DocumentId", DocumentId.ToString()), + new XElement("ClientId", ClientId), + new XElement("ImplementerId", ImplementerId), new XElement("Count", Count.ToString()), new XElement("Sum", Sum.ToString()), new XElement("Status", Status.ToString()), diff --git a/LawFirm/LawFirmView/App.config b/LawFirm/LawFirmView/App.config new file mode 100644 index 0000000..c4f7e76 --- /dev/null +++ b/LawFirm/LawFirmView/App.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file