diff --git a/.gitignore b/.gitignore index 3ceca38..f0a5976 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs Reports +Logs # Mono auto generated files mono_crash.* diff --git a/Hospital/HospitalBusinessLogics/BusinessLogics/DoctorLogic.cs b/Hospital/HospitalBusinessLogics/BusinessLogics/DoctorLogic.cs index df42112..0c62f9e 100644 --- a/Hospital/HospitalBusinessLogics/BusinessLogics/DoctorLogic.cs +++ b/Hospital/HospitalBusinessLogics/BusinessLogics/DoctorLogic.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; namespace HospitalBusinessLogics.BusinessLogics @@ -159,9 +160,9 @@ namespace HospitalBusinessLogics.BusinessLogics { throw new ArgumentNullException("Не указано ФИО доктора", nameof(model.FullName)); } - if (string.IsNullOrEmpty(model.Email)) + if (string.IsNullOrEmpty(model.Email) || !Regex.IsMatch(model.Email, @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$", RegexOptions.IgnoreCase)) { - throw new ArgumentNullException("Не указана электронная почта (логин)", nameof(model.Email)); + throw new ArgumentNullException("Невалидная электронная почта (логин)", nameof(model.Email)); } if (string.IsNullOrEmpty(model.Password)) { diff --git a/Hospital/HospitalContracts/ViewModels/DiseaseViewModel.cs b/Hospital/HospitalContracts/ViewModels/DiseaseViewModel.cs index b770d88..ae22ed9 100644 --- a/Hospital/HospitalContracts/ViewModels/DiseaseViewModel.cs +++ b/Hospital/HospitalContracts/ViewModels/DiseaseViewModel.cs @@ -34,5 +34,33 @@ namespace HospitalContracts.ViewModels /// Идентификатор рецепта /// public int RecipeId { get; set; } + + /// + /// Получить хэш-код + /// + /// + public override int GetHashCode() + { + return Id.GetHashCode(); + } + + /// + /// Сравнить объекты + /// + /// + /// + public override bool Equals(object? obj) + { + if (this == obj) + { + return true; + } + if (obj != null && obj is DiseaseViewModel other) + { + return this.Id == other.Id; + } + + return false; + } } } diff --git a/Hospital/HospitalContracts/ViewModels/MedicineViewModel.cs b/Hospital/HospitalContracts/ViewModels/MedicineViewModel.cs index a2c98ee..e9a6f1e 100644 --- a/Hospital/HospitalContracts/ViewModels/MedicineViewModel.cs +++ b/Hospital/HospitalContracts/ViewModels/MedicineViewModel.cs @@ -29,5 +29,33 @@ namespace HospitalContracts.ViewModels /// [DisplayName("Описание лекарства")] public string? Description { get; set; } + + /// + /// Получить хэш-код + /// + /// + public override int GetHashCode() + { + return Id.GetHashCode(); + } + + /// + /// Сравнить объекты + /// + /// + /// + public override bool Equals(object? obj) + { + if (this == obj) + { + return true; + } + if (obj != null && obj is MedicineViewModel other) + { + return this.Id == other.Id; + } + + return false; + } } } diff --git a/Hospital/HospitalContracts/ViewModels/ProcedureViewModel.cs b/Hospital/HospitalContracts/ViewModels/ProcedureViewModel.cs index 0443f98..bb1ba3c 100644 --- a/Hospital/HospitalContracts/ViewModels/ProcedureViewModel.cs +++ b/Hospital/HospitalContracts/ViewModels/ProcedureViewModel.cs @@ -38,5 +38,33 @@ namespace HospitalContracts.ViewModels get; set; } = new(); + + /// + /// Получить хэш-код + /// + /// + public override int GetHashCode() + { + return Id.GetHashCode(); + } + + /// + /// Сравнить объекты + /// + /// + /// + public override bool Equals(object? obj) + { + if (this == obj) + { + return true; + } + if (obj != null && obj is ProcedureViewModel other) + { + return this.Id == other.Id; + } + + return false; + } } } diff --git a/Hospital/HospitalDatabaseImplement/Implements/DiseaseStorage.cs b/Hospital/HospitalDatabaseImplement/Implements/DiseaseStorage.cs index d2adb14..420c857 100644 --- a/Hospital/HospitalDatabaseImplement/Implements/DiseaseStorage.cs +++ b/Hospital/HospitalDatabaseImplement/Implements/DiseaseStorage.cs @@ -125,7 +125,7 @@ namespace HospitalDatabaseImplement.Implements return null; } - disease.Update(model); + disease.Update(context, model); context.SaveChanges(); return disease.GetViewModel; } diff --git a/Hospital/HospitalDatabaseImplement/Models/Disease.cs b/Hospital/HospitalDatabaseImplement/Models/Disease.cs index 7ca3093..ddc4a03 100644 --- a/Hospital/HospitalDatabaseImplement/Models/Disease.cs +++ b/Hospital/HospitalDatabaseImplement/Models/Disease.cs @@ -73,7 +73,7 @@ namespace HospitalDatabaseImplement.Models /// Изменить сущность /// /// - public void Update(DiseaseBindingModel model) + public void Update(HospitalDatabase context, DiseaseBindingModel model) { if (model == null) { @@ -82,7 +82,11 @@ namespace HospitalDatabaseImplement.Models Name = model.Name; Symptoms = model.Symptoms; - } + RecipeId = model.RecipeId; + Recipe = context.Recipes + .First(x => x.Id == model.RecipeId); + + } /// /// Получить модель представления diff --git a/Hospital/HospitalWebApp/Controllers/PatientController.cs b/Hospital/HospitalWebApp/Controllers/PatientController.cs index 30bd30c..ae0a8ae 100644 --- a/Hospital/HospitalWebApp/Controllers/PatientController.cs +++ b/Hospital/HospitalWebApp/Controllers/PatientController.cs @@ -294,7 +294,7 @@ namespace HospitalWebApp.Controllers var result = new { - allRecipes = allRecipes.Select(r => new { id = r.Id, issueDate = r.IssueDate }), + allRecipes = allRecipes.Select(r => new { id = r.Id, issueDate = r.IssueDate.ToShortDateString() }), patientRecipeIds = patientRecipeIds }; diff --git a/Hospital/HospitalWebApp/HospitalWebApp.csproj b/Hospital/HospitalWebApp/HospitalWebApp.csproj index 4567e9c..ccbb81b 100644 --- a/Hospital/HospitalWebApp/HospitalWebApp.csproj +++ b/Hospital/HospitalWebApp/HospitalWebApp.csproj @@ -8,6 +8,7 @@ + diff --git a/Hospital/HospitalWebApp/Program.cs b/Hospital/HospitalWebApp/Program.cs index a415524..1fca2d1 100644 --- a/Hospital/HospitalWebApp/Program.cs +++ b/Hospital/HospitalWebApp/Program.cs @@ -7,12 +7,17 @@ using HospitalContracts.BusinessLogicsContracts; using HospitalContracts.StoragesContracts; using HospitalDatabaseImplement.Implements; using HospitalWebApp; +using NLog.Extensions.Logging; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllersWithViews(); +// Logger service +builder.Logging.SetMinimumLevel(LogLevel.Trace); +builder.Logging.AddNLog("nlog.config"); + // Storage services builder.Services.AddTransient(); builder.Services.AddTransient(); diff --git a/Hospital/HospitalWebApp/Views/Disease/CreateDisease.cshtml b/Hospital/HospitalWebApp/Views/Disease/CreateDisease.cshtml index c0d33bd..952439a 100644 --- a/Hospital/HospitalWebApp/Views/Disease/CreateDisease.cshtml +++ b/Hospital/HospitalWebApp/Views/Disease/CreateDisease.cshtml @@ -26,7 +26,7 @@ diff --git a/Hospital/HospitalWebApp/Views/Disease/Diseases.cshtml b/Hospital/HospitalWebApp/Views/Disease/Diseases.cshtml index 4912495..b34b9a2 100644 --- a/Hospital/HospitalWebApp/Views/Disease/Diseases.cshtml +++ b/Hospital/HospitalWebApp/Views/Disease/Diseases.cshtml @@ -38,10 +38,10 @@ @foreach (var disease in Model) { - @Html.DisplayFor(modelItem => disease.Id) - @Html.DisplayFor(modelItem => disease.Name) - @Html.DisplayFor(modelItem => disease.Symptoms) - @Html.DisplayFor(modelItem => disease.RecipeId) + @disease.Id + @disease.Name + @disease.Symptoms + @disease.RecipeId

