diff --git a/LawCompany/LawCompanyDatabaseImplement/Implements/CaseStorage.cs b/LawCompany/LawCompanyDatabaseImplement/Implements/CaseStorage.cs index 3e52d94..e672228 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Implements/CaseStorage.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Implements/CaseStorage.cs @@ -20,13 +20,13 @@ namespace LawCompanyDatabaseImplement.Implements } public List GetFilteredList(CaseSearchModel model) { - if (!model.DateFrom.HasValue && !model.DateTo.HasValue + if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ExecutorId.HasValue) { return new(); } - if (model.ExecutorId.HasValue) + if (model.ExecutorId.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue) { using var context = new LawCompanyDatabase(); return context.Cases @@ -35,13 +35,23 @@ namespace LawCompanyDatabaseImplement.Implements .Select(x => x.GetViewModel) .ToList(); } + else 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) + .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() + .Select(x => x.GetViewModel) .ToList(); } else diff --git a/LawCompany/LawCompanyDatabaseImplement/Implements/ConsultationStorage.cs b/LawCompany/LawCompanyDatabaseImplement/Implements/ConsultationStorage.cs index dc01699..d803185 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Implements/ConsultationStorage.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Implements/ConsultationStorage.cs @@ -21,57 +21,56 @@ namespace LawCompanyDatabaseImplement.Implements } public List GetFilteredList(ConsultationSearchModel model) { - if (!model.Id.HasValue && !model.GuarantorId.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue - && !model.ConsultationDate.HasValue) - { - return new(); - } - if (!model.GuarantorId.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue) - { - using var context = new LawCompanyDatabase(); - return context.Consultations - .Include(x => x.Lawyers) - .ThenInclude(x => x.Lawyer) - .Where(x => x.GuarantorId == model.GuarantorId && x.ConsultationDate >= model.DateFrom - && x.ConsultationDate <= model.DateTo) - .ToList() - .Select(x => x.GetViewModel) - .ToList(); - } - if (!model.GuarantorId.HasValue) - { - using var context = new LawCompanyDatabase(); - return context.Consultations - .Include(x => x.Lawyers) - .ThenInclude(x => x.Lawyer) - .Where(x => x.GuarantorId == model.GuarantorId) - .ToList() - .Select(x => x.GetViewModel) - .ToList(); - } - else if (!model.DateFrom.HasValue || !model.DateTo.HasValue) - { - using var context = new LawCompanyDatabase(); - return context.Consultations - .Include(x => x.Lawyers) - .ThenInclude(x => x.Lawyer) - .Where(x => x.Id == model.Id) - .ToList() - .Select(x => x.GetViewModel) - .ToList(); - } - else - { - using var context = new LawCompanyDatabase(); - return context.Consultations - .Include(x => x.Lawyers) - .ThenInclude(x => x.Lawyer) - .Where(x => x.ConsultationDate >= model.DateFrom && x.ConsultationDate <= model.DateTo) - .ToList() - .Select(x => x.GetViewModel) - .ToList(); - } - } + if (!model.Id.HasValue && !model.GuarantorId.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue + && !model.ConsultationDate.HasValue && !model.CaseId.HasValue) + { + return new(); + } + if (model.GuarantorId.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue) + { + using var context = new LawCompanyDatabase(); + return context.Consultations + .Include(x => x.Lawyers) + .ThenInclude(x => x.Lawyer) + .Where(x => x.GuarantorId == model.GuarantorId && x.ConsultationDate >= model.DateFrom + && x.ConsultationDate <= model.DateTo) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + else if (model.GuarantorId.HasValue) + { + using var context = new LawCompanyDatabase(); + return context.Consultations + .Include(x => x.Lawyers) + .ThenInclude(x => x.Lawyer) + .Where(x => x.GuarantorId == model.GuarantorId) + .Select(x => x.GetViewModel) + .ToList(); + } + else if (!model.DateFrom.HasValue || !model.DateTo.HasValue) + { + using var context = new LawCompanyDatabase(); + return context.Consultations + .Include(x => x.Lawyers) + .ThenInclude(x => x.Lawyer) + .Where(x => x.Id == model.Id) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + else + { + using var context = new LawCompanyDatabase(); + return context.Consultations + .Include(x => x.Lawyers) + .ThenInclude(x => x.Lawyer) + .Where(x => x.ConsultationDate >= model.DateFrom && x.ConsultationDate <= model.DateTo) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + } public ConsultationViewModel? GetElement(ConsultationSearchModel model) { if (!model.Id.HasValue && !model.GuarantorId.HasValue && !model.ConsultationDate.HasValue) diff --git a/LawCompany/LawCompanyRestApi/Controllers/CaseController.cs b/LawCompany/LawCompanyRestApi/Controllers/CaseController.cs index 9bc3280..6e8c42f 100644 --- a/LawCompany/LawCompanyRestApi/Controllers/CaseController.cs +++ b/LawCompany/LawCompanyRestApi/Controllers/CaseController.cs @@ -130,12 +130,12 @@ namespace LawCompanyRestApi.Controllers } [HttpPost] - public void AddClientToCase(Tuple model) + public void AddClientToCase(Tuple model) { try { - - _logic.AddClientToCase(model.Item1, model.Item2); + var modelClient = _clientlogic.ReadElement(new ClientSearchModel { Id = model.Item2 }); + if (modelClient != null) _logic.AddClientToCase(model.Item1, modelClient); } catch (Exception ex) {