2023-04-07 01:21:27 +04:00
using HospitalClientApp.Models ;
2023-05-20 06:49:33 +04:00
using HospitalContracts.BindingModels ;
using HospitalContracts.SearchModels ;
using HospitalContracts.ViewModels ;
2023-04-07 01:21:27 +04:00
using Microsoft.AspNetCore.Mvc ;
2023-05-20 06:49:33 +04:00
using Microsoft.Extensions.Hosting ;
2023-04-07 01:21:27 +04:00
using System.Diagnostics ;
2023-05-20 06:49:33 +04:00
using System.Diagnostics.Metrics ;
2023-06-03 15:50:25 +04:00
using System.Reflection ;
2023-05-20 06:49:33 +04:00
using System.Xml.Linq ;
2023-04-07 01:21:27 +04:00
namespace HospitalClientApp.Controllers
{
public class HomeController : Controller
{
private readonly ILogger < HomeController > _logger ;
public HomeController ( ILogger < HomeController > logger )
{
_logger = logger ;
}
public IActionResult Index ( )
{
2023-05-20 06:49:33 +04:00
if ( APIClient . Client = = null )
{
return Redirect ( "~/Home/Enter" ) ;
}
2023-04-07 01:21:27 +04:00
return View ( ) ;
}
2023-05-20 06:49:33 +04:00
[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 . Client = APIClient . GetRequest < ClientViewModel > ( $"api/client/login?login={login}&password={password}" ) ;
if ( APIClient . Client = = null )
{
throw new Exception ( "Неверный логин/пароль" ) ;
}
Response . Redirect ( "Index" ) ;
}
[HttpGet]
2023-04-07 01:21:27 +04:00
public IActionResult Privacy ( )
{
2023-05-20 06:49:33 +04:00
if ( APIClient . Client = = null )
{
return Redirect ( "~/Home/Enter" ) ;
}
return View ( APIClient . Client ) ;
}
[HttpPost]
public void Privacy ( string login , string password , string fio )
{
if ( APIClient . Client = = null )
{
throw new Exception ( "Вы как сюда попали? Сюда вход только авторизованным" ) ;
}
if ( string . IsNullOrEmpty ( login ) | | string . IsNullOrEmpty ( password ) | | string . IsNullOrEmpty ( fio ) )
{
throw new Exception ( "Введите логин, пароль и ФИО" ) ;
}
APIClient . PostRequest ( "api/client/updatedata" , new ClientBindingModel
{
Id = APIClient . Client . Id ,
ClientFIO = fio ,
Email = login ,
Password = password
} ) ;
APIClient . Client . ClientFIO = fio ;
APIClient . Client . Email = login ;
APIClient . Client . Password = password ;
Response . Redirect ( "Index" ) ;
}
[HttpGet]
public IActionResult Register ( )
{
return View ( ) ;
}
[HttpPost]
public void Register ( string login , string password , string fio )
{
if ( string . IsNullOrEmpty ( login ) | | string . IsNullOrEmpty ( password ) | | string . IsNullOrEmpty ( fio ) )
{
throw new Exception ( "Введите логин, пароль и ФИО" ) ;
}
APIClient . PostRequest ( "api/client/register" , new ClientBindingModel
{
ClientFIO = fio ,
Email = login ,
Password = password
} ) ;
Response . Redirect ( "Enter" ) ;
return ;
}
/// <summary>
/// ПРОЦЕДУРЫ
/// </summary>
/// <returns></returns>
public IActionResult ListProcedures ( )
{
if ( APIClient . Client = = null )
{
return Redirect ( "~/Home/Enter" ) ;
}
return View ( APIClient . GetRequest < List < ProceduresViewModel > > ( $"api/main/GetProcedureList?ClientId={APIClient.Client.Id}" ) ) ;
}
public IActionResult CreateProcedure ( int? id )
{
if ( APIClient . Client = = null )
{
return Redirect ( "~/Home/Enter" ) ;
}
2023-06-03 15:50:25 +04:00
ViewBag . Medicines = APIClient . GetRequest < List < MedicinesViewModel > > ( "api/main/getmedicineslist" ) ;
2023-05-20 06:49:33 +04:00
if ( ! id . HasValue )
{
2023-06-03 15:50:25 +04:00
return View ( new ProceduresViewModel ( ) ) ;
2023-05-20 06:49:33 +04:00
}
var model = APIClient . GetRequest < ProceduresViewModel ? > ( $"api/main/getprocedure?id={id}" ) ;
return View ( model ) ;
}
[HttpPost]
2023-06-03 15:50:25 +04:00
public void CreateProcedure ( ProceduresBindingModel model , int? id , string procedurename , string proceduretype )
2023-05-20 06:49:33 +04:00
{
if ( APIClient . Client = = null )
{
throw new Exception ( "Вы как сюда попали? Сюда вход только авторизованным" ) ;
}
2023-06-03 15:50:25 +04:00
if ( model . Id ! = 0 )
2023-05-20 06:49:33 +04:00
{
APIClient . PostRequest ( "api/main/updateprocedure" , new ProceduresBindingModel
{
Id = id . Value ,
ProceduresName = procedurename ,
Type = proceduretype
} ) ;
}
else
{
APIClient . PostRequest ( "api/main/createprocedure" , new ProceduresBindingModel
{
ClientId = APIClient . Client . Id ,
ProceduresName = procedurename ,
Type = proceduretype
} ) ;
}
Response . Redirect ( "ListProcedures" ) ;
}
[HttpGet]
public ProceduresViewModel ? GetProcedure ( int procedureId )
{
if ( APIClient . Client = = null )
{
throw new Exception ( "Необходима авторизация" ) ;
}
var result = APIClient . GetRequest < ProceduresViewModel > ( $"api/main/getprocedure?procedureid={procedureId}" ) ;
if ( result = = null )
{
return default ;
}
var proceduresName = result . ProceduresName ;
var proceduretype = result . Type ;
return result ;
}
[HttpPost]
public void DeleteProcedure ( int procedure )
{
if ( APIClient . Client = = null )
{
throw new Exception ( "Доступно только авторизованным пользователям" ) ;
}
APIClient . PostRequest ( $"api/main/DeleteProcedure" , new ProceduresBindingModel { Id = procedure } ) ;
Response . Redirect ( "ListProcedures" ) ;
}
public IActionResult DeleteProcedure ( )
{
if ( APIClient . Client = = null )
{
return Redirect ( "~/Home/Enter" ) ;
}
ViewBag . Procedures = APIClient . GetRequest < List < ProceduresViewModel > > ( $"api/main/getprocedurelist?clientId={APIClient.Client.Id}" ) ;
2023-04-07 01:21:27 +04:00
return View ( ) ;
}
2023-06-03 15:50:25 +04:00
//[HttpGet]
//public IActionResult AddDrugCourse()
//{
// if (APIClient.Client == null)
// {
// return Redirect("~/Home/Enter");
// }
// ViewBag.Medicines = APIClient.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicines");
// ViewBag.DrugCourses = APIClient.GetRequest<List<DrugCourseViewModel>>($"api/drugcourse/getdrugcourses");
// return View();
//}
//[HttpPost]
//public void AddMedicineDrugCourse(int medicine, int drugcourse)
//{
// if (APIClient.Client == null)
// {
// throw new Exception("Доступно только авторизованным пользователям");
// }
// APIClient.PostRequest($"api/medicine/addmedicinedrugcourse", (new DrugCourseBindingModel { Id = drugcourse }, new MedicineBindingModel { Id = medicine }));
// Response.Redirect("ListDrugCourses");
//}
2023-05-20 06:49:33 +04:00
/// <summary>
/// ЛЕКАРСТВА
/// </summary>
/// <returns></returns>
public IActionResult ListMedicines ( )
{
if ( APIClient . Client = = null )
{
return Redirect ( "~/Home/Enter" ) ;
}
return View ( APIClient . GetRequest < List < MedicinesViewModel > > ( $"api/main/getmedicineslist?clientId={APIClient.Client.Id}" ) ) ;
}
public IActionResult CreateMedicine ( int? id )
{
if ( APIClient . Client = = null )
{
return Redirect ( "~/Home/Enter" ) ;
}
if ( ! id . HasValue )
{
return View ( ) ;
}
var model = APIClient . GetRequest < MedicinesViewModel ? > ( $"api/main/getmedicine?id={id}" ) ;
return View ( model ) ;
}
[HttpPost]
public void CreateMedicine ( int? id , string namemedicine , string group )
{
if ( APIClient . Client = = null )
{
throw new Exception ( "Вы как сюда попали? Сюда вход только авторизованным" ) ;
}
if ( id . HasValue )
{
APIClient . PostRequest ( "api/main/updatemedicine" , new MedicinesBindingModel
{
Id = id . Value ,
MedicinesName = namemedicine ,
Group = group
} ) ;
}
else
{
APIClient . PostRequest ( "api/main/createmedicine" , new MedicinesBindingModel
{
ClientId = APIClient . Client . Id ,
MedicinesName = namemedicine ,
Group = group
} ) ;
}
Response . Redirect ( "ListMedicines" ) ;
}
[HttpGet]
public MedicinesViewModel ? GetMedicine ( int medicineId )
{
if ( APIClient . Client = = null )
{
throw new Exception ( "Необходима авторизация" ) ;
}
var result = APIClient . GetRequest < MedicinesViewModel > ( $"api/main/getmedicine?medicineid={medicineId}" ) ;
if ( result = = null )
{
return default ;
}
var medicineName = result . MedicinesName ;
var group = result . Group ;
return result ;
}
[HttpPost]
public void DeleteMedicine ( int medicine )
{
if ( APIClient . Client = = null )
{
throw new Exception ( "Доступно только авторизованным пользователям" ) ;
}
APIClient . PostRequest ( $"api/main/DeleteMedicine" , new ProceduresBindingModel { Id = medicine } ) ;
Response . Redirect ( "ListMedicines" ) ;
}
public IActionResult DeleteMedicine ( )
{
if ( APIClient . Client = = null )
{
return Redirect ( "~/Home/Enter" ) ;
}
ViewBag . Medicines = APIClient . GetRequest < List < MedicinesViewModel > > ( $"api/main/GetMedicinesList?clientId={APIClient.Client.Id}" ) ;
return View ( ) ;
}
/// <summary>
/// РЕЦЕПТЫ
/// </summary>
/// <returns></returns>
public IActionResult ListRecipes ( )
{
if ( APIClient . Client = = null )
{
return Redirect ( "~/Home/Enter" ) ;
}
return View ( APIClient . GetRequest < List < RecipesViewModel > > ( $"api/main/getrecipeslist?clientId={APIClient.Client.Id}" ) ) ;
}
public IActionResult CreateRecipe ( int? id )
{
if ( APIClient . Client = = null )
{
return Redirect ( "~/Home/Enter" ) ;
}
2023-06-03 15:50:25 +04:00
ViewBag . Symptomses = APIClient . GetRequest < List < SymptomsViewModel > > ( "api/main/getsymptoms" ) ;
2023-05-20 06:49:33 +04:00
ViewBag . Procedures = APIClient . GetRequest < List < ProceduresViewModel > > ( "api/main/getprocedurelist" ) ;
if ( ! id . HasValue )
{
return View ( new RecipesViewModel ( ) ) ;
}
2023-06-03 15:50:25 +04:00
var model = APIClient . GetRequest < ProceduresViewModel ? > ( $"api/main/getprocedure?id={id}" ) ;
2023-05-20 06:49:33 +04:00
return View ( model ) ;
}
[HttpPost]
2023-06-03 15:50:25 +04:00
public void CreateRecipe ( RecipesBindingModel model , int? id , int symptoms , string dose , string modeofapplication )
2023-05-20 06:49:33 +04:00
{
if ( APIClient . Client = = null )
{
throw new Exception ( "Вы как сюда попали? Сюда вход только авторизованным" ) ;
}
model . ClientId = APIClient . Client . Id ;
if ( model . Id ! = 0 )
{
APIClient . PostRequest ( "api/main/updaterecipe" , model ) ;
}
else
{
2023-06-03 15:50:25 +04:00
APIClient . PostRequest ( "api/main/createrecipe" , new RecipesBindingModel
{
ClientId = APIClient . Client . Id ,
Dose = dose ,
SymptomsId = symptoms ,
ModeOfApplication = modeofapplication
} ) ;
2023-05-20 06:49:33 +04:00
}
Response . Redirect ( "ListRecipes" ) ;
}
[HttpGet]
public Tuple < RecipesViewModel , string > ? GetRecipe ( int recipeId )
{
if ( APIClient . Client = = null )
{
throw new Exception ( "Необходима авторизация" ) ;
}
var result = APIClient . GetRequest < Tuple < RecipesViewModel , List < Tuple < string , string > > > > ( $"api/main/getrecipe?recipeId={recipeId}" ) ;
if ( result = = null )
{
return default ;
}
string table = "" ;
for ( int i = 0 ; i < result . Item2 . Count ; i + + )
{
var proceduresName = result . Item2 [ i ] . Item1 ;
var type = result . Item2 [ i ] . Item2 ;
table + = "<tr style=\"height: 44px\">" ;
table + = $"<td class=\" u - border - 1 u - border - grey - 30 u - table - cell \ ">{proceduresName}</td>" ;
table + = $"<td class=\" u - border - 1 u - border - grey - 30 u - table - cell \ ">{type}</td>" ;
table + = "</tr>" ;
}
return Tuple . Create ( result . Item1 , table ) ;
}
2023-06-03 15:50:25 +04:00
[HttpPost]
public void DeleteRecipe ( int recipe )
{
if ( APIClient . Client = = null )
{
throw new Exception ( "Доступно только авторизованным пользователям" ) ;
}
APIClient . PostRequest ( $"api/main/DeleteRecipe" , new RecipesBindingModel { Id = recipe } ) ;
Response . Redirect ( "ListRecipes" ) ;
}
public IActionResult DeleteRecipe ( )
{
if ( APIClient . Client = = null )
{
return Redirect ( "~/Home/Enter" ) ;
}
ViewBag . Recipes = APIClient . GetRequest < List < RecipesViewModel > > ( $"api/main/GetRecipesList?clientId={APIClient.Client.Id}" ) ;
return View ( ) ;
}
2023-04-07 01:21:27 +04:00
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error ( )
{
return View ( new ErrorViewModel { RequestId = Activity . Current ? . Id ? ? HttpContext . TraceIdentifier } ) ;
}
}
}