From d431b48bf9423564065c5fbf7f4c161f404d3de6 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Wed, 17 May 2023 17:48:12 +0400 Subject: [PATCH] =?UTF-8?q?REST=20=D0=B8=20MVC=20(=D1=82=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D0=BA=D0=BE=20CRUD)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Hospital/Hospital.sln | 10 +- .../Controllers/ApothecaryController.cs | 85 ++++++++++++ .../Controllers/MedicineController.cs | 124 ++++++++++++++++++ .../Controllers/PrescriptionController.cs | 99 ++++++++++++++ .../Controllers/ProcedureController.cs | 38 ++++++ .../Controllers/RecipeController.cs | 113 ++++++++++++++++ .../HospitalRestApi/HospitalRestApi.csproj | 19 +++ Hospital/HospitalRestApi/Program.cs | 65 +++++++++ .../Properties/launchSettings.json | 31 +++++ .../appsettings.Development.json | 8 ++ Hospital/HospitalRestApi/appsettings.json | 9 ++ Hospital/HospitalWeb/APIClient.cs | 45 +++++++ .../HospitalWeb/Controllers/HomeController.cs | 89 ++++++++++++- .../Controllers/MedicineController.cs | 122 +++++++++++++++++ .../Controllers/PrescriptionController.cs | 85 ++++++++++++ .../Controllers/RecipeController.cs | 78 +++++++++++ Hospital/HospitalWeb/HospitalWeb.csproj | 3 +- Hospital/HospitalWeb/Program.cs | 8 +- Hospital/HospitalWeb/Views/Home/Enter.cshtml | 20 +++ Hospital/HospitalWeb/Views/Home/Index.cshtml | 49 ++++++- .../HospitalWeb/Views/Home/Privacy.cshtml | 29 +++- .../HospitalWeb/Views/Home/Register.cshtml | 21 +++ .../Medicine/AddProcedureMedicine.cshtml | 35 +++++ .../HospitalWeb/Views/Medicine/Create.cshtml | 43 ++++++ .../Views/Medicine/Medicines.cshtml | 70 ++++++++++ .../Views/Prescription/Create.cshtml | 48 +++++++ .../Views/Prescription/Prescriptions.cshtml | 69 ++++++++++ .../HospitalWeb/Views/Recipe/Create.cshtml | 96 ++++++++++++++ .../HospitalWeb/Views/Recipe/Recipes.cshtml | 65 +++++++++ .../HospitalWeb/Views/Shared/_Layout.cshtml | 18 ++- Hospital/HospitalWeb/appsettings.json | 3 +- 31 files changed, 1577 insertions(+), 20 deletions(-) create mode 100644 Hospital/HospitalRestApi/Controllers/ApothecaryController.cs create mode 100644 Hospital/HospitalRestApi/Controllers/MedicineController.cs create mode 100644 Hospital/HospitalRestApi/Controllers/PrescriptionController.cs create mode 100644 Hospital/HospitalRestApi/Controllers/ProcedureController.cs create mode 100644 Hospital/HospitalRestApi/Controllers/RecipeController.cs create mode 100644 Hospital/HospitalRestApi/HospitalRestApi.csproj create mode 100644 Hospital/HospitalRestApi/Program.cs create mode 100644 Hospital/HospitalRestApi/Properties/launchSettings.json create mode 100644 Hospital/HospitalRestApi/appsettings.Development.json create mode 100644 Hospital/HospitalRestApi/appsettings.json create mode 100644 Hospital/HospitalWeb/APIClient.cs create mode 100644 Hospital/HospitalWeb/Controllers/MedicineController.cs create mode 100644 Hospital/HospitalWeb/Controllers/PrescriptionController.cs create mode 100644 Hospital/HospitalWeb/Controllers/RecipeController.cs create mode 100644 Hospital/HospitalWeb/Views/Home/Enter.cshtml create mode 100644 Hospital/HospitalWeb/Views/Home/Register.cshtml create mode 100644 Hospital/HospitalWeb/Views/Medicine/AddProcedureMedicine.cshtml create mode 100644 Hospital/HospitalWeb/Views/Medicine/Create.cshtml create mode 100644 Hospital/HospitalWeb/Views/Medicine/Medicines.cshtml create mode 100644 Hospital/HospitalWeb/Views/Prescription/Create.cshtml create mode 100644 Hospital/HospitalWeb/Views/Prescription/Prescriptions.cshtml create mode 100644 Hospital/HospitalWeb/Views/Recipe/Create.cshtml create mode 100644 Hospital/HospitalWeb/Views/Recipe/Recipes.cshtml diff --git a/Hospital/Hospital.sln b/Hospital/Hospital.sln index 509d58b..4559a6a 100644 --- a/Hospital/Hospital.sln +++ b/Hospital/Hospital.sln @@ -11,9 +11,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HospitalContracts", "Hospit EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HospitalDatabaseImplement", "HospitalDatabaseImplement\HospitalDatabaseImplement.csproj", "{B99AB6C1-2F4F-4E40-B933-45CE5E6CC37B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HospitalBusinessLogic", "HospitalBusinessLogic\HospitalBusinessLogic.csproj", "{C8819EE4-365C-4960-9578-3B8A45B5EBF4}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HospitalBusinessLogic", "HospitalBusinessLogic\HospitalBusinessLogic.csproj", "{C8819EE4-365C-4960-9578-3B8A45B5EBF4}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTest", "UnitTest\UnitTest.csproj", "{A8EB3C34-5C9B-4C40-8B0F-21D62ACBFFFF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTest", "UnitTest\UnitTest.csproj", "{A8EB3C34-5C9B-4C40-8B0F-21D62ACBFFFF}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HospitalRestApi", "HospitalRestApi\HospitalRestApi.csproj", "{71DD78F3-FA96-4027-97D7-45E6E34654B8}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -45,6 +47,10 @@ Global {A8EB3C34-5C9B-4C40-8B0F-21D62ACBFFFF}.Debug|Any CPU.Build.0 = Debug|Any CPU {A8EB3C34-5C9B-4C40-8B0F-21D62ACBFFFF}.Release|Any CPU.ActiveCfg = Release|Any CPU {A8EB3C34-5C9B-4C40-8B0F-21D62ACBFFFF}.Release|Any CPU.Build.0 = Release|Any CPU + {71DD78F3-FA96-4027-97D7-45E6E34654B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {71DD78F3-FA96-4027-97D7-45E6E34654B8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {71DD78F3-FA96-4027-97D7-45E6E34654B8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {71DD78F3-FA96-4027-97D7-45E6E34654B8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Hospital/HospitalRestApi/Controllers/ApothecaryController.cs b/Hospital/HospitalRestApi/Controllers/ApothecaryController.cs new file mode 100644 index 0000000..18ab231 --- /dev/null +++ b/Hospital/HospitalRestApi/Controllers/ApothecaryController.cs @@ -0,0 +1,85 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.BusinessLogicContracts; +using HospitalContracts.SearchModels; +using HospitalContracts.ViewModels; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace HospitalRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ApothecaryController : ControllerBase + { + private readonly ILogger _logger; + private readonly IApothecaryLogic _logic; + //private readonly IMessageInfoLogic _mailLogic; + + public ApothecaryController(IApothecaryLogic logic, ILogger logger) + { + _logger = logger; + _logic = logic; + //_mailLogic = mailLogic; + } + + [HttpGet] + public ApothecaryViewModel? Login(string login, string password) + { + try + { + return _logic.ReadElement(new ApothecarySearchModel + { + Login = login, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка входа в систему"); + throw; + } + } + [HttpPost] + public void Register(ApothecaryBindingModel model) + { + try + { + _logic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка регистрации"); + throw; + } + } + [HttpPost] + public void UpdateData(ApothecaryBindingModel model) + { + try + { + _logic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления данных"); + throw; + } + } + /* [HttpGet] + public List? GetMessages(int clientId) + { + try + { + return _mailLogic.ReadList(new MessageInfoSearchModel + { + ClientId = clientId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения писем клиента"); + throw; + } + }*/ + } +} diff --git a/Hospital/HospitalRestApi/Controllers/MedicineController.cs b/Hospital/HospitalRestApi/Controllers/MedicineController.cs new file mode 100644 index 0000000..52dc58d --- /dev/null +++ b/Hospital/HospitalRestApi/Controllers/MedicineController.cs @@ -0,0 +1,124 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.BusinessLogicContracts; +using HospitalContracts.SearchModels; +using HospitalContracts.ViewModels; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace HospitalRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class MedicineController : ControllerBase + { + private readonly ILogger _logger; + private readonly IMedicineLogic _logic; + private readonly IProcedureLogic _logicP; + + public MedicineController(IMedicineLogic logic, ILogger logger, IProcedureLogic logicP) + { + _logger = logger; + _logic = logic; + _logicP = logicP; + } + + [HttpGet] + public List? GetMedicines(int? apothecaryid) + { + try + { + if (apothecaryid == null) + { + return _logic.ReadList(null); + } + return _logic.ReadList(new MedicineSearchModel + { + ApothecaryId = apothecaryid + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка лекарств"); + throw; + } + } + + [HttpGet] + public MedicineViewModel? GetMedicine(int id) + { + try + { + return _logic.ReadElement(new MedicineSearchModel + { + Id = id + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения поступления "); + throw; + } + } + + [HttpPost] + public void Create(MedicineBindingModel model) + { + try + { + _logic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания лекарства"); + throw; + } + } + + [HttpPost] + public void Update(MedicineBindingModel model) + { + try + { + _logic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления лекарства"); + throw; + } + } + + [HttpPost] + public void Delete(MedicineBindingModel model) + { + try + { + _logic.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления лекарства"); + throw; + } + } + + [HttpPost] + public void AddProcedureMedicine(Tuple addInfo) + { + var medicineId = addInfo.Item1.Id; + var procedureId = addInfo.Item2.Id; + var procedure = _logicP.ReadElement(new ProcedureSearchModel { Id = procedureId }); + var medicine = _logic.ReadElement(new MedicineSearchModel { Id = medicineId }); + if (procedure != null && medicine != null) + { + var procedureMedicines = procedure.ProcedureMedicines; + procedureMedicines[medicineId] = medicine; + _logicP.Update(new ProcedureBindingModel { + Id = procedureId, + Name = procedure.Name, + ProcedureMedicines = procedureMedicines + }); + } + } + } +} diff --git a/Hospital/HospitalRestApi/Controllers/PrescriptionController.cs b/Hospital/HospitalRestApi/Controllers/PrescriptionController.cs new file mode 100644 index 0000000..3b951d8 --- /dev/null +++ b/Hospital/HospitalRestApi/Controllers/PrescriptionController.cs @@ -0,0 +1,99 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.BusinessLogicContracts; +using HospitalContracts.SearchModels; +using HospitalContracts.ViewModels; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace HospitalRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class PrescriptionController : ControllerBase + { + private readonly ILogger _logger; + private readonly IPrescriptionLogic _logic; + + public PrescriptionController(IPrescriptionLogic logic, ILogger logger) + { + _logger = logger; + _logic = logic; + } + + [HttpGet] + public List? GetPrescriptions(int apothecaryid) + { + try + { + return _logic.ReadList(new PrescriptionSearchModel + { + ApothecaryId = apothecaryid + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка поступлений аптекаря id ={ Id}", apothecaryid); + throw; + } + } + + [HttpGet] + public PrescriptionViewModel? GetPrescription(int id) + { + try + { + return _logic.ReadElement(new PrescriptionSearchModel + { + Id = id + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения поступления "); + throw; + } + } + + [HttpPost] + public void Create(PrescriptionBindingModel model) + { + try + { + _logic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания поступления"); + throw; + } + } + + [HttpPost] + public void Update(PrescriptionBindingModel model) + { + try + { + _logic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления поступления"); + throw; + } + } + + [HttpPost] + public void Delete(PrescriptionBindingModel model) + { + try + { + _logic.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления поступления"); + throw; + } + } + } +} diff --git a/Hospital/HospitalRestApi/Controllers/ProcedureController.cs b/Hospital/HospitalRestApi/Controllers/ProcedureController.cs new file mode 100644 index 0000000..7fe18bc --- /dev/null +++ b/Hospital/HospitalRestApi/Controllers/ProcedureController.cs @@ -0,0 +1,38 @@ +using HospitalContracts.BusinessLogicContracts; +using HospitalContracts.SearchModels; +using HospitalContracts.ViewModels; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace HospitalRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ProcedureController : ControllerBase + { + private readonly ILogger _logger; + private readonly IProcedureLogic _logic; + + public ProcedureController(ILogger logger, IProcedureLogic logic) + { + _logger = logger; + _logic = logic; + } + + [HttpGet] + public List? GetProcedures() + { + try + { + return _logic.ReadList(null); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка процедур"); + throw; + } + } + + } +} diff --git a/Hospital/HospitalRestApi/Controllers/RecipeController.cs b/Hospital/HospitalRestApi/Controllers/RecipeController.cs new file mode 100644 index 0000000..bd068f6 --- /dev/null +++ b/Hospital/HospitalRestApi/Controllers/RecipeController.cs @@ -0,0 +1,113 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.BusinessLogicContracts; +using HospitalContracts.SearchModels; +using HospitalContracts.ViewModels; +using HospitalDataModels.Models; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace HospitalRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class RecipeController : ControllerBase + { + private readonly ILogger _logger; + private readonly IRecipeLogic _logic; + private readonly IMedicineLogic _logicM; + + public RecipeController(IRecipeLogic logic, ILogger logger, IMedicineLogic logicM) + { + _logger = logger; + _logic = logic; + _logicM = logicM; + } + + [HttpGet] + public List? GetRecipes(int apothecaryid) + { + try + { + return _logic.ReadList(new RecipeSearchModel + { + ApothecaryId = apothecaryid + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка рецептов аптекаря id ={ Id}", apothecaryid); + throw; + } + } + + [HttpGet] + public RecipeViewModel? GetRecipe(int id) + { + try + { + return _logic.ReadElement(new RecipeSearchModel + { + Id = id + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения рецепта "); + throw; + } + } + + [HttpPost] + public void Create(RecipeBindingModel model) + { + try + { + _logic.Create(GetModelWithMedicines(model)); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания рецепта"); + throw; + } + } + + [HttpPost] + public void Update(RecipeBindingModel model) + { + try + { + _logic.Update(GetModelWithMedicines(model)); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления рецепта"); + throw; + } + } + + [HttpPost] + public void Delete(RecipeBindingModel model) + { + try + { + _logic.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления рецепта"); + throw; + } + } + + private RecipeBindingModel GetModelWithMedicines(RecipeBindingModel model) + { + var medicines = _logicM.ReadList(new MedicineSearchModel { Ids = model.RecipeMedicines.Keys.ToArray() }); + if (medicines != null) + { + model.RecipeMedicines = medicines.Where(m => model.RecipeMedicines.Keys.Contains(m.Id)) + .ToDictionary(m => m.Id, m => m as IMedicineModel); + } + return model; + } + } +} diff --git a/Hospital/HospitalRestApi/HospitalRestApi.csproj b/Hospital/HospitalRestApi/HospitalRestApi.csproj new file mode 100644 index 0000000..1bd2680 --- /dev/null +++ b/Hospital/HospitalRestApi/HospitalRestApi.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + diff --git a/Hospital/HospitalRestApi/Program.cs b/Hospital/HospitalRestApi/Program.cs new file mode 100644 index 0000000..6d976d8 --- /dev/null +++ b/Hospital/HospitalRestApi/Program.cs @@ -0,0 +1,65 @@ +using HospitalBusinessLogic; +using HospitalContracts.BusinessLogicContracts; +using HospitalContracts.StorageContracts; +using HospitalDatabaseImplement.Implements; +using Microsoft.OpenApi.Models; + +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddTransient(); + +//builder.Services.AddTransient(); +//builder.Services.AddTransient(); +//builder.Services.AddSingleton(); + +builder.Services.AddControllers().AddJsonOptions((option) => +{ + option.JsonSerializerOptions.IncludeFields = true; +}); + + +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(c => +{ + c.SwaggerDoc("v1", new OpenApiInfo + { + Title = "HospitalRestApi", + Version = "v1" + }); +}); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", + "HospitalRestApi v1")); +} +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/Hospital/HospitalRestApi/Properties/launchSettings.json b/Hospital/HospitalRestApi/Properties/launchSettings.json new file mode 100644 index 0000000..4230a5a --- /dev/null +++ b/Hospital/HospitalRestApi/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:43890", + "sslPort": 44365 + } + }, + "profiles": { + "HospitalRestApi": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7199;http://localhost:5199", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Hospital/HospitalRestApi/appsettings.Development.json b/Hospital/HospitalRestApi/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Hospital/HospitalRestApi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Hospital/HospitalRestApi/appsettings.json b/Hospital/HospitalRestApi/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/Hospital/HospitalRestApi/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/Hospital/HospitalWeb/APIClient.cs b/Hospital/HospitalWeb/APIClient.cs new file mode 100644 index 0000000..c19ace9 --- /dev/null +++ b/Hospital/HospitalWeb/APIClient.cs @@ -0,0 +1,45 @@ +using System.Net.Http.Headers; +using System.Text; +using HospitalContracts.ViewModels; +using Newtonsoft.Json; + + +namespace HospitalWeb +{ + public static class APIClient + { + private static readonly HttpClient _client = new(); + public static ApothecaryViewModel? Apothecary { get; set; } = null; + public static void Connect(IConfiguration configuration) + { + _client.BaseAddress = new Uri(configuration["IPAddress"]); + _client.DefaultRequestHeaders.Accept.Clear(); + _client.DefaultRequestHeaders.Accept.Add(new + MediaTypeWithQualityHeaderValue("application/json")); + } + public static T? GetRequest(string requestUrl) + { + var response = _client.GetAsync(requestUrl); + var result = response.Result.Content.ReadAsStringAsync().Result; + if (response.Result.IsSuccessStatusCode) + { + return JsonConvert.DeserializeObject(result); + } + else + { + throw new Exception(result); + } + } + public static void PostRequest(string requestUrl, T model) + { + var json = JsonConvert.SerializeObject(model); + var data = new StringContent(json, Encoding.UTF8, "application/json"); + var response = _client.PostAsync(requestUrl, data); + var result = response.Result.Content.ReadAsStringAsync().Result; + if (!response.Result.IsSuccessStatusCode) + { + throw new Exception(result); + } + } + } +} diff --git a/Hospital/HospitalWeb/Controllers/HomeController.cs b/Hospital/HospitalWeb/Controllers/HomeController.cs index f54798e..21d8e86 100644 --- a/Hospital/HospitalWeb/Controllers/HomeController.cs +++ b/Hospital/HospitalWeb/Controllers/HomeController.cs @@ -1,4 +1,7 @@ -using HospitalWeb.Models; +using HospitalContracts.BindingModels; +using HospitalContracts.ViewModels; +using HospitalDatabaseImplement; +using HospitalWeb.Models; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; @@ -10,19 +13,99 @@ namespace HospitalWeb.Controllers public HomeController(ILogger logger) { - _logger = logger; + _logger = logger; } public IActionResult Index() { - return View(); + if (APIClient.Apothecary == null) + { + return Redirect("~/Home/Enter"); + } + //return View(APIClient.GetRequest>($"api/prescription/getprescriptions?apothecaryId={APIClient.Apothecary.Id}")); + return Redirect("/prescription"); + } + [HttpGet] public IActionResult Privacy() + { + if (APIClient.Apothecary == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.Apothecary); + } + [HttpPost] + public void Privacy(string login, string password) + { + if (APIClient.Apothecary == null) + { + throw new Exception("Доступно только авторизованным пользователям"); + } + if (string.IsNullOrEmpty(login) || + string.IsNullOrEmpty(password)) + { + throw new Exception("Введите логин и пароль"); + } + APIClient.PostRequest("api/apothecary/updatedata", new + ApothecaryBindingModel + { + Id = APIClient.Apothecary.Id, + Login = login, + Password = password + }); + APIClient.Apothecary.Login = login; + APIClient.Apothecary.Password = password; + Response.Redirect("Index"); + } + + [HttpGet] + public IActionResult Enter() { return View(); } + [HttpPost] + public void Enter(string login, string password) + { + if (string.IsNullOrEmpty(login) || + string.IsNullOrEmpty(password)) + { + throw new Exception("Введите логин и пароль"); + } + APIClient.Apothecary = + APIClient.GetRequest($"api/apothecary/login?login={login}&password={password}"); + if (APIClient.Apothecary == null) + { + throw new Exception("Неверный логин/пароль"); + } + Response.Redirect("Index"); + } + + [HttpGet] + public IActionResult Register() + { + return View(); + } + [HttpPost] + public void Register(string login, string password) + { + if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) + { + throw new Exception("Введите логин и пароль"); + } + APIClient.PostRequest("api/apothecary/register", new + ApothecaryBindingModel + { + Login = login, + Password = password + }); + Response.Redirect("Enter"); + return; + } + + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { diff --git a/Hospital/HospitalWeb/Controllers/MedicineController.cs b/Hospital/HospitalWeb/Controllers/MedicineController.cs new file mode 100644 index 0000000..89f81a9 --- /dev/null +++ b/Hospital/HospitalWeb/Controllers/MedicineController.cs @@ -0,0 +1,122 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; +using System.Globalization; + +namespace HospitalWeb.Controllers +{ + public class MedicineController : Controller + { + private readonly ILogger _logger; + + public MedicineController(ILogger logger) + { + _logger = logger; + } + + public IActionResult Index() + { + return View(); + } + + + [HttpGet("/medicine")] + public IActionResult Medicines() + { + if (APIClient.Apothecary == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/medicine/getmedicines?apothecaryId={APIClient.Apothecary.Id}")); + } + + [HttpGet("/medicine/save/{id?}")] + public IActionResult Create(int? id) + { + if (APIClient.Apothecary == null) + { + return Redirect("~/Home/Enter"); + } + + if (!id.HasValue) + { + return View(); + } + var model = APIClient.GetRequest($"api/medicine/getmedicine?id={id}"); + return View(model); + + } + + [HttpPost("/medicine/save/{id?}")] + public void Create(int? id, string name, string costString, string dose) + { + if (APIClient.Apothecary == null) + { + throw new Exception("Доступно только авторизованным пользователям"); + } + if (!double.TryParse(costString, NumberStyles.Any, CultureInfo.InvariantCulture, out double cost) || cost <= 0) + { + throw new Exception("Цена лекарства должна быть больше 0"); + } + if (id.HasValue) + { + APIClient.PostRequest("api/medicine/update", new MedicineBindingModel + { + Id = id.Value, + Name = name, + Cost = cost, + Dose = dose + }); + } + else + { + APIClient.PostRequest("api/medicine/create", new MedicineBindingModel + { + ApothecaryId = APIClient.Apothecary.Id, + Name = name, + Cost = cost, + Dose = dose + + }); + } + + Response.Redirect("/medicine"); + } + + [HttpPost("/medicine/delete")] + public void Delete(int id) + { + if (APIClient.Apothecary == null) + { + throw new Exception("Доступно только авторизованным пользователям"); + } + + APIClient.PostRequest($"api/medicine/delete", new MedicineBindingModel { Id = id }); + Response.Redirect("/medicine"); + } + + [HttpGet("/medicine/addProcedure")] + public IActionResult AddProcedureMedicine() + { + if (APIClient.Apothecary == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Procedures = APIClient.GetRequest>($"api/procedure/getprocedures"); + ViewBag.Medicines = APIClient.GetRequest>($"api/medicine/getmedicines?apothecaryId={APIClient.Apothecary.Id}"); + return View(); + } + + [HttpPost("/medicine/addProcedure")] + public void AddProcedureMedicine(int medicine, int procedure) + { + if (APIClient.Apothecary == null) + { + throw new Exception("Доступно только авторизованным пользователям"); + } + APIClient.PostRequest($"api/medicine/addproceduremedicine", (new MedicineBindingModel { Id = medicine}, new ProcedureBindingModel { Id = procedure})); + Response.Redirect("/medicine"); + } + + } +} diff --git a/Hospital/HospitalWeb/Controllers/PrescriptionController.cs b/Hospital/HospitalWeb/Controllers/PrescriptionController.cs new file mode 100644 index 0000000..2aebdb1 --- /dev/null +++ b/Hospital/HospitalWeb/Controllers/PrescriptionController.cs @@ -0,0 +1,85 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace HospitalWeb.Controllers +{ + public class PrescriptionController : Controller + { + private readonly ILogger _logger; + + public PrescriptionController(ILogger logger) + { + _logger = logger; + } + + [HttpGet("/prescription")] + public IActionResult Prescriptions() + { + if (APIClient.Apothecary == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/prescription/getprescriptions?apothecaryId={APIClient.Apothecary.Id}")); + } + + [HttpGet("/prescription/save/{id?}")] + public IActionResult Create(int? id) + { + if (APIClient.Apothecary == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Medicines = APIClient.GetRequest>($"api/medicine/getmedicines"); + if (!id.HasValue) { + return View(); + } + var model = APIClient.GetRequest($"api/prescription/getprescription?id={id}"); + return View(model); + + } + + [HttpPost("/prescription/save/{id?}")] + public void Create(int? id, int medicine, int number) + { + if (APIClient.Apothecary == null) + { + throw new Exception("Доступно только авторизованным пользователям"); + } + if (number <= 0) + { + throw new Exception("Количество лекарств должно быть больше 0"); + } + if (id.HasValue) + { + APIClient.PostRequest("api/prescription/update", new PrescriptionBindingModel + { + Id = id.Value, + Number = number + }); + } + else { + APIClient.PostRequest("api/prescription/create", new PrescriptionBindingModel + { + ApothecaryId = APIClient.Apothecary.Id, + MedicineId = medicine, + Number = number + }); + } + + Response.Redirect("/prescription"); + } + + [HttpPost("/prescription/delete")] + public void Delete(int id) + { + if (APIClient.Apothecary == null) + { + throw new Exception("Доступно только авторизованным пользователям"); + } + + APIClient.PostRequest($"api/prescription/delete", new PrescriptionBindingModel { Id = id }); + Response.Redirect("/prescription"); + } + } +} diff --git a/Hospital/HospitalWeb/Controllers/RecipeController.cs b/Hospital/HospitalWeb/Controllers/RecipeController.cs new file mode 100644 index 0000000..1d4624b --- /dev/null +++ b/Hospital/HospitalWeb/Controllers/RecipeController.cs @@ -0,0 +1,78 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.ViewModels; +using HospitalDatabaseImplement.Models; +using Microsoft.AspNetCore.Mvc; + +namespace HospitalWeb.Controllers +{ + public class RecipeController : Controller + { + private readonly ILogger _logger; + + public RecipeController(ILogger logger) + { + _logger = logger; + } + + [HttpGet("/recipe")] + public IActionResult Recipes() + { + if (APIClient.Apothecary == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/recipe/getrecipes?apothecaryId={APIClient.Apothecary.Id}")); + } + + [HttpGet("/recipe/save/{id?}")] + public IActionResult Create(int? id) + { + if (APIClient.Apothecary == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Medicines = APIClient.GetRequest>($"api/medicine/getmedicines"); + if (!id.HasValue) + { + return View(new RecipeViewModel()); + } + var model = APIClient.GetRequest($"api/recipe/getrecipe?id={id}"); + return View(model); + + } + + [HttpPost("/recipe/save/{id?}")] + public void Create(RecipeBindingModel model) + { + if (APIClient.Apothecary == null) + { + throw new Exception("Доступно только авторизованным пользователям"); + } + model.ApothecaryId = APIClient.Apothecary.Id; + if (model.Id != 0) + { + // тут надо вытащить ключи, потом по ним сделать массовый запрос сущностей лекарств, а потом вставить как значения в словарь + //model.RecipeMedicines = + APIClient.PostRequest("api/recipe/update", model); + } + else + { + APIClient.PostRequest("api/recipe/create", model); + } + + Response.Redirect("/recipe"); + } + + [HttpPost("/recipe/delete")] + public void Delete(int id) + { + if (APIClient.Apothecary == null) + { + throw new Exception("Доступно только авторизованным пользователям"); + } + + APIClient.PostRequest($"api/recipe/delete", new RecipeBindingModel { Id = id }); + Response.Redirect("/recipe"); + } + } +} diff --git a/Hospital/HospitalWeb/HospitalWeb.csproj b/Hospital/HospitalWeb/HospitalWeb.csproj index 0f23fc6..18aad1b 100644 --- a/Hospital/HospitalWeb/HospitalWeb.csproj +++ b/Hospital/HospitalWeb/HospitalWeb.csproj @@ -11,12 +11,13 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + - + diff --git a/Hospital/HospitalWeb/Program.cs b/Hospital/HospitalWeb/Program.cs index 0727468..93e7cff 100644 --- a/Hospital/HospitalWeb/Program.cs +++ b/Hospital/HospitalWeb/Program.cs @@ -1,10 +1,13 @@ +using HospitalDatabaseImplement; +using HospitalWeb; + var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllersWithViews(); var app = builder.Build(); - +APIClient.Connect(builder.Configuration); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { @@ -24,4 +27,7 @@ app.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); +LoaderFromXML.LoadProcedures(); +LoaderFromXML.LoadTreatments(); +LoaderFromXML.LoadPatients(); app.Run(); diff --git a/Hospital/HospitalWeb/Views/Home/Enter.cshtml b/Hospital/HospitalWeb/Views/Home/Enter.cshtml new file mode 100644 index 0000000..636c82c --- /dev/null +++ b/Hospital/HospitalWeb/Views/Home/Enter.cshtml @@ -0,0 +1,20 @@ +@{ + ViewData["Title"] = "Enter"; +} +
+

Вход в приложение

+
+
+
+
Логин:
+
+
+
+
Пароль:
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/Hospital/HospitalWeb/Views/Home/Index.cshtml b/Hospital/HospitalWeb/Views/Home/Index.cshtml index d2d19bd..57c7c5d 100644 --- a/Hospital/HospitalWeb/Views/Home/Index.cshtml +++ b/Hospital/HospitalWeb/Views/Home/Index.cshtml @@ -1,8 +1,49 @@ -@{ +@using HospitalContracts.ViewModels +@model List +@{ ViewData["Title"] = "Home Page"; } -
-

Welcome

-

Learn about building Web apps with ASP.NET Core.

+

Поступления

+
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } +

+ Создать поступление +

+ + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + } + +
НомерДата поступленияЛекарствоКоличество
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.Date) + + @Html.DisplayFor(modelItem => item.MedicineName) + + @Html.DisplayFor(modelItem => item.Number) +
+ } +
\ No newline at end of file diff --git a/Hospital/HospitalWeb/Views/Home/Privacy.cshtml b/Hospital/HospitalWeb/Views/Home/Privacy.cshtml index af4fb19..3f47325 100644 --- a/Hospital/HospitalWeb/Views/Home/Privacy.cshtml +++ b/Hospital/HospitalWeb/Views/Home/Privacy.cshtml @@ -1,6 +1,25 @@ -@{ - ViewData["Title"] = "Privacy Policy"; +@using HospitalContracts.ViewModels +@model ApothecaryViewModel +@{ + ViewData["Title"] = "Privacy Policy"; } -

@ViewData["Title"]

- -

Use this page to detail your site's privacy policy.

+
+

Личные данные

+
+
+
+
Логин:
+
+
+
+
Пароль:
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/Hospital/HospitalWeb/Views/Home/Register.cshtml b/Hospital/HospitalWeb/Views/Home/Register.cshtml new file mode 100644 index 0000000..4cbf085 --- /dev/null +++ b/Hospital/HospitalWeb/Views/Home/Register.cshtml @@ -0,0 +1,21 @@ +@{ +ViewData["Title"] = "Register"; +} +
+

Регистрация

+
+
+
+
Логин:
+
+
+
+
Пароль:
+
+
+
+
+
+
+
diff --git a/Hospital/HospitalWeb/Views/Medicine/AddProcedureMedicine.cshtml b/Hospital/HospitalWeb/Views/Medicine/AddProcedureMedicine.cshtml new file mode 100644 index 0000000..110cd9e --- /dev/null +++ b/Hospital/HospitalWeb/Views/Medicine/AddProcedureMedicine.cshtml @@ -0,0 +1,35 @@ +@using HospitalContracts.ViewModels; +@using System.Globalization +@model MedicineViewModel +@{ + ViewData["Title"] = "Create"; +} + +@{ + +
+

Привязка процедуры

+
+ +
+
+
Процедура:
+
+ +
+
+
+
Лекарство:
+
+ +
+
+
+
+
+ +
+
+
+} + diff --git a/Hospital/HospitalWeb/Views/Medicine/Create.cshtml b/Hospital/HospitalWeb/Views/Medicine/Create.cshtml new file mode 100644 index 0000000..b253934 --- /dev/null +++ b/Hospital/HospitalWeb/Views/Medicine/Create.cshtml @@ -0,0 +1,43 @@ +@using HospitalContracts.ViewModels; +@using System.Globalization +@model MedicineViewModel +@{ + ViewData["Title"] = "Create"; +} + +@{ + if (Model != null) + { +
+

Редактирование лекарства

+
+ } + else { +
+

Создание лекарства

+
+ } +
+ +
+
Название:
+
+
+
+
Цена:
+
+
+ +
+
Дозировка:
+
+
+
+
+
+ +
+
+
+} + diff --git a/Hospital/HospitalWeb/Views/Medicine/Medicines.cshtml b/Hospital/HospitalWeb/Views/Medicine/Medicines.cshtml new file mode 100644 index 0000000..0cd7fd5 --- /dev/null +++ b/Hospital/HospitalWeb/Views/Medicine/Medicines.cshtml @@ -0,0 +1,70 @@ +@using HospitalContracts.ViewModels +@model List +@{ + ViewData["Title"] = "Лекарства"; +} +
+

Лекарства

+
+
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } +

+ На главную + Создать лекарство + Привязать процедуру +

+ + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + + } + +
НомерНазваниеЦенаДозировка
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.Name) + + @Html.DisplayFor(modelItem => item.Cost) + + @Html.DisplayFor(modelItem => item.Dose) + + Редактировать + +
+ } +
+@section scripts { + +} \ No newline at end of file diff --git a/Hospital/HospitalWeb/Views/Prescription/Create.cshtml b/Hospital/HospitalWeb/Views/Prescription/Create.cshtml new file mode 100644 index 0000000..16a4d97 --- /dev/null +++ b/Hospital/HospitalWeb/Views/Prescription/Create.cshtml @@ -0,0 +1,48 @@ +@using HospitalContracts.ViewModels; +@model PrescriptionViewModel +@{ + ViewData["Title"] = "Create"; +} + +@{ + if (Model != null) + { +
+

Редактирование поступления

+
+ } + else { +
+

Создание поступления

+
+ } +
+ +
+
+
Лекарство:
+
+ @{ + if (Model != null) + { + + } else { + + } + } +
+
+ +
+
Количество:
+
+
+
+
+
+ +
+
+ +} + diff --git a/Hospital/HospitalWeb/Views/Prescription/Prescriptions.cshtml b/Hospital/HospitalWeb/Views/Prescription/Prescriptions.cshtml new file mode 100644 index 0000000..11d6cd6 --- /dev/null +++ b/Hospital/HospitalWeb/Views/Prescription/Prescriptions.cshtml @@ -0,0 +1,69 @@ +@using HospitalContracts.ViewModels +@model List +@{ + ViewData["Title"] = "Поступления"; +} +
+

Поступления

+
+
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } +

+ На главную + Создать поступление +

+ + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + + } + +
НомерДата поступленияЛекарствоКоличество
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.Date) + + @Html.DisplayFor(modelItem => item.MedicineName) + + @Html.DisplayFor(modelItem => item.Number) + + Редактировать + +
+ } +
+@section scripts { + +} \ No newline at end of file diff --git a/Hospital/HospitalWeb/Views/Recipe/Create.cshtml b/Hospital/HospitalWeb/Views/Recipe/Create.cshtml new file mode 100644 index 0000000..5eae7af --- /dev/null +++ b/Hospital/HospitalWeb/Views/Recipe/Create.cshtml @@ -0,0 +1,96 @@ +@using HospitalContracts.ViewModels; +@using System.Globalization +@model RecipeViewModel +@{ + ViewData["Title"] = "Create"; +} + +@{ + if (Model.Id > 0) + { +
+

Редактирование рецепта

+
+ } + else { +
+

Создание рецепта

+
+ } +
+ +
+
Название:
+
+
+
+
Добавление лекарств
+
+ + +
+
+
+ + + + + + + + + @foreach (var medicine in Model.RecipeMedicines) + { + + + + + } + +
Название
@medicine.Value.Name + +
+
+
+
+
+ +
+
+ @foreach (var medicine in Model.RecipeMedicines.Keys) + { + + } +
+} +@section scripts { + +} + diff --git a/Hospital/HospitalWeb/Views/Recipe/Recipes.cshtml b/Hospital/HospitalWeb/Views/Recipe/Recipes.cshtml new file mode 100644 index 0000000..8ea1908 --- /dev/null +++ b/Hospital/HospitalWeb/Views/Recipe/Recipes.cshtml @@ -0,0 +1,65 @@ +@using HospitalContracts.ViewModels +@model List +@{ + ViewData["Title"] = "Рецепты"; +} +
+

Рецепты

+
+
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } +

+ На главную + Создать рецепт +

+ + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + } + +
НомерДата создания рецептаНазвание рецепта
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.Date) + + @Html.DisplayFor(modelItem => item.Name) + + Редактировать + +
+ } +
+@section scripts { + +} \ No newline at end of file diff --git a/Hospital/HospitalWeb/Views/Shared/_Layout.cshtml b/Hospital/HospitalWeb/Views/Shared/_Layout.cshtml index dd7f1e8..01d7c15 100644 --- a/Hospital/HospitalWeb/Views/Shared/_Layout.cshtml +++ b/Hospital/HospitalWeb/Views/Shared/_Layout.cshtml @@ -20,10 +20,22 @@ @@ -38,7 +50,7 @@
- © 2023 - HospitalWeb - Privacy + © 2023 - HospitalWeb
diff --git a/Hospital/HospitalWeb/appsettings.json b/Hospital/HospitalWeb/appsettings.json index 10f68b8..2ac5cbb 100644 --- a/Hospital/HospitalWeb/appsettings.json +++ b/Hospital/HospitalWeb/appsettings.json @@ -5,5 +5,6 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "IPAddress": "http://localhost:5199/" }