diff --git a/Hospital/HospitalWebApp/Views/Disease/UpdateDisease.cshtml b/Hospital/HospitalWebApp/Views/Disease/UpdateDisease.cshtml index dc26931..8bdf83d 100644 --- a/Hospital/HospitalWebApp/Views/Disease/UpdateDisease.cshtml +++ b/Hospital/HospitalWebApp/Views/Disease/UpdateDisease.cshtml @@ -31,7 +31,7 @@ @foreach (var recipe in ViewBag.Recipes) { var isSelected = Model.RecipeId.Equals(recipe.Id); - + } diff --git a/Hospital/HospitalWebApp/Views/Home/Reports.cshtml b/Hospital/HospitalWebApp/Views/Home/Reports.cshtml index 2009a38..e57be1b 100644 --- a/Hospital/HospitalWebApp/Views/Home/Reports.cshtml +++ b/Hospital/HospitalWebApp/Views/Home/Reports.cshtml @@ -34,7 +34,7 @@ -
+
diff --git a/Hospital/HospitalWebApp/Views/Medicine/Medicines.cshtml b/Hospital/HospitalWebApp/Views/Medicine/Medicines.cshtml index d86a582..f9bd135 100644 --- a/Hospital/HospitalWebApp/Views/Medicine/Medicines.cshtml +++ b/Hospital/HospitalWebApp/Views/Medicine/Medicines.cshtml @@ -37,9 +37,9 @@ @foreach (var medicine in Model) { - @Html.DisplayFor(modelItem => medicine.Id) - @Html.DisplayFor(modelItem => medicine.Name) - @Html.DisplayFor(modelItem => medicine.Description) + @medicine.Id + @medicine.Name + @medicine.Description

diff --git a/Hospital/HospitalWebApp/Views/Patient/CreatePatientRecipe.cshtml b/Hospital/HospitalWebApp/Views/Patient/CreatePatientRecipe.cshtml index 796ab9a..e16c99c 100644 --- a/Hospital/HospitalWebApp/Views/Patient/CreatePatientRecipe.cshtml +++ b/Hospital/HospitalWebApp/Views/Patient/CreatePatientRecipe.cshtml @@ -27,7 +27,7 @@
diff --git a/Hospital/HospitalWebApp/Views/Patient/Patients.cshtml b/Hospital/HospitalWebApp/Views/Patient/Patients.cshtml index e9c4e45..9f6d9bc 100644 --- a/Hospital/HospitalWebApp/Views/Patient/Patients.cshtml +++ b/Hospital/HospitalWebApp/Views/Patient/Patients.cshtml @@ -39,11 +39,11 @@ @foreach (var patient in Model) { - @Html.DisplayFor(modelItem => patient.Id) - @Html.DisplayFor(modelItem => patient.FullName) - @Html.DisplayFor(modelItem => patient.BirthDate) - @Html.DisplayFor(modelItem => patient.Phone) - @Html.DisplayFor(modelItem => patient.DoctorFullName) + @patient.Id + @patient.FullName + @patient.BirthDate.ToShortDateString() + @patient.Phone + @patient.DoctorFullName

diff --git a/Hospital/HospitalWebApp/Views/Procedure/Procedures.cshtml b/Hospital/HospitalWebApp/Views/Procedure/Procedures.cshtml index 70963db..a82ccf1 100644 --- a/Hospital/HospitalWebApp/Views/Procedure/Procedures.cshtml +++ b/Hospital/HospitalWebApp/Views/Procedure/Procedures.cshtml @@ -37,9 +37,9 @@ @foreach (var procedure in Model) { - @Html.DisplayFor(modelItem => procedure.Id) - @Html.DisplayFor(modelItem => procedure.Name) - @Html.DisplayFor(modelItem => procedure.Description) + @procedure.Id + @procedure.Name + @procedure.Description

diff --git a/Hospital/HospitalWebApp/Views/Recipe/Recipes.cshtml b/Hospital/HospitalWebApp/Views/Recipe/Recipes.cshtml index 7d41016..ff7e320 100644 --- a/Hospital/HospitalWebApp/Views/Recipe/Recipes.cshtml +++ b/Hospital/HospitalWebApp/Views/Recipe/Recipes.cshtml @@ -37,9 +37,9 @@ @foreach (var recipe in Model) { - @Html.DisplayFor(modelItem => recipe.Id) - @Html.DisplayFor(modelItem => recipe.IssueDate) - @Html.DisplayFor(modelItem => recipe.DoctorFullName) + @recipe.Id + @recipe.IssueDate.ToShortDateString() + @recipe.DoctorFullName

diff --git a/Hospital/HospitalWebApp/nlog.config b/Hospital/HospitalWebApp/nlog.config new file mode 100644 index 0000000..e2fc1e9 --- /dev/null +++ b/Hospital/HospitalWebApp/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file