From 53a5d68e7c64a2d431d64abb65a592dd455e1da7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BE=D1=84=D1=8C=D1=8F=20=D0=AF=D0=BA=D0=BE=D0=B1?= =?UTF-8?q?=D1=87=D1=83=D0=BA?= Date: Wed, 1 May 2024 15:08:34 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=BD=D0=B5=D0=BC=D0=BD=D0=BE=D0=B3=D0=BE?= =?UTF-8?q?=20=D0=BD=D0=B0=D0=BF=D0=B5=D1=80=D1=91=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/CaseLogic.cs | 3 +- .../BusinessLogics/ClientLogic.cs | 3 +- .../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 | 23 ++++--- .../Implements/ClientStorage.cs | 23 ++++++- .../Implements/VisitStorage.cs | 60 ++++++++++++------- .../Models/Case.cs | 6 +- .../Models/Client.cs | 4 ++ .../Models/Visit.cs | 9 +-- 18 files changed, 103 insertions(+), 40 deletions(-) diff --git a/LawCompany/LawCompanyBusinessLogic/BusinessLogics/CaseLogic.cs b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/CaseLogic.cs index 4ba768d..a4bb738 100644 --- a/LawCompany/LawCompanyBusinessLogic/BusinessLogics/CaseLogic.cs +++ b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/CaseLogic.cs @@ -135,7 +135,8 @@ namespace LawCompanyBusinessLogic.BusinessLogics Name = element.Name, DateCreate = element.DateCreate, Status = element.Status, - CaseClients = element.CaseClients + CaseClients = element.CaseClients, + ExecutorId = element.ExecutorId, }); return true; diff --git a/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ClientLogic.cs b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ClientLogic.cs index 202ba3b..8569c90 100644 --- a/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ClientLogic.cs +++ b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ClientLogic.cs @@ -141,7 +141,8 @@ namespace LawCompanyBusinessLogic.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/LawCompany/LawCompanyBusinessLogic/BusinessLogics/VisitLogic.cs b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/VisitLogic.cs index c52b0eb..de86834 100644 --- a/LawCompany/LawCompanyBusinessLogic/BusinessLogics/VisitLogic.cs +++ b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/VisitLogic.cs @@ -104,7 +104,8 @@ namespace LawCompanyBusinessLogic.BusinessLogics Id = element.Id, VisitDate = element.VisitDate, HearingId = element.HearingId, - VisitClients = element.VisitClients + VisitClients = element.VisitClients, + ExecutorId = element.ExecutorId, }); return true; diff --git a/LawCompany/LawCompanyContracts/BindingModels/CaseBindingModel.cs b/LawCompany/LawCompanyContracts/BindingModels/CaseBindingModel.cs index 27973fb..4ad97c4 100644 --- a/LawCompany/LawCompanyContracts/BindingModels/CaseBindingModel.cs +++ b/LawCompany/LawCompanyContracts/BindingModels/CaseBindingModel.cs @@ -12,5 +12,6 @@ namespace LawCompanyContracts.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/LawCompany/LawCompanyContracts/BindingModels/ClientBindingModel.cs b/LawCompany/LawCompanyContracts/BindingModels/ClientBindingModel.cs index c7b9335..ecec925 100644 --- a/LawCompany/LawCompanyContracts/BindingModels/ClientBindingModel.cs +++ b/LawCompany/LawCompanyContracts/BindingModels/ClientBindingModel.cs @@ -8,5 +8,6 @@ namespace LawCompanyContracts.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/LawCompany/LawCompanyContracts/BindingModels/VisitBindingModel.cs b/LawCompany/LawCompanyContracts/BindingModels/VisitBindingModel.cs index 126f30a..45d4470 100644 --- a/LawCompany/LawCompanyContracts/BindingModels/VisitBindingModel.cs +++ b/LawCompany/LawCompanyContracts/BindingModels/VisitBindingModel.cs @@ -8,5 +8,6 @@ namespace LawCompanyContracts.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/LawCompany/LawCompanyContracts/SearchModels/CaseSearchModel.cs b/LawCompany/LawCompanyContracts/SearchModels/CaseSearchModel.cs index bba0142..0a9ce15 100644 --- a/LawCompany/LawCompanyContracts/SearchModels/CaseSearchModel.cs +++ b/LawCompany/LawCompanyContracts/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/LawCompany/LawCompanyContracts/SearchModels/ClientSearchModel.cs b/LawCompany/LawCompanyContracts/SearchModels/ClientSearchModel.cs index 987fc34..ca49891 100644 --- a/LawCompany/LawCompanyContracts/SearchModels/ClientSearchModel.cs +++ b/LawCompany/LawCompanyContracts/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/LawCompany/LawCompanyContracts/SearchModels/VisitSearchModel.cs b/LawCompany/LawCompanyContracts/SearchModels/VisitSearchModel.cs index 7e4909b..065327d 100644 --- a/LawCompany/LawCompanyContracts/SearchModels/VisitSearchModel.cs +++ b/LawCompany/LawCompanyContracts/SearchModels/VisitSearchModel.cs @@ -13,5 +13,6 @@ namespace LawCompanyContracts.SearchModels public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } public int? HearingId { get; set; } + public int? ExecutorId { get; set; } } } diff --git a/LawCompany/LawCompanyContracts/ViewModels/CaseViewModel.cs b/LawCompany/LawCompanyContracts/ViewModels/CaseViewModel.cs index 7428a49..54f6884 100644 --- a/LawCompany/LawCompanyContracts/ViewModels/CaseViewModel.cs +++ b/LawCompany/LawCompanyContracts/ViewModels/CaseViewModel.cs @@ -18,5 +18,6 @@ namespace LawCompanyContracts.ViewModels [DisplayName("Дата выполнения")] public DateTime? DateImplement { get; set; } public Dictionary CaseClients { get; set; } = new(); + public int ExecutorId { get; set; } } } diff --git a/LawCompany/LawCompanyContracts/ViewModels/ClientViewModel.cs b/LawCompany/LawCompanyContracts/ViewModels/ClientViewModel.cs index 4bc0610..d88280c 100644 --- a/LawCompany/LawCompanyContracts/ViewModels/ClientViewModel.cs +++ b/LawCompany/LawCompanyContracts/ViewModels/ClientViewModel.cs @@ -12,5 +12,6 @@ namespace LawCompanyContracts.ViewModels public string Email { get; set; } = string.Empty; [DisplayName("Телефон клиента")] public string Phone { get; set; } = string.Empty; + public int ExecutorId { get; set; } } } diff --git a/LawCompany/LawCompanyContracts/ViewModels/VisitViewModel.cs b/LawCompany/LawCompanyContracts/ViewModels/VisitViewModel.cs index 4bc8160..db98b12 100644 --- a/LawCompany/LawCompanyContracts/ViewModels/VisitViewModel.cs +++ b/LawCompany/LawCompanyContracts/ViewModels/VisitViewModel.cs @@ -10,5 +10,6 @@ namespace LawCompanyContracts.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/LawCompany/LawCompanyDatabaseImplement/Implements/CaseStorage.cs b/LawCompany/LawCompanyDatabaseImplement/Implements/CaseStorage.cs index edd985a..3e52d94 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Implements/CaseStorage.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Implements/CaseStorage.cs @@ -13,23 +13,33 @@ namespace LawCompanyDatabaseImplement.Implements { using var context = new LawCompanyDatabase(); 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 LawCompanyDatabase(); + 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 LawCompanyDatabase(); 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,15 +56,14 @@ namespace LawCompanyDatabaseImplement.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 LawCompanyDatabase(); 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/LawCompany/LawCompanyDatabaseImplement/Implements/ClientStorage.cs b/LawCompany/LawCompanyDatabaseImplement/Implements/ClientStorage.cs index 779c6ad..2c8f20e 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Implements/ClientStorage.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Implements/ClientStorage.cs @@ -18,7 +18,7 @@ namespace LawCompanyDatabaseImplement.Implements 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 +30,22 @@ namespace LawCompanyDatabaseImplement.Implements .Select(x => x.GetViewModel) .ToList(); } + else if (model.ExecutorId.HasValue && model.Id.HasValue) + { + using var context = new LawCompanyDatabase(); + return context.Clients + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + else if (model.ExecutorId.HasValue) + { + using var context = new LawCompanyDatabase(); + return context.Clients + .Where(x => x.ExecutorId == model.ExecutorId) + .Select(x => x.GetViewModel) + .ToList(); + } else { using var context = new LawCompanyDatabase(); @@ -42,7 +58,7 @@ namespace LawCompanyDatabaseImplement.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 +66,8 @@ namespace LawCompanyDatabaseImplement.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/LawCompany/LawCompanyDatabaseImplement/Implements/VisitStorage.cs b/LawCompany/LawCompanyDatabaseImplement/Implements/VisitStorage.cs index 8bb9715..795c358 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Implements/VisitStorage.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Implements/VisitStorage.cs @@ -13,7 +13,7 @@ namespace LawCompanyDatabaseImplement.Implements { using var context = new LawCompanyDatabase(); 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 LawCompanyDatabaseImplement.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 LawCompanyDatabase(); 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 LawCompanyDatabase(); 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 LawCompanyDatabase(); return context.Visits @@ -71,16 +63,44 @@ namespace LawCompanyDatabaseImplement.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 LawCompanyDatabase(); + 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 LawCompanyDatabase(); + 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.VisitDate.HasValue + && !model.HearingId.HasValue) { return new(); } using var context = new LawCompanyDatabase(); 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/LawCompany/LawCompanyDatabaseImplement/Models/Case.cs b/LawCompany/LawCompanyDatabaseImplement/Models/Case.cs index efa27e5..fcf778d 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Models/Case.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Models/Case.cs @@ -20,6 +20,7 @@ namespace LawCompanyDatabaseImplement.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 LawCompanyDatabaseImplement.Models } [ForeignKey("CaseId")] public virtual List Clients { get; set; } = new(); - [ForeignKey("CaseId")] - public virtual List Hearings { get; set; } = new(); public static Case Create(LawCompanyDatabase context, CaseBindingModel model) { if (model == null) @@ -53,6 +52,7 @@ namespace LawCompanyDatabaseImplement.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 LawCompanyDatabaseImplement.Models if (model.DateImplement.HasValue) DateImplement = model.DateImplement; - if (!model.CompanyId.HasValue) CompanyId = model.CompanyId; } public CaseViewModel GetViewModel => new() { @@ -81,6 +80,7 @@ namespace LawCompanyDatabaseImplement.Models CaseType = CaseType, DateCreate = DateCreate, DateImplement = DateImplement, + ExecutorId = ExecutorId, Status = Status, CaseClients = CaseClients, }; diff --git a/LawCompany/LawCompanyDatabaseImplement/Models/Client.cs b/LawCompany/LawCompanyDatabaseImplement/Models/Client.cs index da01051..ce016c3 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Models/Client.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Models/Client.cs @@ -19,6 +19,7 @@ namespace LawCompanyDatabaseImplement.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 LawCompanyDatabaseImplement.Models FIO = model.FIO, Email = model.Email, Phone = model.Phone, + ExecutorId = model.ExecutorId, }; } public static Client Create(ClientViewModel model) @@ -42,6 +44,7 @@ namespace LawCompanyDatabaseImplement.Models FIO = model.FIO, Email = model.Email, Phone = model.Phone, + ExecutorId = model.ExecutorId, }; } public void Update(ClientBindingModel? model) @@ -60,6 +63,7 @@ namespace LawCompanyDatabaseImplement.Models FIO = FIO, Email = Email, Phone = Phone, + ExecutorId = ExecutorId, }; } } diff --git a/LawCompany/LawCompanyDatabaseImplement/Models/Visit.cs b/LawCompany/LawCompanyDatabaseImplement/Models/Visit.cs index 7ee523a..373dec9 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Models/Visit.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Models/Visit.cs @@ -16,7 +16,7 @@ namespace LawCompanyDatabaseImplement.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 LawCompanyDatabaseImplement.Models } [ForeignKey("VisitId")] public virtual List Clients { get; set; } = new(); - public static Visit? Create(LawCompanyDatabase context, - VisitBindingModel? model) + public static Visit? Create(LawCompanyDatabase context, VisitBindingModel? model) { if (model == null) { @@ -54,6 +53,7 @@ namespace LawCompanyDatabaseImplement.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 LawCompanyDatabaseImplement.Models Id = Id, VisitDate = VisitDate, HearingId = HearingId, - VisitClients = VisitClients + VisitClients = VisitClients, + ExecutorId = ExecutorId, }; public void UpdateClients(LawCompanyDatabase context, VisitBindingModel model)