2024-04-30 16:53:50 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2024-05-29 23:07:34 +04:00
|
|
|
|
using Microsoft.IdentityModel.Tokens;
|
2024-05-26 18:16:46 +04:00
|
|
|
|
using PolyclinicBusinessLogic.BusinessLogics;
|
2024-05-29 01:12:32 +04:00
|
|
|
|
using PolyclinicBusinessLogic.OfficePackage;
|
2024-05-26 18:16:46 +04:00
|
|
|
|
using PolyclinicContracts.BindingModels;
|
2024-05-26 13:45:07 +04:00
|
|
|
|
using PolyclinicContracts.BusinessLogicsContracts;
|
2024-05-26 18:16:46 +04:00
|
|
|
|
using PolyclinicContracts.SearchModels;
|
2024-05-26 13:45:07 +04:00
|
|
|
|
using PolyclinicContracts.ViewModels;
|
2024-05-29 23:07:34 +04:00
|
|
|
|
using PolyclinicDataModels.Enums;
|
2024-05-28 16:55:59 +04:00
|
|
|
|
using PolyclinicDataModels.Models;
|
2024-04-30 16:53:50 +04:00
|
|
|
|
using PolyclinicWebAppSuretor.Models;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
|
|
|
|
namespace PolyclinicWebAppSuretor.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class HomeController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<HomeController> _logger;
|
2024-05-26 13:45:07 +04:00
|
|
|
|
private readonly IProcedureLogic _procedureLogic;
|
2024-05-28 00:17:46 +04:00
|
|
|
|
private readonly IMedicamentLogic _medicamentLogic;
|
|
|
|
|
private readonly IRecipeLogic _recipeLogic;
|
|
|
|
|
private readonly ISymptomLogic _symptomLogic;
|
2024-05-28 16:55:59 +04:00
|
|
|
|
private readonly ICourseLogic _courseLogic;
|
2024-05-29 01:12:32 +04:00
|
|
|
|
private readonly ISuretorReportLogic _suretorReportLogic;
|
2024-05-29 12:35:30 +04:00
|
|
|
|
private readonly IUserLogic _userLogic;
|
2024-05-30 01:42:23 +04:00
|
|
|
|
private readonly SendMailLogic _sendMailLogic;
|
2024-04-30 16:53:50 +04:00
|
|
|
|
|
2024-05-28 00:17:46 +04:00
|
|
|
|
public HomeController(ILogger<HomeController> logger,
|
|
|
|
|
IProcedureLogic procedureLogic,
|
|
|
|
|
IMedicamentLogic medicamentLogic,
|
|
|
|
|
IRecipeLogic recipeLogic,
|
2024-05-28 16:55:59 +04:00
|
|
|
|
ISymptomLogic symptomLogic,
|
2024-05-29 01:12:32 +04:00
|
|
|
|
ICourseLogic courseLogic,
|
2024-05-29 12:35:30 +04:00
|
|
|
|
ISuretorReportLogic suretorReportLogic,
|
2024-05-30 01:42:23 +04:00
|
|
|
|
IUserLogic userLogic,
|
|
|
|
|
SendMailLogic sendMailLogic)
|
2024-04-30 16:53:50 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
2024-05-26 13:45:07 +04:00
|
|
|
|
_procedureLogic = procedureLogic;
|
2024-05-28 00:17:46 +04:00
|
|
|
|
_medicamentLogic = medicamentLogic;
|
|
|
|
|
_recipeLogic = recipeLogic;
|
|
|
|
|
_symptomLogic = symptomLogic;
|
2024-05-28 16:55:59 +04:00
|
|
|
|
_courseLogic = courseLogic;
|
2024-05-29 01:12:32 +04:00
|
|
|
|
_suretorReportLogic = suretorReportLogic;
|
2024-05-29 12:35:30 +04:00
|
|
|
|
_userLogic = userLogic;
|
2024-05-30 01:42:23 +04:00
|
|
|
|
_sendMailLogic = sendMailLogic;
|
2024-04-30 16:53:50 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult Index()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult Privacy()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-29 23:07:34 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// USER
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
2024-05-29 12:35:30 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public IActionResult Register(RegisterModel model)
|
|
|
|
|
{
|
|
|
|
|
var errors = new List<string>();
|
|
|
|
|
|
|
|
|
|
if (HttpContext.Request.Method == "POST")
|
|
|
|
|
{
|
|
|
|
|
var userEmail = _userLogic.ReadElement(new UserSearchModel { Email = model.Email });
|
|
|
|
|
if (userEmail != null) errors.Add("<22><><EFBFBD><EFBFBD> Email <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
if (model.Password != model.ConfirmPassword) errors.Add("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
if (errors.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
model.Errors = errors;
|
|
|
|
|
model.Email = string.Empty;
|
|
|
|
|
model.ConfirmPassword = string.Empty;
|
|
|
|
|
model.FIO = model.FIO;
|
|
|
|
|
return View(model);
|
|
|
|
|
}
|
2024-05-29 23:07:34 +04:00
|
|
|
|
var user = new UserBindingModel
|
|
|
|
|
{
|
|
|
|
|
FIO = model.FIO,
|
|
|
|
|
Email = model.Email,
|
|
|
|
|
Password = model.Password,
|
|
|
|
|
Role = UserRole.<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
};
|
|
|
|
|
_userLogic.Create(user);
|
2024-05-29 12:35:30 +04:00
|
|
|
|
return RedirectToAction("Login");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-05-29 23:07:34 +04:00
|
|
|
|
return View(model);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public IActionResult Login(LoginModel model)
|
|
|
|
|
{
|
|
|
|
|
var errors = new List<string>();
|
|
|
|
|
if (HttpContext.Request.Method == "POST")
|
|
|
|
|
{
|
|
|
|
|
var user = _userLogic.ReadElement(new UserSearchModel { Email = model.Email, Password = model.Password });
|
|
|
|
|
if (user == null)
|
|
|
|
|
{
|
|
|
|
|
errors.Add("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
}
|
|
|
|
|
else if (user.Role != UserRole.<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
|
|
|
|
{
|
|
|
|
|
errors.Add("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>");
|
|
|
|
|
}
|
|
|
|
|
if (errors.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
model = new LoginModel
|
|
|
|
|
{
|
|
|
|
|
Errors = errors
|
|
|
|
|
};
|
|
|
|
|
return View(model);
|
|
|
|
|
}
|
|
|
|
|
LoginManager.LogginedUser = user;
|
|
|
|
|
return RedirectToAction("", "Home");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
model = new();
|
|
|
|
|
return View(model);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public IActionResult Logout()
|
|
|
|
|
{
|
|
|
|
|
LoginManager.LogginedUser = null;
|
|
|
|
|
return RedirectToAction("Login");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public IActionResult Privacy(UserPrivacyModel model)
|
|
|
|
|
{
|
|
|
|
|
var currentUser = LoginManager.LogginedUser;
|
|
|
|
|
if (currentUser == null)
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("Login");
|
|
|
|
|
}
|
|
|
|
|
if (HttpContext.Request.Method == "POST")
|
|
|
|
|
{
|
|
|
|
|
var errors = new List<string>();
|
|
|
|
|
var checkedUser = _userLogic.ReadElement(new UserSearchModel { Email = model.Email });
|
|
|
|
|
if (checkedUser != null && checkedUser.Id != LoginManager.LogginedUser.Id)
|
|
|
|
|
{
|
|
|
|
|
errors.Add("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD> Email <20><><EFBFBD> <20><><EFBFBD><EFBFBD>");
|
|
|
|
|
}
|
|
|
|
|
if (model.Password != model.ConfirmPassword)
|
|
|
|
|
{
|
|
|
|
|
errors.Add("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
}
|
|
|
|
|
if (errors.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
model.Errors = errors;
|
|
|
|
|
model.Password = string.Empty;
|
|
|
|
|
model.ConfirmPassword = string.Empty;
|
|
|
|
|
return View(model);
|
|
|
|
|
}
|
|
|
|
|
var user = new UserBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = currentUser.Id,
|
|
|
|
|
FIO = model.FIO,
|
|
|
|
|
Email = model.Email,
|
|
|
|
|
Password = model.Password.IsNullOrEmpty() ? LoginManager.LogginedUser.Password : model.Password,
|
|
|
|
|
};
|
|
|
|
|
_userLogic.Update(user);
|
|
|
|
|
LoginManager.LogginedUser = _userLogic.ReadElement(new UserSearchModel { Id = model.Id });
|
|
|
|
|
return RedirectToAction("Privacy");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
model = new()
|
|
|
|
|
{
|
|
|
|
|
Id = currentUser.Id,
|
|
|
|
|
FIO = currentUser.FIO,
|
|
|
|
|
Email = currentUser.Email,
|
|
|
|
|
Role = currentUser.Role
|
|
|
|
|
};
|
|
|
|
|
return View(model);
|
2024-05-29 12:35:30 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-29 02:59:50 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// RECIPES
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
2024-05-28 00:17:46 +04:00
|
|
|
|
public IActionResult Recipes()
|
|
|
|
|
{
|
2024-05-29 23:48:37 +04:00
|
|
|
|
var currentUser = LoginManager.LogginedUser;
|
|
|
|
|
if (currentUser == null)
|
|
|
|
|
{
|
2024-05-30 01:42:23 +04:00
|
|
|
|
return RedirectToAction("Login", "Home");
|
2024-05-29 23:48:37 +04:00
|
|
|
|
}
|
2024-05-28 00:17:46 +04:00
|
|
|
|
List<RecipeViewModel> recipes = _recipeLogic.ReadList(null);
|
|
|
|
|
if (recipes == null)
|
|
|
|
|
{
|
|
|
|
|
recipes = new();
|
|
|
|
|
}
|
|
|
|
|
return View(recipes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[HttpPost]
|
2024-05-28 16:55:59 +04:00
|
|
|
|
public IActionResult CreateRecipe(RecipeModel model, int[] selectedProcedures)
|
2024-05-28 00:17:46 +04:00
|
|
|
|
{
|
2024-05-29 23:48:37 +04:00
|
|
|
|
var currentUser = LoginManager.LogginedUser;
|
|
|
|
|
if (currentUser == null)
|
|
|
|
|
{
|
2024-05-30 01:42:23 +04:00
|
|
|
|
return RedirectToAction("Login", "Home");
|
2024-05-29 23:48:37 +04:00
|
|
|
|
}
|
2024-05-29 02:59:50 +04:00
|
|
|
|
ViewBag.Courses = _courseLogic.ReadList();
|
2024-05-28 00:17:46 +04:00
|
|
|
|
if (HttpContext.Request.Method == "GET")
|
|
|
|
|
{
|
|
|
|
|
ViewData["Title"] = "<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
2024-05-28 16:55:59 +04:00
|
|
|
|
model = new()
|
|
|
|
|
{
|
2024-05-29 12:35:30 +04:00
|
|
|
|
Procedures = _procedureLogic.ReadList().Select(x => (x, false)).ToList()
|
2024-05-28 16:55:59 +04:00
|
|
|
|
};
|
|
|
|
|
return View("CreateRecipe", model);
|
2024-05-28 00:17:46 +04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-05-28 16:55:59 +04:00
|
|
|
|
var allProcedures = _procedureLogic.ReadList(null);
|
|
|
|
|
|
2024-05-28 00:17:46 +04:00
|
|
|
|
RecipeBindingModel recipe = new RecipeBindingModel
|
|
|
|
|
{
|
2024-05-29 01:12:32 +04:00
|
|
|
|
ProceduresCount = model.RecipeViewModel.ProceduresCount,
|
|
|
|
|
Comment = model.RecipeViewModel.Comment,
|
2024-05-29 02:26:50 +04:00
|
|
|
|
CourseId = model.RecipeViewModel.CourseId,
|
2024-05-29 01:12:32 +04:00
|
|
|
|
RecipeProcedures = selectedProcedures
|
2024-05-28 16:55:59 +04:00
|
|
|
|
.ToDictionary(
|
|
|
|
|
x => x,
|
2024-05-29 12:35:30 +04:00
|
|
|
|
x => allProcedures.Where(y => y.Id == x) as IProcedureModel
|
2024-05-28 16:55:59 +04:00
|
|
|
|
)
|
2024-05-28 00:17:46 +04:00
|
|
|
|
};
|
2024-05-29 02:26:50 +04:00
|
|
|
|
|
2024-05-28 00:17:46 +04:00
|
|
|
|
_recipeLogic.Create(recipe);
|
2024-05-28 16:55:59 +04:00
|
|
|
|
return RedirectToAction("Recipes");
|
2024-05-28 00:17:46 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[HttpPost]
|
2024-05-28 16:55:59 +04:00
|
|
|
|
public IActionResult EditRecipe(int id, RecipeModel model, int[] selectedProcedures)
|
2024-05-28 00:17:46 +04:00
|
|
|
|
{
|
2024-05-29 23:48:37 +04:00
|
|
|
|
var currentUser = LoginManager.LogginedUser;
|
|
|
|
|
if (currentUser == null)
|
|
|
|
|
{
|
2024-05-30 01:42:23 +04:00
|
|
|
|
return RedirectToAction("Login", "Home");
|
2024-05-29 23:48:37 +04:00
|
|
|
|
}
|
2024-05-29 12:35:30 +04:00
|
|
|
|
ViewBag.Courses = _courseLogic.ReadList();
|
|
|
|
|
|
2024-05-28 00:17:46 +04:00
|
|
|
|
if (HttpContext.Request.Method == "GET")
|
|
|
|
|
{
|
2024-05-28 16:55:59 +04:00
|
|
|
|
var obj = _recipeLogic.ReadElement(new RecipeSearchModel { Id = id });
|
|
|
|
|
model = new()
|
|
|
|
|
{
|
|
|
|
|
RecipeViewModel = obj,
|
2024-05-29 12:35:30 +04:00
|
|
|
|
Procedures = _procedureLogic.ReadList().Select(x => (x, obj.RecipeProcedures.ContainsKey(x.Id))).ToList()
|
2024-05-28 16:55:59 +04:00
|
|
|
|
};
|
2024-05-29 12:35:30 +04:00
|
|
|
|
ViewData["Title"] = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
2024-05-28 16:55:59 +04:00
|
|
|
|
return View("CreateRecipe", model);
|
2024-05-28 00:17:46 +04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-05-28 16:55:59 +04:00
|
|
|
|
var allProcedures = _procedureLogic.ReadList(null);
|
|
|
|
|
|
|
|
|
|
RecipeBindingModel recipe = new RecipeBindingModel
|
2024-05-28 00:17:46 +04:00
|
|
|
|
{
|
2024-05-28 16:55:59 +04:00
|
|
|
|
Id = id,
|
|
|
|
|
ProceduresCount = model.RecipeViewModel.ProceduresCount,
|
|
|
|
|
Comment = model.RecipeViewModel.Comment,
|
2024-05-29 02:26:50 +04:00
|
|
|
|
CourseId = model.RecipeViewModel.CourseId,
|
2024-05-28 16:55:59 +04:00
|
|
|
|
RecipeProcedures = selectedProcedures
|
|
|
|
|
.ToDictionary(
|
|
|
|
|
x => x,
|
2024-05-29 12:35:30 +04:00
|
|
|
|
x => allProcedures.Where(y => y.Id == x) as IProcedureModel
|
2024-05-28 16:55:59 +04:00
|
|
|
|
)
|
2024-05-28 00:17:46 +04:00
|
|
|
|
};
|
2024-05-28 16:55:59 +04:00
|
|
|
|
_recipeLogic.Update(recipe);
|
|
|
|
|
return RedirectToAction("Recipes");
|
2024-05-28 00:17:46 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public IActionResult DeleteRecipe(int id)
|
|
|
|
|
{
|
2024-05-29 23:48:37 +04:00
|
|
|
|
var currentUser = LoginManager.LogginedUser;
|
|
|
|
|
if (currentUser == null)
|
|
|
|
|
{
|
2024-05-30 01:42:23 +04:00
|
|
|
|
return RedirectToAction("Login", "Home");
|
2024-05-29 23:48:37 +04:00
|
|
|
|
}
|
2024-05-28 16:55:59 +04:00
|
|
|
|
var obj = _recipeLogic.ReadElement(new RecipeSearchModel { Id = id });
|
2024-05-28 00:17:46 +04:00
|
|
|
|
if (obj != null)
|
|
|
|
|
{
|
2024-05-28 16:55:59 +04:00
|
|
|
|
_recipeLogic.Delete(new RecipeBindingModel { Id = obj.Id });
|
2024-05-28 00:17:46 +04:00
|
|
|
|
}
|
2024-05-28 16:55:59 +04:00
|
|
|
|
return RedirectToAction("Recipes");
|
2024-05-28 00:17:46 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-29 02:59:50 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// MEDICAMENTS
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
2024-04-30 19:59:10 +04:00
|
|
|
|
public IActionResult Medicaments()
|
|
|
|
|
{
|
2024-05-29 23:48:37 +04:00
|
|
|
|
var currentUser = LoginManager.LogginedUser;
|
|
|
|
|
if (currentUser == null)
|
|
|
|
|
{
|
2024-05-30 01:42:23 +04:00
|
|
|
|
return RedirectToAction("Login", "Home");
|
2024-05-29 23:48:37 +04:00
|
|
|
|
}
|
2024-05-28 00:17:46 +04:00
|
|
|
|
List<MedicamentViewModel> medicaments = _medicamentLogic.ReadList(null);
|
|
|
|
|
if (medicaments == null)
|
|
|
|
|
{
|
|
|
|
|
medicaments = new();
|
|
|
|
|
}
|
|
|
|
|
return View(medicaments);
|
2024-04-30 19:59:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-28 00:17:46 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public IActionResult CreateMedicament(MedicamentViewModel model)
|
2024-04-30 19:59:10 +04:00
|
|
|
|
{
|
2024-05-29 23:48:37 +04:00
|
|
|
|
var currentUser = LoginManager.LogginedUser;
|
|
|
|
|
if (currentUser == null)
|
|
|
|
|
{
|
2024-05-30 01:42:23 +04:00
|
|
|
|
return RedirectToAction("Login", "Home");
|
2024-05-29 23:48:37 +04:00
|
|
|
|
}
|
2024-05-28 00:17:46 +04:00
|
|
|
|
ViewBag.Procedures = _procedureLogic.ReadList(null);
|
|
|
|
|
ViewBag.Symptomes = _symptomLogic.ReadList(null);
|
|
|
|
|
if (HttpContext.Request.Method == "GET")
|
2024-05-26 13:45:07 +04:00
|
|
|
|
{
|
2024-05-28 00:17:46 +04:00
|
|
|
|
ViewData["Title"] = "<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// TODO <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> UserId
|
|
|
|
|
MedicamentBindingModel medicament = new MedicamentBindingModel
|
|
|
|
|
{
|
|
|
|
|
Name = model.Name,
|
|
|
|
|
Comment = model.Comment ?? string.Empty,
|
|
|
|
|
SymptomId = model.SymptomId,
|
|
|
|
|
ProcedureId = model.ProcedureId,
|
|
|
|
|
};
|
|
|
|
|
_medicamentLogic.Create(medicament);
|
|
|
|
|
return RedirectToAction("Medicaments");
|
2024-05-26 13:45:07 +04:00
|
|
|
|
}
|
2024-04-30 19:59:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-28 00:17:46 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public IActionResult EditMedicament(MedicamentViewModel model)
|
2024-04-30 19:59:10 +04:00
|
|
|
|
{
|
2024-05-29 23:48:37 +04:00
|
|
|
|
var currentUser = LoginManager.LogginedUser;
|
|
|
|
|
if (currentUser == null)
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("Login", "User");
|
|
|
|
|
}
|
2024-05-28 21:53:46 +04:00
|
|
|
|
ViewBag.Procedures = _procedureLogic.ReadList(null);
|
|
|
|
|
ViewBag.Symptomes = _symptomLogic.ReadList(null);
|
2024-05-28 00:17:46 +04:00
|
|
|
|
if (HttpContext.Request.Method == "GET")
|
|
|
|
|
{
|
|
|
|
|
var obj = _medicamentLogic.ReadElement(new MedicamentSearchModel { Id = model.Id });
|
|
|
|
|
ViewData["Title"] = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|
|
|
|
return View("CreateMedicament", obj);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MedicamentBindingModel medicament = new MedicamentBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
Name = model.Name,
|
|
|
|
|
Comment = model.Comment ?? string.Empty,
|
|
|
|
|
SymptomId = model.SymptomId,
|
|
|
|
|
ProcedureId = model.ProcedureId,
|
|
|
|
|
};
|
|
|
|
|
_medicamentLogic.Update(medicament);
|
|
|
|
|
return RedirectToAction("Medicaments");
|
|
|
|
|
}
|
2024-04-30 19:59:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-28 00:17:46 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public IActionResult DeleteMedicament(int id)
|
2024-04-30 21:24:45 +04:00
|
|
|
|
{
|
2024-05-29 23:48:37 +04:00
|
|
|
|
var currentUser = LoginManager.LogginedUser;
|
|
|
|
|
if (currentUser == null)
|
|
|
|
|
{
|
2024-05-30 01:42:23 +04:00
|
|
|
|
return RedirectToAction("Login", "Home");
|
2024-05-29 23:48:37 +04:00
|
|
|
|
}
|
2024-05-28 00:17:46 +04:00
|
|
|
|
var obj = _medicamentLogic.ReadElement(new MedicamentSearchModel { Id = id });
|
|
|
|
|
if (obj != null)
|
|
|
|
|
{
|
|
|
|
|
_medicamentLogic.Delete(new MedicamentBindingModel { Id = obj.Id });
|
|
|
|
|
}
|
|
|
|
|
return RedirectToAction("Medicaments");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-05-29 23:48:37 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// PROCEDURES
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
2024-05-28 00:17:46 +04:00
|
|
|
|
public IActionResult Procedures()
|
|
|
|
|
{
|
2024-05-29 23:48:37 +04:00
|
|
|
|
var currentUser = LoginManager.LogginedUser;
|
|
|
|
|
if (currentUser == null)
|
|
|
|
|
{
|
2024-05-30 01:42:23 +04:00
|
|
|
|
return RedirectToAction("Login", "Home");
|
2024-05-29 23:48:37 +04:00
|
|
|
|
}
|
2024-05-30 01:42:23 +04:00
|
|
|
|
List<ProcedureViewModel> procedure = _procedureLogic.ReadList(new ProcedureSearchModel { UserId = currentUser.Id});
|
2024-05-28 00:17:46 +04:00
|
|
|
|
if (procedure == null)
|
|
|
|
|
{
|
|
|
|
|
procedure = new();
|
|
|
|
|
}
|
|
|
|
|
return View(procedure);
|
2024-04-30 21:24:45 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-26 18:16:46 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
[HttpPost]
|
2024-05-27 21:27:51 +04:00
|
|
|
|
public IActionResult CreateProcedure(ProcedureViewModel model)
|
2024-05-01 00:55:32 +04:00
|
|
|
|
{
|
2024-05-29 23:48:37 +04:00
|
|
|
|
var currentUser = LoginManager.LogginedUser;
|
|
|
|
|
if (currentUser == null)
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("Login", "User");
|
|
|
|
|
}
|
2024-05-26 18:16:46 +04:00
|
|
|
|
if (HttpContext.Request.Method == "GET")
|
|
|
|
|
{
|
|
|
|
|
ViewData["Title"] = "<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// TODO <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> UserId
|
|
|
|
|
ProcedureBindingModel procedure = new ProcedureBindingModel
|
|
|
|
|
{
|
2024-05-27 21:27:51 +04:00
|
|
|
|
Name = model.Name,
|
2024-05-30 01:42:23 +04:00
|
|
|
|
UserId = currentUser.Id,
|
2024-05-27 21:27:51 +04:00
|
|
|
|
Comment = model.Comment ?? string.Empty,
|
|
|
|
|
DateStartProcedure = model.DateStartProcedure,
|
|
|
|
|
DateStopProcedure = model.DateStopProcedure
|
2024-05-26 18:16:46 +04:00
|
|
|
|
};
|
|
|
|
|
_procedureLogic.Create(procedure);
|
|
|
|
|
return RedirectToAction("Procedures");
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-27 19:09:14 +04:00
|
|
|
|
|
2024-05-26 18:16:46 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
[HttpPost]
|
2024-05-27 19:09:14 +04:00
|
|
|
|
public IActionResult EditProcedure(ProcedureViewModel model)
|
2024-05-26 18:16:46 +04:00
|
|
|
|
{
|
2024-05-29 23:48:37 +04:00
|
|
|
|
var currentUser = LoginManager.LogginedUser;
|
|
|
|
|
if (currentUser == null)
|
|
|
|
|
{
|
2024-05-30 01:42:23 +04:00
|
|
|
|
return RedirectToAction("Login", "Home");
|
2024-05-29 23:48:37 +04:00
|
|
|
|
}
|
2024-05-26 18:16:46 +04:00
|
|
|
|
if (HttpContext.Request.Method == "GET")
|
|
|
|
|
{
|
2024-05-27 19:09:14 +04:00
|
|
|
|
var obj = _procedureLogic.ReadElement(new ProcedureSearchModel { Id = model.Id });
|
2024-05-26 18:16:46 +04:00
|
|
|
|
ViewData["Title"] = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
2024-05-27 19:09:14 +04:00
|
|
|
|
return View("CreateProcedure", obj);
|
2024-05-26 18:16:46 +04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ProcedureBindingModel procedure = new ProcedureBindingModel
|
|
|
|
|
{
|
2024-05-27 19:09:14 +04:00
|
|
|
|
Id = model.Id,
|
|
|
|
|
Name = model.Name,
|
|
|
|
|
Comment = model.Comment,
|
2024-05-30 01:42:23 +04:00
|
|
|
|
UserId = currentUser.Id,
|
2024-05-27 19:09:14 +04:00
|
|
|
|
DateStartProcedure = model.DateStartProcedure,
|
|
|
|
|
DateStopProcedure = model.DateStopProcedure
|
2024-05-26 18:16:46 +04:00
|
|
|
|
};
|
|
|
|
|
_procedureLogic.Update(procedure);
|
|
|
|
|
return RedirectToAction("Procedures");
|
|
|
|
|
}
|
2024-05-01 00:55:32 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-27 21:27:51 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public IActionResult DeleteProcedure(int id)
|
|
|
|
|
{
|
2024-05-29 23:48:37 +04:00
|
|
|
|
var currentUser = LoginManager.LogginedUser;
|
|
|
|
|
if (currentUser == null)
|
|
|
|
|
{
|
2024-05-30 01:42:23 +04:00
|
|
|
|
return RedirectToAction("Login", "Home");
|
2024-05-29 23:48:37 +04:00
|
|
|
|
}
|
2024-05-27 21:27:51 +04:00
|
|
|
|
var obj = _procedureLogic.ReadElement(new ProcedureSearchModel { Id = id });
|
|
|
|
|
if (obj != null)
|
|
|
|
|
{
|
|
|
|
|
_procedureLogic.Delete(new ProcedureBindingModel { Id = obj.Id });
|
|
|
|
|
}
|
|
|
|
|
return RedirectToAction("Procedures");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-28 18:46:06 +04:00
|
|
|
|
public IActionResult AddSymptomToMedicament(AddSymptomToMedicamentModel model)
|
2024-05-01 18:01:42 +04:00
|
|
|
|
{
|
2024-05-29 23:48:37 +04:00
|
|
|
|
var currentUser = LoginManager.LogginedUser;
|
|
|
|
|
if (currentUser == null)
|
|
|
|
|
{
|
2024-05-30 01:42:23 +04:00
|
|
|
|
return RedirectToAction("Login", "Home");
|
2024-05-29 23:48:37 +04:00
|
|
|
|
}
|
2024-05-28 18:46:06 +04:00
|
|
|
|
model = new()
|
|
|
|
|
{
|
|
|
|
|
Medicaments = _medicamentLogic.ReadList(null),
|
|
|
|
|
Symptoms = _symptomLogic.ReadList(null)
|
|
|
|
|
};
|
|
|
|
|
return View(model);
|
2024-05-01 18:01:42 +04:00
|
|
|
|
}
|
2024-05-27 19:09:14 +04:00
|
|
|
|
|
2024-05-29 01:12:32 +04:00
|
|
|
|
public IActionResult ListCoursesByProcedures()
|
|
|
|
|
{
|
2024-05-29 23:48:37 +04:00
|
|
|
|
var currentUser = LoginManager.LogginedUser;
|
|
|
|
|
if (currentUser == null)
|
|
|
|
|
{
|
2024-05-30 01:42:23 +04:00
|
|
|
|
return RedirectToAction("Login", "Home");
|
2024-05-29 23:48:37 +04:00
|
|
|
|
}
|
2024-05-29 01:12:32 +04:00
|
|
|
|
ViewBag.Procedures = _procedureLogic.ReadList(null);
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public IActionResult CreateWordFile(int procedureId, string fileName, string fileFormat)
|
|
|
|
|
{
|
2024-05-29 23:48:37 +04:00
|
|
|
|
var currentUser = LoginManager.LogginedUser;
|
|
|
|
|
if (currentUser == null)
|
|
|
|
|
{
|
2024-05-30 01:42:23 +04:00
|
|
|
|
return RedirectToAction("Login", "Home");
|
2024-05-29 23:48:37 +04:00
|
|
|
|
}
|
2024-05-29 12:35:30 +04:00
|
|
|
|
var procedure = _procedureLogic.ReadElement(new ProcedureSearchModel { Id = procedureId });
|
2024-05-29 01:12:32 +04:00
|
|
|
|
ViewBag.Procedures = procedure;
|
|
|
|
|
|
|
|
|
|
fileName = fileName + $".{fileFormat}";
|
|
|
|
|
|
2024-05-29 12:35:30 +04:00
|
|
|
|
if (procedure == null)
|
2024-05-29 01:12:32 +04:00
|
|
|
|
{
|
|
|
|
|
return NotFound("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var report = new ReportBindingModel
|
|
|
|
|
{
|
|
|
|
|
FileName = fileName,
|
|
|
|
|
};
|
|
|
|
|
|
2024-05-29 12:35:30 +04:00
|
|
|
|
var procedureSearch = new ProcedureSearchModel { Id = procedureId };
|
2024-05-29 01:12:32 +04:00
|
|
|
|
|
2024-05-29 14:01:29 +04:00
|
|
|
|
procedureSearch.Name = procedure.Name;
|
|
|
|
|
|
2024-05-29 01:12:32 +04:00
|
|
|
|
if (fileFormat == "docx")
|
|
|
|
|
{
|
2024-05-29 12:35:30 +04:00
|
|
|
|
_suretorReportLogic.SaveCoursesByProcedureToWordFile(report, procedureSearch);
|
2024-05-29 01:12:32 +04:00
|
|
|
|
}
|
2024-05-29 21:16:38 +04:00
|
|
|
|
else if (fileFormat == "xlsx")
|
2024-05-29 14:01:29 +04:00
|
|
|
|
{
|
|
|
|
|
_suretorReportLogic.SaveCoursesByProcedureToExcelFile(report, procedureSearch);
|
|
|
|
|
}
|
2024-05-29 01:12:32 +04:00
|
|
|
|
|
|
|
|
|
var filePath = Path.Combine(Directory.GetCurrentDirectory(), fileName);
|
|
|
|
|
byte[] fileBytes = System.IO.File.ReadAllBytes(filePath);
|
|
|
|
|
string mimeType = fileFormat.ToLower() == "docx" ? "application/vnd.openxmlformats-officedocument.wordprocessingml.document" : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
|
|
|
return File(fileBytes, mimeType, fileName);
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-29 21:16:38 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
// PROCEDURESREPORT
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
2024-05-01 18:01:42 +04:00
|
|
|
|
[HttpGet]
|
2024-05-29 23:48:37 +04:00
|
|
|
|
public IActionResult ProceduresReport()
|
2024-05-29 21:16:38 +04:00
|
|
|
|
{
|
2024-05-29 23:48:37 +04:00
|
|
|
|
var currentUser = LoginManager.LogginedUser;
|
|
|
|
|
if (currentUser == null)
|
|
|
|
|
{
|
2024-05-30 01:42:23 +04:00
|
|
|
|
return RedirectToAction("Login", "Home");
|
2024-05-29 23:48:37 +04:00
|
|
|
|
}
|
2024-05-29 21:16:38 +04:00
|
|
|
|
return View(new List<ReportProceduresViewModel>());
|
2024-05-29 23:48:37 +04:00
|
|
|
|
}
|
2024-05-29 21:16:38 +04:00
|
|
|
|
|
2024-05-01 18:01:42 +04:00
|
|
|
|
[HttpPost]
|
2024-05-29 21:16:38 +04:00
|
|
|
|
public IActionResult ProceduresReport(DateTime? dateFrom, DateTime? dateTo, string reportType)
|
2024-05-01 18:01:42 +04:00
|
|
|
|
{
|
2024-05-29 23:48:37 +04:00
|
|
|
|
var currentUser = LoginManager.LogginedUser;
|
|
|
|
|
if (currentUser == null)
|
|
|
|
|
{
|
2024-05-30 01:42:23 +04:00
|
|
|
|
return RedirectToAction("Login", "Home");
|
2024-05-29 23:48:37 +04:00
|
|
|
|
}
|
2024-05-29 21:16:38 +04:00
|
|
|
|
|
2024-05-30 01:42:23 +04:00
|
|
|
|
var proceduresReport = _suretorReportLogic.GetProceduresByMedicametsAndSymptoms();
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>)
|
|
|
|
|
if (dateFrom.HasValue)
|
|
|
|
|
{
|
|
|
|
|
proceduresReport = proceduresReport.Where(p => p.DateStartProcedure >= dateFrom.Value).ToList();
|
|
|
|
|
}
|
|
|
|
|
if (dateTo.HasValue)
|
|
|
|
|
{
|
|
|
|
|
proceduresReport = proceduresReport.Where(p => p.DateStopProcedure <= dateTo.Value).ToList();
|
|
|
|
|
}
|
2024-05-29 21:16:38 +04:00
|
|
|
|
|
2024-05-30 01:42:23 +04:00
|
|
|
|
if (reportType == "form")
|
|
|
|
|
{
|
2024-05-29 21:16:38 +04:00
|
|
|
|
return View(proceduresReport);
|
|
|
|
|
}
|
|
|
|
|
else if (reportType == "email")
|
|
|
|
|
{
|
|
|
|
|
var reportBindingModel = new ReportBindingModel
|
|
|
|
|
{
|
|
|
|
|
FileName = "ProceduresReport.pdf",
|
|
|
|
|
DateFrom = dateFrom,
|
|
|
|
|
DateTo = dateTo
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_suretorReportLogic.SaveProceduresToPdfFile(reportBindingModel);
|
|
|
|
|
|
2024-05-30 01:42:23 +04:00
|
|
|
|
// <20><><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><> <20> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
2024-05-29 21:16:38 +04:00
|
|
|
|
var fileName = "ProceduresReport.pdf";
|
2024-05-29 21:42:34 +04:00
|
|
|
|
var filePath = Path.Combine(Directory.GetCurrentDirectory(), fileName);
|
|
|
|
|
byte[] fileBytes = System.IO.File.ReadAllBytes(filePath);
|
2024-05-30 01:42:23 +04:00
|
|
|
|
|
|
|
|
|
if (System.IO.File.Exists(filePath))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var userEmail = currentUser.Email;
|
|
|
|
|
_sendMailLogic.SendEmail(userEmail, $"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, {currentUser.FIO}! <20><><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!", filePath);
|
|
|
|
|
|
|
|
|
|
TempData["Message"] = $"<22><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> .pdf <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> '{currentUser.Email}'";
|
|
|
|
|
return File(fileBytes, "application/pdf", fileName);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
TempData["Error"] = $"Error while sending email: {ex.Message}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
TempData["Error"] = "Failed to generate the report.";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return View(new List<ReportProceduresViewModel>());
|
2024-05-01 18:01:42 +04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-05-29 21:16:38 +04:00
|
|
|
|
return View(new List<ReportProceduresViewModel>());
|
2024-05-01 18:01:42 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-30 16:53:50 +04:00
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
|
|
|
public IActionResult Error()
|
|
|
|
|
{
|
|
|
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|