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<ApothecaryController> 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<MessageInfoViewModel>? 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<MedicineController> logger, IProcedureLogic logicP) + { + _logger = logger; + _logic = logic; + _logicP = logicP; + } + + [HttpGet] + public List<MedicineViewModel>? 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<MedicineBindingModel, ProcedureBindingModel> 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<PrescriptionController> logger) + { + _logger = logger; + _logic = logic; + } + + [HttpGet] + public List<PrescriptionViewModel>? 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<ProcedureController> logger, IProcedureLogic logic) + { + _logger = logger; + _logic = logic; + } + + [HttpGet] + public List<ProcedureViewModel>? 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<RecipeController> logger, IMedicineLogic logicM) + { + _logger = logger; + _logic = logic; + _logicM = logicM; + } + + [HttpGet] + public List<RecipeViewModel>? 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 @@ +<Project Sdk="Microsoft.NET.Sdk.Web"> + + <PropertyGroup> + <TargetFramework>net6.0</TargetFramework> + <Nullable>enable</Nullable> + <ImplicitUsings>enable</ImplicitUsings> + </PropertyGroup> + + <ItemGroup> + <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.16" /> + <PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" /> + </ItemGroup> + + <ItemGroup> + <ProjectReference Include="..\HospitalBusinessLogic\HospitalBusinessLogic.csproj" /> + <ProjectReference Include="..\HospitalDatabaseImplement\HospitalDatabaseImplement.csproj" /> + </ItemGroup> + +</Project> 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<IApothecaryStorage, ApothecaryStorage>(); +builder.Services.AddTransient<IMedicineStorage, MedicineStorage>(); +builder.Services.AddTransient<IPrescriptionStorage, PrescriptionStorage>(); +builder.Services.AddTransient<IRecipeStorage, RecipeStorage>(); + +builder.Services.AddTransient<IPatientStorage, PatientStorage>(); +builder.Services.AddTransient<IProcedureStorage, ProcedureStorage>(); +builder.Services.AddTransient<ITreatmentStorage, TreatmentStorage>(); + +builder.Services.AddTransient<IApothecaryLogic, ApothecaryLogic>(); +builder.Services.AddTransient<IMedicineLogic, MedicineLogic>(); +builder.Services.AddTransient<IPrescriptionLogic, PrescriptionLogic>(); +builder.Services.AddTransient<IRecipeLogic, RecipeLogic>(); + +builder.Services.AddTransient<IProcedureLogic, ProcedureLogic>(); +builder.Services.AddTransient<ITreatmentLogic, TreatmentLogic>(); + +builder.Services.AddTransient<IReportLogic, ReportLogic>(); + +//builder.Services.AddTransient<AbstractSaveToWord, SaveToWord>(); +//builder.Services.AddTransient<AbstractSaveToExcel, SaveToExcel>(); +//builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>(); + +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<T>(string requestUrl) + { + var response = _client.GetAsync(requestUrl); + var result = response.Result.Content.ReadAsStringAsync().Result; + if (response.Result.IsSuccessStatusCode) + { + return JsonConvert.DeserializeObject<T>(result); + } + else + { + throw new Exception(result); + } + } + public static void PostRequest<T>(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<HomeController> logger) { - _logger = logger; + _logger = logger; } public IActionResult Index() { - return View(); + if (APIClient.Apothecary == null) + { + return Redirect("~/Home/Enter"); + } + //return View(APIClient.GetRequest<List<PrescriptionViewModel>>($"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<ApothecaryViewModel>($"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<MedicineController> _logger; + + public MedicineController(ILogger<MedicineController> 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<List<MedicineViewModel>>($"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<MedicineViewModel?>($"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<List<ProcedureViewModel>>($"api/procedure/getprocedures"); + ViewBag.Medicines = APIClient.GetRequest<List<MedicineViewModel>>($"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<PrescriptionController> _logger; + + public PrescriptionController(ILogger<PrescriptionController> logger) + { + _logger = logger; + } + + [HttpGet("/prescription")] + public IActionResult Prescriptions() + { + if (APIClient.Apothecary == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest<List<PrescriptionViewModel>>($"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<List<MedicineViewModel>>($"api/medicine/getmedicines"); + if (!id.HasValue) { + return View(); + } + var model = APIClient.GetRequest<PrescriptionViewModel?>($"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<RecipeController> _logger; + + public RecipeController(ILogger<RecipeController> logger) + { + _logger = logger; + } + + [HttpGet("/recipe")] + public IActionResult Recipes() + { + if (APIClient.Apothecary == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest<List<RecipeViewModel>>($"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<List<MedicineViewModel>>($"api/medicine/getmedicines"); + if (!id.HasValue) + { + return View(new RecipeViewModel()); + } + var model = APIClient.GetRequest<RecipeViewModel?>($"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 @@ <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> </PackageReference> + <PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> </ItemGroup> <ItemGroup> - <ProjectReference Include="..\HospitalBusinessLogic\HospitalBusinessLogic.csproj" /> <ProjectReference Include="..\HospitalContracts\HospitalContracts.csproj" /> <ProjectReference Include="..\HospitalDatabaseImplement\HospitalDatabaseImplement.csproj" /> + <ProjectReference Include="..\HospitalDataModels\HospitalDataModels.csproj" /> </ItemGroup> </Project> 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"; +} +<div class="text-center"> + <h2 class="display-4">Вход в приложение</h2> +</div> +<form method="post"> + <div class="row"> + <div class="col-4">Логин:</div> + <div class="col-8"><input type="text" name="login" /></div> + </div> + <div class="row"> + <div class="col-4">Пароль:</div> + <div class="col-8"><input type="password" name="password" /></div> + </div> + <div class="row"> + <div class="col-8"></div> + <div class="col-4"><input type="submit" value="Вход" class="btn btnprimary" /></div> + </div> +</form> \ 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<PrescriptionViewModel> +@{ ViewData["Title"] = "Home Page"; } - <div class="text-center"> - <h1 class="display-4">Welcome</h1> - <p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p> + <h1 class="display-4">Поступления</h1> </div> +<div class="text-center"> + @{ + if (Model == null) + { + <h3 class="display-4">Авторизируйтесь</h3> + return; + } + <p> + <a asp-action="Create">Создать поступление</a> + </p> + <table class="table"> + <thead> + <tr> + <th>Номер</th> + <th>Дата поступления</th> + <th>Лекарство</th> + <th>Количество</th> + </tr> + </thead> + <tbody> + @foreach (var item in Model) + { + <tr> + <td> + @Html.DisplayFor(modelItem => item.Id) + </td> + <td> + @Html.DisplayFor(modelItem => item.Date) + </td> + <td> + @Html.DisplayFor(modelItem => item.MedicineName) + </td> + <td> + @Html.DisplayFor(modelItem => item.Number) + </td> + </tr> + } + </tbody> + </table> + } +</div> \ 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"; } -<h1>@ViewData["Title"]</h1> - -<p>Use this page to detail your site's privacy policy.</p> +<div class="text-center"> + <h2 class="display-4">Личные данные</h2> +</div> +<form method="post"> + <div class="row"> + <div class="col-4">Логин:</div> + <div class="col-8"><input type="text" name="login" + value="@Model.Login"/></div> + </div> + <div class="row"> + <div class="col-4">Пароль:</div> + <div class="col-8"><input type="password" name="password" + value="@Model.Password"/></div> + </div> + <div class="row"> + <div class="col-8"></div> + <div class="col-4"><input type="submit" value="Сохранить" class="btn + btn-primary" /></div> +</div> +</form> \ 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"; +} +<div class="text-center"> + <h2 class="display-4">Регистрация</h2> +</div> +<form method="post"> + <div class="row"> + <div class="col-4">Логин:</div> + <div class="col-8"><input type="text" name="login" /></div> + </div> + <div class="row"> + <div class="col-4">Пароль:</div> + <div class="col-8"><input type="password" name="password" /></div> + </div> + <div class="row"> + <div class="col-8"></div> + <div class="col-4"><input type="submit" value="Регистрация" + class="btn btn-primary" /></div> + </div> +</form> 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"; +} + +@{ + + <div class="text-center"> + <h2 class="display-4">Привязка процедуры</h2> + </div> + + <form method="post"> + <div class="row"> + <div class="col-4">Процедура:</div> + <div class="col-8"> + <select id="procedure" name="procedure" class="form-control" asp-items="@(new SelectList(@ViewBag.Procedures,"Id", "Name"))"></select> + </div> + </div> + <div class="row"> + <div class="col-4">Лекарство:</div> + <div class="col-8"> + <select id="medicine" name="medicine" class="form-control" asp-items="@(new SelectList(@ViewBag.Medicines,"Id", "Name"))"></select> + </div> + </div> + <div class="row"> + <div class="col-8"></div> + <div class="col-4"> + <input type="submit" value="Отправить" class="btn btn-primary" /> + </div> + </div> + </form> +} + 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) + { + <div class="text-center"> + <h2 class="display-4">Редактирование лекарства</h2> + </div> + } + else { + <div class="text-center"> + <h2 class="display-4">Создание лекарства</h2> + </div> + } + <form method="post"> + <input type="hidden" name="id" value="@Model?.Id" /> + <div class="row"> + <div class="col-4">Название:</div> + <div class="col-8"><input type="text" id="name" value="@Model?.Name" name="name" required/></div> + </div> + <div class="row"> + <div class="col-4">Цена:</div> + <div class="col-8"><input type="number" step="0.1" id="costString" value="@Model?.Cost.ToString(CultureInfo.InvariantCulture)" name="costString" required/></div> + </div> + + <div class="row"> + <div class="col-4">Дозировка:</div> + <div class="col-8"><input type="text" id="dose" value="@Model?.Dose" name="dose" required/></div> + </div> + <div class="row"> + <div class="col-8"></div> + <div class="col-4"> + <input type="submit" value="Отправить" class="btn btn-primary" /> + </div> + </div> + </form> +} + 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<MedicineViewModel> +@{ + ViewData["Title"] = "Лекарства"; +} +<div class="text-center"> + <h1 class="display-4">Лекарства</h1> +</div> +<div class="text-center"> + @{ + if (Model == null) + { + <h3 class="display-4">Авторизируйтесь</h3> + return; + } + <p> + <a asp-controller="Home" asp-action="Index">На главную</a> + <a asp-controller="Medicine" asp-action="Create">Создать лекарство</a> + <a asp-controller="Medicine" asp-action="AddProcedureMedicine">Привязать процедуру</a> + </p> + <table class="table"> + <thead> + <tr> + <th>Номер</th> + <th>Название</th> + <th>Цена</th> + <th>Дозировка</th> + <th></th> + </tr> + </thead> + <tbody> + @foreach (var item in Model) + { + <tr> + <td> + @Html.DisplayFor(modelItem => item.Id) + </td> + <td> + @Html.DisplayFor(modelItem => item.Name) + </td> + <td> + @Html.DisplayFor(modelItem => item.Cost) + </td> + <td> + @Html.DisplayFor(modelItem => item.Dose) + </td> + <td> + <a class="btn btn-warning" asp-controller="Medicine" asp-action="Create" asp-route-id="@item.Id">Редактировать</a> + <button class="btn btn-danger delete-btn" data-id="@item.Id">Удалить</button> + </td> + </tr> + } + </tbody> + </table> + } +</div> +@section scripts { + <script> + $(function () { + $(".delete-btn").click(function () { + var id = $(this).data("id"); + if (confirm("Вы действительно хотите удалить эту запись?")) { + $.post("@Url.Action("Delete", "Medicine")", { id: id }, function () { + window.location.reload(); + }); + } + }); + }); + </script> +} \ 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) + { + <div class="text-center"> + <h2 class="display-4">Редактирование поступления</h2> + </div> + } + else { + <div class="text-center"> + <h2 class="display-4">Создание поступления</h2> + </div> + } + <form method="post"> + <input type="hidden" name="id" value="@Model?.Id" /> + <div class="row"> + <div class="row"> + <div class="col-4">Лекарство:</div> + <div class="col-8"> + @{ + if (Model != null) + { + <select id="medicine" name="medicine" class="form-control" asp-items="@(new SelectList(@ViewBag.Medicines,"Id", "Name"))" value="@Model?.MedicineId" disabled="disabled"></select> + } else { + <select id="medicine" name="medicine" class="form-control" asp-items="@(new SelectList(@ViewBag.Medicines,"Id", "Name"))"></select> + } + } + </div> + </div> + + <div class="row"> + <div class="col-4">Количество:</div> + <div class="col-8"><input type="number" id="number" value="@Model?.Number" name="number"/></div> + </div> + <div class="row"> + <div class="col-8"></div> + <div class="col-4"> + <input type="submit" value="Отправить" class="btn btn-primary" /> + </div> + </div> + </form> +} + 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<PrescriptionViewModel> +@{ + ViewData["Title"] = "Поступления"; +} +<div class="text-center"> + <h1 class="display-4">Поступления</h1> +</div> +<div class="text-center"> + @{ + if (Model == null) + { + <h3 class="display-4">Авторизируйтесь</h3> + return; + } + <p> + <a asp-controller="Home" asp-action="Index">На главную</a> + <a asp-controller="Prescription" asp-action="Create">Создать поступление</a> + </p> + <table class="table"> + <thead> + <tr> + <th>Номер</th> + <th>Дата поступления</th> + <th>Лекарство</th> + <th>Количество</th> + <th></th> + </tr> + </thead> + <tbody> + @foreach (var item in Model) + { + <tr> + <td> + @Html.DisplayFor(modelItem => item.Id) + </td> + <td> + @Html.DisplayFor(modelItem => item.Date) + </td> + <td> + @Html.DisplayFor(modelItem => item.MedicineName) + </td> + <td> + @Html.DisplayFor(modelItem => item.Number) + </td> + <td> + <a class="btn btn-warning" asp-controller="Prescription" asp-action="Create" asp-route-id="@item.Id">Редактировать</a> + <button class="btn btn-danger delete-btn" data-id="@item.Id">Удалить</button> + </td> + </tr> + } + </tbody> + </table> + } +</div> +@section scripts { + <script> + $(function () { + $(".delete-btn").click(function () { + var id = $(this).data("id"); + if (confirm("Вы действительно хотите удалить эту запись?")) { + $.post("@Url.Action("Delete", "Prescription")", { id: id }, function () { + window.location.reload(); + }); + } + }); + }); + </script> +} \ 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) + { + <div class="text-center"> + <h2 class="display-4">Редактирование рецепта</h2> + </div> + } + else { + <div class="text-center"> + <h2 class="display-4">Создание рецепта</h2> + </div> + } + <form id="recipe-form" method="post"> + <input type="hidden" name="id" value="@Model?.Id" /> + <div class="row"> + <div class="col-4">Название:</div> + <div class="col-8"><input type="text" id="name" value="@Model?.Name" name="name" required/></div> + </div> + <div class="row"> + <div class="col-4">Добавление лекарств</div> + <div class="col-8"> + <select id="medicines" name="medicines" class="form-control" asp-items="@(new SelectList(@ViewBag.Medicines,"Id", "Name"))"></select> + <button type="button" onclick="addMedicine()">Добавить лекарство</button> + </div> + </div> + <div class="row"> + <table id="medicinesTable"> + <thead> + <tr> + <th>Название</th> + <th></th> + </tr> + </thead> + <tbody> + @foreach (var medicine in Model.RecipeMedicines) + { + <tr> + <td>@medicine.Value.Name</td> + <td> + <button type="button" data-id="@medicine.Key" onclick="removeMedicine('@medicine.Key')">Удалить</button> + </td> + </tr> + } + </tbody> + </table> + </div> + <div class="row"> + <div class="col-8"></div> + <div class="col-4"> + <input type="submit" value="Отправить" class="btn btn-primary" /> + </div> + </div> + @foreach (var medicine in Model.RecipeMedicines.Keys) + { + <input type="hidden" name="RecipeMedicines[@medicine]" value="@medicine"/> + } + </form> +} +@section scripts { + <script> + var recipeMedicines = @Json.Serialize(Model.RecipeMedicines); + function addMedicine() { + var medicineId = $('#medicines').val(); + var medicineName = $('#medicines option:selected').text(); + if (recipeMedicines.hasOwnProperty(medicineId)) { + alert('This medicine is already added.'); + return; + } + recipeMedicines[medicineId] = { Id: medicineId, Name: medicineName }; + var row = $('<tr>').append($('<td>').text(medicineName)); + var removeButton = $('<button>').text('Remove').attr('data-id', medicineId).click((function(id) { + return function() { + removeMedicine(id); + }; + })(medicineId)); + row.append($('<td>').append(removeButton)); + + $('#medicinesTable tbody').append(row); + var input = $('<input>').attr('type', 'hidden').attr('name', 'RecipeMedicines[' + medicineId + ']').val(medicineId); + $('#recipe-form').append(input); + } + function removeMedicine(medicineId) { + delete recipeMedicines[medicineId]; + $('#medicinesTable button[data-id="' + medicineId + '"]').closest('tr').remove(); + $('#recipe-form input[name="RecipeMedicines[' + medicineId + ']"]').remove(); + } + </script> +} + 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<RecipeViewModel> +@{ + ViewData["Title"] = "Рецепты"; +} +<div class="text-center"> + <h1 class="display-4">Рецепты</h1> +</div> +<div class="text-center"> + @{ + if (Model == null) + { + <h3 class="display-4">Авторизируйтесь</h3> + return; + } + <p> + <a asp-controller="Home" asp-action="Index">На главную</a> + <a asp-controller="Recipe" asp-action="Create">Создать рецепт</a> + </p> + <table class="table"> + <thead> + <tr> + <th>Номер</th> + <th>Дата создания рецепта</th> + <th>Название рецепта</th> + <th></th> + </tr> + </thead> + <tbody> + @foreach (var item in Model) + { + <tr> + <td> + @Html.DisplayFor(modelItem => item.Id) + </td> + <td> + @Html.DisplayFor(modelItem => item.Date) + </td> + <td> + @Html.DisplayFor(modelItem => item.Name) + </td> + <td> + <a class="btn btn-warning" asp-controller="Recipe" asp-action="Create" asp-route-id="@item.Id">Редактировать</a> + <button class="btn btn-danger delete-btn" data-id="@item.Id">Удалить</button> + </td> + </tr> + } + </tbody> + </table> + } +</div> +@section scripts { + <script> + $(function () { + $(".delete-btn").click(function () { + var id = $(this).data("id"); + if (confirm("Вы действительно хотите удалить эту запись?")) { + $.post("@Url.Action("Delete", "Recipe")", { id: id }, function () { + window.location.reload(); + }); + } + }); + }); + </script> +} \ 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 @@ <div class="navbar-collapse collapse d-sm-inline-flex justify-content-between"> <ul class="navbar-nav flex-grow-1"> <li class="nav-item"> - <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a> + <a class="nav-link text-dark" asp-area="" asp-controller="Prescription" asp-action="Prescriptions">Поступления</a> + </li> + <li class="nav-item"> + <a class="nav-link text-dark" asp-area="" asp-controller="Medicine" asp-action="Medicines">Лекарства</a> + </li> + <li class="nav-item"> + <a class="nav-link text-dark" asp-area="" asp-controller="Recipe" asp-action="Recipes">Рецепты</a> </li> <li class="nav-item"> - <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a> + <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Профиль</a> + </li> + <li class="nav-item"> + <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Enter">Вход</a> + </li> + <li class="nav-item"> + <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Register">Регистрация</a> </li> </ul> </div> @@ -38,7 +50,7 @@ <footer class="border-top footer text-muted"> <div class="container"> - © 2023 - HospitalWeb - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a> + © 2023 - HospitalWeb </div> </footer> <script src="~/lib/jquery/dist/jquery.min.js"></script> 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/" }