From d3343f2964562d4cbf402f79ae959bdd4ba01f02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A4=D0=B5=D0=B4?= =?UTF-8?q?=D0=BE=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Sat, 27 Apr 2024 23:00:03 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=83=20=D0=BF=D1=83=20=D0=BF=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/CaseLogic.cs | 3 +- .../BusinessLogics/ClientLogic.cs | 4 +- .../BusinessLogics/VisitLogic.cs | 3 +- .../BindingModels/CaseBindingModel.cs | 1 + .../BindingModels/ClientBindingModel.cs | 1 + .../BindingModels/VisitBindingModel.cs | 1 + .../SearchModels/CaseSearchModel.cs | 1 + .../SearchModels/ClientSearchModel.cs | 1 + .../SearchModels/VisitSearchModel.cs | 1 + .../ViewModels/CaseViewModel.cs | 1 + .../ViewModels/ClientViewModel.cs | 1 + .../ViewModels/VisitViewModel.cs | 1 + .../Implements/CaseStorage.cs | 22 +++++-- .../Implements/ClientStorage.cs | 26 ++++++-- .../Implements/VisitStorage.cs | 60 ++++++++++++------- .../LawFirmDatabaseImplement/Models/Case.cs | 6 +- .../LawFirmDatabaseImplement/Models/Client.cs | 4 ++ .../LawFirmDatabaseImplement/Models/Visit.cs | 9 +-- 18 files changed, 105 insertions(+), 41 deletions(-) diff --git a/LawFim/LawFirmBusinessLogic/BusinessLogics/CaseLogic.cs b/LawFim/LawFirmBusinessLogic/BusinessLogics/CaseLogic.cs index 877b157..05ab225 100644 --- a/LawFim/LawFirmBusinessLogic/BusinessLogics/CaseLogic.cs +++ b/LawFim/LawFirmBusinessLogic/BusinessLogics/CaseLogic.cs @@ -135,7 +135,8 @@ namespace LawFirmBusinessLogic.BusinessLogics Name = element.Name, DateCreate = element.DateCreate, Status = element.Status, - CaseClients = element.CaseClients + CaseClients = element.CaseClients, + ExecutorId = element.ExecutorId, }); return true; diff --git a/LawFim/LawFirmBusinessLogic/BusinessLogics/ClientLogic.cs b/LawFim/LawFirmBusinessLogic/BusinessLogics/ClientLogic.cs index 75da981..4f30153 100644 --- a/LawFim/LawFirmBusinessLogic/BusinessLogics/ClientLogic.cs +++ b/LawFim/LawFirmBusinessLogic/BusinessLogics/ClientLogic.cs @@ -141,8 +141,8 @@ namespace LawFirmBusinessLogic.BusinessLogics { FIO = model.FIO, Phone = model.Phone, - Email = model.Email - + Email = model.Email, + ExecutorId = model.ExecutorId, }); if (element != null && element.Id != model.Id) { diff --git a/LawFim/LawFirmBusinessLogic/BusinessLogics/VisitLogic.cs b/LawFim/LawFirmBusinessLogic/BusinessLogics/VisitLogic.cs index fe8669e..e4ef723 100644 --- a/LawFim/LawFirmBusinessLogic/BusinessLogics/VisitLogic.cs +++ b/LawFim/LawFirmBusinessLogic/BusinessLogics/VisitLogic.cs @@ -104,7 +104,8 @@ namespace LawFirmBusinessLogic.BusinessLogics Id = element.Id, VisitDate = element.VisitDate, HearingId = element.HearingId, - VisitClients = element.VisitClients + VisitClients = element.VisitClients, + ExecutorId = element.ExecutorId, }); return true; diff --git a/LawFim/LawFirmContracts/BindingModels/CaseBindingModel.cs b/LawFim/LawFirmContracts/BindingModels/CaseBindingModel.cs index 39df803..4bd4b4a 100644 --- a/LawFim/LawFirmContracts/BindingModels/CaseBindingModel.cs +++ b/LawFim/LawFirmContracts/BindingModels/CaseBindingModel.cs @@ -12,5 +12,6 @@ namespace LawFirmContracts.BindingModels public DateTime DateCreate { get; set; } public DateTime? DateImplement { get; set; } public Dictionary CaseClients { get; set; } = new(); + public int ExecutorId { get; set; } } } diff --git a/LawFim/LawFirmContracts/BindingModels/ClientBindingModel.cs b/LawFim/LawFirmContracts/BindingModels/ClientBindingModel.cs index 7df2dc1..596394c 100644 --- a/LawFim/LawFirmContracts/BindingModels/ClientBindingModel.cs +++ b/LawFim/LawFirmContracts/BindingModels/ClientBindingModel.cs @@ -8,5 +8,6 @@ namespace LawFirmContracts.BindingModels public string FIO { get; set; } = string.Empty; public string Phone { get; set; } = string.Empty; public string Email { get; set; } = string.Empty; + public int ExecutorId { get; set; } } } diff --git a/LawFim/LawFirmContracts/BindingModels/VisitBindingModel.cs b/LawFim/LawFirmContracts/BindingModels/VisitBindingModel.cs index e701744..1d9f972 100644 --- a/LawFim/LawFirmContracts/BindingModels/VisitBindingModel.cs +++ b/LawFim/LawFirmContracts/BindingModels/VisitBindingModel.cs @@ -8,5 +8,6 @@ namespace LawFirmContracts.BindingModels public DateTime VisitDate { get; set; } public int HearingId { get; set; } public Dictionary VisitClients { get; set; } = new(); + public int ExecutorId { get; set; } } } diff --git a/LawFim/LawFirmContracts/SearchModels/CaseSearchModel.cs b/LawFim/LawFirmContracts/SearchModels/CaseSearchModel.cs index 4ae6a92..557b44d 100644 --- a/LawFim/LawFirmContracts/SearchModels/CaseSearchModel.cs +++ b/LawFim/LawFirmContracts/SearchModels/CaseSearchModel.cs @@ -7,5 +7,6 @@ public string? CaseType { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } + public int? ExecutorId { get; set; } } } diff --git a/LawFim/LawFirmContracts/SearchModels/ClientSearchModel.cs b/LawFim/LawFirmContracts/SearchModels/ClientSearchModel.cs index 5a8ab7b..655c92b 100644 --- a/LawFim/LawFirmContracts/SearchModels/ClientSearchModel.cs +++ b/LawFim/LawFirmContracts/SearchModels/ClientSearchModel.cs @@ -6,5 +6,6 @@ public string? FIO { get; set; } public string? Phone { get; set; } public string? Email { get; set; } + public int? ExecutorId { get; set; } } } diff --git a/LawFim/LawFirmContracts/SearchModels/VisitSearchModel.cs b/LawFim/LawFirmContracts/SearchModels/VisitSearchModel.cs index d2cd17a..36bd712 100644 --- a/LawFim/LawFirmContracts/SearchModels/VisitSearchModel.cs +++ b/LawFim/LawFirmContracts/SearchModels/VisitSearchModel.cs @@ -7,5 +7,6 @@ public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } public int? HearingId { get; set; } + public int? ExecutorId { get; set; } } } diff --git a/LawFim/LawFirmContracts/ViewModels/CaseViewModel.cs b/LawFim/LawFirmContracts/ViewModels/CaseViewModel.cs index 80ed018..36c491c 100644 --- a/LawFim/LawFirmContracts/ViewModels/CaseViewModel.cs +++ b/LawFim/LawFirmContracts/ViewModels/CaseViewModel.cs @@ -18,5 +18,6 @@ namespace LawFirmContracts.ViewModels [DisplayName("Дата выполнения")] public DateTime? DateImplement { get; set; } public Dictionary CaseClients { get; set; } = new(); + public int ExecutorId { get; set; } } } diff --git a/LawFim/LawFirmContracts/ViewModels/ClientViewModel.cs b/LawFim/LawFirmContracts/ViewModels/ClientViewModel.cs index 45eefe2..a2b3d4d 100644 --- a/LawFim/LawFirmContracts/ViewModels/ClientViewModel.cs +++ b/LawFim/LawFirmContracts/ViewModels/ClientViewModel.cs @@ -12,5 +12,6 @@ namespace LawFirmContracts.ViewModels public string Email { get; set; } = string.Empty; [DisplayName("Телефон клиента")] public string Phone { get; set; } = string.Empty; + public int ExecutorId { get; set; } } } diff --git a/LawFim/LawFirmContracts/ViewModels/VisitViewModel.cs b/LawFim/LawFirmContracts/ViewModels/VisitViewModel.cs index 91a6274..62a4838 100644 --- a/LawFim/LawFirmContracts/ViewModels/VisitViewModel.cs +++ b/LawFim/LawFirmContracts/ViewModels/VisitViewModel.cs @@ -10,5 +10,6 @@ namespace LawFirmContracts.ViewModels public DateTime VisitDate { get; set; } public int HearingId { get; set; } public Dictionary VisitClients { get; set; } = new(); + public int ExecutorId { get; set; } } } diff --git a/LawFim/LawFirmDatabaseImplement/Implements/CaseStorage.cs b/LawFim/LawFirmDatabaseImplement/Implements/CaseStorage.cs index bdfd837..51cb514 100644 --- a/LawFim/LawFirmDatabaseImplement/Implements/CaseStorage.cs +++ b/LawFim/LawFirmDatabaseImplement/Implements/CaseStorage.cs @@ -13,23 +13,33 @@ namespace LawFirmDatabaseImplement.Implements { using var context = new LawFirmDatabase(); return context.Cases.Include(x => x.CaseClients) - .Include(x => x.Clients).ThenInclude(x => x.Client) + .Include(x => x.Clients).ThenInclude(x => x.Client) .ToList() .Select(x => x.GetViewModel) .ToList(); } public List GetFilteredList(CaseSearchModel model) { - if (!model.DateFrom.HasValue && !model.DateTo.HasValue) + if (!model.DateFrom.HasValue && !model.DateTo.HasValue + && !model.ExecutorId.HasValue) { return new(); } - if (!model.DateFrom.HasValue || !model.DateTo.HasValue) + if (model.ExecutorId.HasValue) + { + using var context = new LawFirmDatabase(); + return context.Cases + .Include(x => x.Clients).ThenInclude(x => x.Client) + .Where(x => x.ExecutorId == model.ExecutorId).ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + else if (!model.DateFrom.HasValue || !model.DateTo.HasValue) { using var context = new LawFirmDatabase(); return context.Cases.Include(x => x.CaseClients) - .Include(x => x.Clients).ThenInclude(x => x.Client) + .Include(x => x.Clients).ThenInclude(x => x.Client) .Where(x => x.Id == model.Id) .Select(x => x.GetViewModel).ToList() .ToList(); @@ -46,14 +56,14 @@ namespace LawFirmDatabaseImplement.Implements } public CaseViewModel? GetElement(CaseSearchModel model) { - if (!model.Id.HasValue && string.IsNullOrEmpty(model.Name)) + if (!model.Id.HasValue && !model.ExecutorId.HasValue && string.IsNullOrEmpty(model.Name)) { return null; } using var context = new LawFirmDatabase(); return context.Cases.Include(x => x.Clients).ThenInclude(x => x.Client) .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) - ?.GetViewModel; //имя дела не должно повторяться, уникальное должно быть + ?.GetViewModel; } public CaseViewModel? Insert(CaseBindingModel model) diff --git a/LawFim/LawFirmDatabaseImplement/Implements/ClientStorage.cs b/LawFim/LawFirmDatabaseImplement/Implements/ClientStorage.cs index 1e8be2b..4579c68 100644 --- a/LawFim/LawFirmDatabaseImplement/Implements/ClientStorage.cs +++ b/LawFim/LawFirmDatabaseImplement/Implements/ClientStorage.cs @@ -15,10 +15,11 @@ namespace LawFirmDatabaseImplement.Implements .Select(x => x.GetViewModel) .ToList(); } - public List GetFilteredList(ClientSearchModel model) + public List GetFilteredList(ClientSearchModel + model) { if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue && string.IsNullOrEmpty(model.FIO) - && string.IsNullOrEmpty(model.Phone)) + && string.IsNullOrEmpty(model.Phone) && !model.ExecutorId.HasValue) { return new(); } @@ -30,6 +31,22 @@ namespace LawFirmDatabaseImplement.Implements .Select(x => x.GetViewModel) .ToList(); } + else if (model.ExecutorId.HasValue && model.Id.HasValue) + { + using var context = new LawFirmDatabase(); + return context.Clients + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + else if (model.ExecutorId.HasValue) + { + using var context = new LawFirmDatabase(); + return context.Clients + .Where(x => x.ExecutorId == model.ExecutorId) + .Select(x => x.GetViewModel) + .ToList(); + } else { using var context = new LawFirmDatabase(); @@ -42,7 +59,7 @@ namespace LawFirmDatabaseImplement.Implements public ClientViewModel? GetElement(ClientSearchModel model) { if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue && string.IsNullOrEmpty(model.FIO) - && string.IsNullOrEmpty(model.Phone)) + && string.IsNullOrEmpty(model.Phone) && !model.ExecutorId.HasValue) { return null; } @@ -50,7 +67,8 @@ namespace LawFirmDatabaseImplement.Implements return context.Clients .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Email) - && x.Email == model.Email) || (model.Id.HasValue && x.Id == model.Id)) + && x.Email == model.Email) || (model.Id.HasValue && x.Id == model.Id) || (model.ExecutorId.HasValue + && x.ExecutorId == model.ExecutorId)) ?.GetViewModel; } public ClientViewModel? Insert(ClientBindingModel model) diff --git a/LawFim/LawFirmDatabaseImplement/Implements/VisitStorage.cs b/LawFim/LawFirmDatabaseImplement/Implements/VisitStorage.cs index aba6a17..8318727 100644 --- a/LawFim/LawFirmDatabaseImplement/Implements/VisitStorage.cs +++ b/LawFim/LawFirmDatabaseImplement/Implements/VisitStorage.cs @@ -13,7 +13,7 @@ namespace LawFirmDatabaseImplement.Implements { using var context = new LawFirmDatabase(); return context.Visits - .Include(x => x.Clients) + .Include(x => x.Clients) .ThenInclude(x => x.Client) .ToList() .Select(x => x.GetViewModel) @@ -21,38 +21,30 @@ namespace LawFirmDatabaseImplement.Implements } public List GetFilteredList(VisitSearchModel model) { - if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue + if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ExecutorId.HasValue && !model.VisitDate.HasValue && !model.HearingId.HasValue) { return new(); } - if (!model.DateFrom.HasValue || !model.DateTo.HasValue) + if (model.ExecutorId.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue) { using var context = new LawFirmDatabase(); return context.Visits - .Include(x => x.Clients).ThenInclude(x => x.Client) - .Where(x => x.Id == model.Id) + .Include(x => x.Clients).ThenInclude(x => x.Client) + .Where(x => x.ExecutorId == model.ExecutorId && x.VisitDate >= model.DateFrom && x.VisitDate <= model.DateTo) .Select(x => x.GetViewModel) .ToList(); } - else + else if (model.ExecutorId.HasValue) { using var context = new LawFirmDatabase(); return context.Visits - .Include(x => x.Clients).ThenInclude(x => x.Client) - .Where(x => x.VisitDate >= model.DateFrom && x.VisitDate <= model.DateTo) + .Include(x => x.Clients).ThenInclude(x => x.Client) + .Where(x => x.ExecutorId == model.ExecutorId) .Select(x => x.GetViewModel) .ToList(); } - } - public List GetFilteredDateList(VisitSearchModel model) - { - if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue) - { - return new(); - } - - if (!model.DateFrom.HasValue || !model.DateTo.HasValue) + else if (!model.DateFrom.HasValue || !model.DateTo.HasValue) { using var context = new LawFirmDatabase(); return context.Visits @@ -71,16 +63,44 @@ namespace LawFirmDatabaseImplement.Implements .ToList(); } } + public List GetFilteredDateList(VisitSearchModel model) + { + if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ExecutorId.HasValue) + { + return new(); + } + + if (!model.DateFrom.HasValue || !model.DateTo.HasValue) + { + using var context = new LawFirmDatabase(); + return context.Visits + .Include(x => x.Clients).ThenInclude(x => x.Client) + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + else + { + using var context = new LawFirmDatabase(); + return context.Visits + .Include(x => x.Clients).ThenInclude(x => x.Client) + .Where(x => x.VisitDate >= model.DateFrom && x.VisitDate <= model.DateTo) + .Select(x => x.GetViewModel) + .ToList(); + } + } public VisitViewModel? GetElement(VisitSearchModel model) { - if (!model.Id.HasValue && !model.VisitDate.HasValue && !model.HearingId.HasValue) + if (!model.Id.HasValue && !model.ExecutorId.HasValue + && !model.VisitDate.HasValue && !model.HearingId.HasValue) { return new(); } using var context = new LawFirmDatabase(); return context.Visits.Include(x => x.Clients).ThenInclude(x => x.Client) - .FirstOrDefault(x => (model.HearingId.HasValue && x.Hearing == model.HearingId) - || (model.Id.HasValue && x.Id == model.Id)) + .FirstOrDefault(x => (model.HearingId.HasValue && x.HearingId == model.HearingId) || (model.Id.HasValue + && x.Id == model.Id) || (model.ExecutorId.HasValue + && x.ExecutorId == model.ExecutorId)) ?.GetViewModel; } public VisitViewModel? Insert(VisitBindingModel model) diff --git a/LawFim/LawFirmDatabaseImplement/Models/Case.cs b/LawFim/LawFirmDatabaseImplement/Models/Case.cs index 072e7db..207175c 100644 --- a/LawFim/LawFirmDatabaseImplement/Models/Case.cs +++ b/LawFim/LawFirmDatabaseImplement/Models/Case.cs @@ -20,6 +20,7 @@ namespace LawFirmDatabaseImplement.Models [Required] public CaseStatus Status { get; private set; } private Dictionary? _caseClients = null; + public int ExecutorId { get; set; } [NotMapped] public Dictionary CaseClients @@ -38,8 +39,6 @@ namespace LawFirmDatabaseImplement.Models } [ForeignKey("CaseId")] public virtual List Clients { get; set; } = new(); - [ForeignKey("CaseId")] - public virtual List Hearings { get; set; } = new(); public static Case Create(LawFirmDatabase context, CaseBindingModel model) { if (model == null) @@ -53,6 +52,7 @@ namespace LawFirmDatabaseImplement.Models DateCreate = model.DateCreate, DateImplement = model.DateImplement, Status = model.Status, + ExecutorId = model.ExecutorId, Clients = model.CaseClients.Select(x => new CaseClient { Client = context.Clients.First(y => y.Id == x.Key) @@ -72,7 +72,6 @@ namespace LawFirmDatabaseImplement.Models if (model.DateImplement.HasValue) DateImplement = model.DateImplement; - if (!model.CompanyId.HasValue) CompanyId = model.CompanyId; } public CaseViewModel GetViewModel => new() { @@ -81,6 +80,7 @@ namespace LawFirmDatabaseImplement.Models CaseType = CaseType, DateCreate = DateCreate, DateImplement = DateImplement, + ExecutorId = ExecutorId, Status = Status, CaseClients = CaseClients, }; diff --git a/LawFim/LawFirmDatabaseImplement/Models/Client.cs b/LawFim/LawFirmDatabaseImplement/Models/Client.cs index 7e9157c..3ef1b37 100644 --- a/LawFim/LawFirmDatabaseImplement/Models/Client.cs +++ b/LawFim/LawFirmDatabaseImplement/Models/Client.cs @@ -19,6 +19,7 @@ namespace LawFirmDatabaseImplement.Models public virtual List CaseClients { get; set; } = new(); [ForeignKey("ClientId")] public virtual List ClientVisits { get; set; } = new(); + public int ExecutorId { get; set; } public static Client? Create(ClientBindingModel? model) { @@ -32,6 +33,7 @@ namespace LawFirmDatabaseImplement.Models FIO = model.FIO, Email = model.Email, Phone = model.Phone, + ExecutorId = model.ExecutorId, }; } public static Client Create(ClientViewModel model) @@ -42,6 +44,7 @@ namespace LawFirmDatabaseImplement.Models FIO = model.FIO, Email = model.Email, Phone = model.Phone, + ExecutorId = model.ExecutorId, }; } public void Update(ClientBindingModel? model) @@ -60,6 +63,7 @@ namespace LawFirmDatabaseImplement.Models FIO = FIO, Email = Email, Phone = Phone, + ExecutorId = ExecutorId, }; } } diff --git a/LawFim/LawFirmDatabaseImplement/Models/Visit.cs b/LawFim/LawFirmDatabaseImplement/Models/Visit.cs index 15fab75..99d51ac 100644 --- a/LawFim/LawFirmDatabaseImplement/Models/Visit.cs +++ b/LawFim/LawFirmDatabaseImplement/Models/Visit.cs @@ -16,7 +16,7 @@ namespace LawFirmDatabaseImplement.Models public int HearingId { get; private set; } public Hearing Hearing { get; set; } = null!; //--- - public int? CompanyId { get; set; } + public int ExecutorId { get; set; } private Dictionary? _visitClients = null; [NotMapped] @@ -37,8 +37,7 @@ namespace LawFirmDatabaseImplement.Models } [ForeignKey("VisitId")] public virtual List Clients { get; set; } = new(); - public static Visit? Create(LawFirmDatabase context, - VisitBindingModel? model) + public static Visit? Create(LawFirmDatabase context, VisitBindingModel? model) { if (model == null) { @@ -54,6 +53,7 @@ namespace LawFirmDatabaseImplement.Models Id = model.Id, VisitDate = model.VisitDate, HearingId = model.HearingId, + ExecutorId = model.ExecutorId, Hearing = context.Hearings.First(x => x.Id == model.HearingId), Clients = model.VisitClients.Select(x => new VisitClient { @@ -78,7 +78,8 @@ namespace LawFirmDatabaseImplement.Models Id = Id, VisitDate = VisitDate, HearingId = HearingId, - VisitClients = VisitClients + VisitClients = VisitClients, + ExecutorId = ExecutorId, }; public void UpdateClients(LawFirmDatabase context, VisitBindingModel model)