374 lines
13 KiB
C#
374 lines
13 KiB
C#
using HospitalClientApp.Models;
|
|
using HospitalContracts.BindingModels;
|
|
using HospitalContracts.SearchModels;
|
|
using HospitalContracts.ViewModels;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Hosting;
|
|
using System.Diagnostics;
|
|
using System.Diagnostics.Metrics;
|
|
using System.Xml.Linq;
|
|
|
|
namespace HospitalClientApp.Controllers
|
|
{
|
|
public class HomeController : Controller
|
|
{
|
|
private readonly ILogger<HomeController> _logger;
|
|
|
|
public HomeController(ILogger<HomeController> logger)
|
|
{
|
|
_logger = logger;
|
|
}
|
|
|
|
public IActionResult Index()
|
|
{
|
|
if (APIClient.Client == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
return View();
|
|
}
|
|
|
|
[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]
|
|
public IActionResult Privacy()
|
|
{
|
|
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");
|
|
}
|
|
|
|
if (!id.HasValue)
|
|
{
|
|
return View();
|
|
}
|
|
var model = APIClient.GetRequest<ProceduresViewModel?>($"api/main/getprocedure?id={id}");
|
|
return View(model);
|
|
}
|
|
[HttpPost]
|
|
public void CreateProcedure(int? id, string procedurename, string proceduretype )
|
|
{
|
|
|
|
if (APIClient.Client == null)
|
|
{
|
|
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
|
}
|
|
if (id.HasValue)
|
|
{
|
|
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}");
|
|
return View();
|
|
}
|
|
/// <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");
|
|
}
|
|
ViewBag.Medicines = APIClient.GetRequest<List<MedicinesViewModel>>("api/main/getmedicineslist");
|
|
ViewBag.Procedures = APIClient.GetRequest<List<ProceduresViewModel>>("api/main/getprocedurelist");
|
|
if (!id.HasValue)
|
|
{
|
|
return View(new RecipesViewModel());
|
|
}
|
|
var model = APIClient.GetRequest<RecipesViewModel?>($"api/main/getrecipe?id={id}");
|
|
return View(model);
|
|
|
|
}
|
|
|
|
[HttpPost]
|
|
public void CreateRecipe(RecipesBindingModel model)
|
|
{
|
|
if (APIClient.Client == null)
|
|
{
|
|
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
|
}
|
|
model.ClientId = APIClient.Client.Id;
|
|
if (model.Id != 0)
|
|
{
|
|
APIClient.PostRequest("api/main/updaterecipe", model);
|
|
}
|
|
else
|
|
{
|
|
APIClient.PostRequest("api/main/createrecipe", model);
|
|
}
|
|
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);
|
|
}
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
public IActionResult Error()
|
|
{
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
}
|
|
}
|
|
} |