From 01197420c0408046e49eb948a66b16874d384f1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=BA=D0=B0=D1=82=D0=B5=D1=80=D0=B8=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=A0=D0=BE=D0=B3=D0=B0=D1=88=D0=BE=D0=B2=D0=B0?= Date: Fri, 7 Apr 2023 11:31:56 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B1=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SearchModels/KurseSearchModel.cs | 2 +- .../SearchModels/RecipesSearchModel.cs | 2 ++ .../Implements/KurseStorage.cs | 5 +++- .../Implements/RecipesStorage.cs | 25 +++++++++++++++++-- ... 20230407072756_InitialCreate.Designer.cs} | 2 +- ...ate.cs => 20230407072756_InitialCreate.cs} | 0 6 files changed, 31 insertions(+), 5 deletions(-) rename HospitalDataBaseImplements/Migrations/{20230406204404_InitialCreate.Designer.cs => 20230407072756_InitialCreate.Designer.cs} (99%) rename HospitalDataBaseImplements/Migrations/{20230406204404_InitialCreate.cs => 20230407072756_InitialCreate.cs} (100%) diff --git a/HospitalContracts/SearchModels/KurseSearchModel.cs b/HospitalContracts/SearchModels/KurseSearchModel.cs index 5401e84..c8e66ee 100644 --- a/HospitalContracts/SearchModels/KurseSearchModel.cs +++ b/HospitalContracts/SearchModels/KurseSearchModel.cs @@ -9,6 +9,6 @@ namespace HospitalContracts.SearchModels public class KurseSearchModel { public int? Id { get; set; } - public int? MedicinesId { get; set; } + public string? MedicinesName { get; set; } } } diff --git a/HospitalContracts/SearchModels/RecipesSearchModel.cs b/HospitalContracts/SearchModels/RecipesSearchModel.cs index ab06da7..c628a4f 100644 --- a/HospitalContracts/SearchModels/RecipesSearchModel.cs +++ b/HospitalContracts/SearchModels/RecipesSearchModel.cs @@ -10,5 +10,7 @@ namespace HospitalContracts.SearchModels { public int? Id { get; set; } public int? ClientId { get; set; } + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set; } } } diff --git a/HospitalDataBaseImplements/Implements/KurseStorage.cs b/HospitalDataBaseImplements/Implements/KurseStorage.cs index b3fa102..3ec1658 100644 --- a/HospitalDataBaseImplements/Implements/KurseStorage.cs +++ b/HospitalDataBaseImplements/Implements/KurseStorage.cs @@ -43,7 +43,10 @@ namespace HospitalDataBaseImplements.Implements return new(); } using var context = new HospitalDatabase(); - return context.Kurse.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); + return context.Kurse + .Where(x => x.MedicinesName.Contains(model.MedicinesName)) + .Select(x => x.GetViewModel) + .ToList(); } public List GetFullList() diff --git a/HospitalDataBaseImplements/Implements/RecipesStorage.cs b/HospitalDataBaseImplements/Implements/RecipesStorage.cs index b6ecabf..54a139e 100644 --- a/HospitalDataBaseImplements/Implements/RecipesStorage.cs +++ b/HospitalDataBaseImplements/Implements/RecipesStorage.cs @@ -39,12 +39,33 @@ namespace HospitalDataBaseImplements.Implements public List GetFilteredList(RecipesSearchModel model) { - if (!model.Id.HasValue) + if (!model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue) { return new(); } using var context = new HospitalDatabase(); - return context.Recipes.Include(x => x.Client).Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); + if (model.DateFrom.HasValue) + { + return context.Recipes + .Include(x => x.Medicines) + .Include(x => x.Client) + .Where(x => x.Date >= model.DateFrom && x.Date <= model.DateTo) + .Select(x => x.GetViewModel) + .ToList(); + } + else if (model.ClientId.HasValue) + return context.Recipes + .Include(x => x.Medicines) + .Include(x => x.Client) + .Where(x => x.ClientId == model.ClientId) + .Select(x => x.GetViewModel) + .ToList(); + return context.Recipes + .Include(x => x.Medicines) + .Include(x => x.Client) + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); } public List GetFullList() diff --git a/HospitalDataBaseImplements/Migrations/20230406204404_InitialCreate.Designer.cs b/HospitalDataBaseImplements/Migrations/20230407072756_InitialCreate.Designer.cs similarity index 99% rename from HospitalDataBaseImplements/Migrations/20230406204404_InitialCreate.Designer.cs rename to HospitalDataBaseImplements/Migrations/20230407072756_InitialCreate.Designer.cs index 2f36a4e..e8f66e8 100644 --- a/HospitalDataBaseImplements/Migrations/20230406204404_InitialCreate.Designer.cs +++ b/HospitalDataBaseImplements/Migrations/20230407072756_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace HospitalDataBaseImplements.Migrations { [DbContext(typeof(HospitalDatabase))] - [Migration("20230406204404_InitialCreate")] + [Migration("20230407072756_InitialCreate")] partial class InitialCreate { /// diff --git a/HospitalDataBaseImplements/Migrations/20230406204404_InitialCreate.cs b/HospitalDataBaseImplements/Migrations/20230407072756_InitialCreate.cs similarity index 100% rename from HospitalDataBaseImplements/Migrations/20230406204404_InitialCreate.cs rename to HospitalDataBaseImplements/Migrations/20230407072756_InitialCreate.cs