REST и MVC (только CRUD)
This commit is contained in:
parent
bdd7ea44f6
commit
d431b48bf9
@ -11,9 +11,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HospitalContracts", "Hospit
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HospitalDatabaseImplement", "HospitalDatabaseImplement\HospitalDatabaseImplement.csproj", "{B99AB6C1-2F4F-4E40-B933-45CE5E6CC37B}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HospitalDatabaseImplement", "HospitalDatabaseImplement\HospitalDatabaseImplement.csproj", "{B99AB6C1-2F4F-4E40-B933-45CE5E6CC37B}"
|
||||||
EndProject
|
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
|
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
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
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}.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.ActiveCfg = Release|Any CPU
|
||||||
{A8EB3C34-5C9B-4C40-8B0F-21D62ACBFFFF}.Release|Any CPU.Build.0 = 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
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
85
Hospital/HospitalRestApi/Controllers/ApothecaryController.cs
Normal file
85
Hospital/HospitalRestApi/Controllers/ApothecaryController.cs
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
}
|
124
Hospital/HospitalRestApi/Controllers/MedicineController.cs
Normal file
124
Hospital/HospitalRestApi/Controllers/MedicineController.cs
Normal file
@ -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
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
38
Hospital/HospitalRestApi/Controllers/ProcedureController.cs
Normal file
38
Hospital/HospitalRestApi/Controllers/ProcedureController.cs
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
113
Hospital/HospitalRestApi/Controllers/RecipeController.cs
Normal file
113
Hospital/HospitalRestApi/Controllers/RecipeController.cs
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
19
Hospital/HospitalRestApi/HospitalRestApi.csproj
Normal file
19
Hospital/HospitalRestApi/HospitalRestApi.csproj
Normal file
@ -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>
|
65
Hospital/HospitalRestApi/Program.cs
Normal file
65
Hospital/HospitalRestApi/Program.cs
Normal file
@ -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();
|
31
Hospital/HospitalRestApi/Properties/launchSettings.json
Normal file
31
Hospital/HospitalRestApi/Properties/launchSettings.json
Normal file
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
8
Hospital/HospitalRestApi/appsettings.Development.json
Normal file
8
Hospital/HospitalRestApi/appsettings.Development.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
9
Hospital/HospitalRestApi/appsettings.json
Normal file
9
Hospital/HospitalRestApi/appsettings.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*"
|
||||||
|
}
|
45
Hospital/HospitalWeb/APIClient.cs
Normal file
45
Hospital/HospitalWeb/APIClient.cs
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,7 @@
|
|||||||
using HospitalWeb.Models;
|
using HospitalContracts.BindingModels;
|
||||||
|
using HospitalContracts.ViewModels;
|
||||||
|
using HospitalDatabaseImplement;
|
||||||
|
using HospitalWeb.Models;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
@ -15,14 +18,94 @@ namespace HospitalWeb.Controllers
|
|||||||
|
|
||||||
public IActionResult Index()
|
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()
|
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();
|
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)]
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||||
public IActionResult Error()
|
public IActionResult Error()
|
||||||
{
|
{
|
||||||
|
122
Hospital/HospitalWeb/Controllers/MedicineController.cs
Normal file
122
Hospital/HospitalWeb/Controllers/MedicineController.cs
Normal file
@ -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");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
85
Hospital/HospitalWeb/Controllers/PrescriptionController.cs
Normal file
85
Hospital/HospitalWeb/Controllers/PrescriptionController.cs
Normal file
@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
78
Hospital/HospitalWeb/Controllers/RecipeController.cs
Normal file
78
Hospital/HospitalWeb/Controllers/RecipeController.cs
Normal file
@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -11,12 +11,13 @@
|
|||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\HospitalBusinessLogic\HospitalBusinessLogic.csproj" />
|
|
||||||
<ProjectReference Include="..\HospitalContracts\HospitalContracts.csproj" />
|
<ProjectReference Include="..\HospitalContracts\HospitalContracts.csproj" />
|
||||||
<ProjectReference Include="..\HospitalDatabaseImplement\HospitalDatabaseImplement.csproj" />
|
<ProjectReference Include="..\HospitalDatabaseImplement\HospitalDatabaseImplement.csproj" />
|
||||||
|
<ProjectReference Include="..\HospitalDataModels\HospitalDataModels.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
|
using HospitalDatabaseImplement;
|
||||||
|
using HospitalWeb;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
builder.Services.AddControllersWithViews();
|
builder.Services.AddControllersWithViews();
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
APIClient.Connect(builder.Configuration);
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
if (!app.Environment.IsDevelopment())
|
if (!app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
@ -24,4 +27,7 @@ app.MapControllerRoute(
|
|||||||
name: "default",
|
name: "default",
|
||||||
pattern: "{controller=Home}/{action=Index}/{id?}");
|
pattern: "{controller=Home}/{action=Index}/{id?}");
|
||||||
|
|
||||||
|
LoaderFromXML.LoadProcedures();
|
||||||
|
LoaderFromXML.LoadTreatments();
|
||||||
|
LoaderFromXML.LoadPatients();
|
||||||
app.Run();
|
app.Run();
|
||||||
|
20
Hospital/HospitalWeb/Views/Home/Enter.cshtml
Normal file
20
Hospital/HospitalWeb/Views/Home/Enter.cshtml
Normal file
@ -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>
|
@ -1,8 +1,49 @@
|
|||||||
@{
|
@using HospitalContracts.ViewModels
|
||||||
|
@model List<PrescriptionViewModel>
|
||||||
|
@{
|
||||||
ViewData["Title"] = "Home Page";
|
ViewData["Title"] = "Home Page";
|
||||||
}
|
}
|
||||||
|
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<h1 class="display-4">Welcome</h1>
|
<h1 class="display-4">Поступления</h1>
|
||||||
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
|
</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>
|
</div>
|
@ -1,6 +1,25 @@
|
|||||||
@{
|
@using HospitalContracts.ViewModels
|
||||||
|
@model ApothecaryViewModel
|
||||||
|
@{
|
||||||
ViewData["Title"] = "Privacy Policy";
|
ViewData["Title"] = "Privacy Policy";
|
||||||
}
|
}
|
||||||
<h1>@ViewData["Title"]</h1>
|
<div class="text-center">
|
||||||
|
<h2 class="display-4">Личные данные</h2>
|
||||||
<p>Use this page to detail your site's privacy policy.</p>
|
</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>
|
21
Hospital/HospitalWeb/Views/Home/Register.cshtml
Normal file
21
Hospital/HospitalWeb/Views/Home/Register.cshtml
Normal file
@ -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>
|
@ -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>
|
||||||
|
}
|
||||||
|
|
43
Hospital/HospitalWeb/Views/Medicine/Create.cshtml
Normal file
43
Hospital/HospitalWeb/Views/Medicine/Create.cshtml
Normal file
@ -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>
|
||||||
|
}
|
||||||
|
|
70
Hospital/HospitalWeb/Views/Medicine/Medicines.cshtml
Normal file
70
Hospital/HospitalWeb/Views/Medicine/Medicines.cshtml
Normal file
@ -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>
|
||||||
|
}
|
48
Hospital/HospitalWeb/Views/Prescription/Create.cshtml
Normal file
48
Hospital/HospitalWeb/Views/Prescription/Create.cshtml
Normal file
@ -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>
|
||||||
|
}
|
||||||
|
|
69
Hospital/HospitalWeb/Views/Prescription/Prescriptions.cshtml
Normal file
69
Hospital/HospitalWeb/Views/Prescription/Prescriptions.cshtml
Normal file
@ -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>
|
||||||
|
}
|
96
Hospital/HospitalWeb/Views/Recipe/Create.cshtml
Normal file
96
Hospital/HospitalWeb/Views/Recipe/Create.cshtml
Normal file
@ -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>
|
||||||
|
}
|
||||||
|
|
65
Hospital/HospitalWeb/Views/Recipe/Recipes.cshtml
Normal file
65
Hospital/HospitalWeb/Views/Recipe/Recipes.cshtml
Normal file
@ -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>
|
||||||
|
}
|
@ -20,10 +20,22 @@
|
|||||||
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
|
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
|
||||||
<ul class="navbar-nav flex-grow-1">
|
<ul class="navbar-nav flex-grow-1">
|
||||||
<li class="nav-item">
|
<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>
|
||||||
<li class="nav-item">
|
<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="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">Профиль</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>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
@ -38,7 +50,7 @@
|
|||||||
|
|
||||||
<footer class="border-top footer text-muted">
|
<footer class="border-top footer text-muted">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
© 2023 - HospitalWeb - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
|
© 2023 - HospitalWeb
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||||
|
@ -5,5 +5,6 @@
|
|||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*",
|
||||||
|
"IPAddress": "http://localhost:5199/"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user