718 lines
25 KiB
C#
718 lines
25 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
||
using Microsoft.IdentityModel.Tokens;
|
||
using PolyclinicBusinessLogic.BusinessLogics;
|
||
using PolyclinicBusinessLogic.OfficePackage;
|
||
using PolyclinicContracts.BindingModels;
|
||
using PolyclinicContracts.BusinessLogicsContracts;
|
||
using PolyclinicContracts.SearchModels;
|
||
using PolyclinicContracts.ViewModels;
|
||
using PolyclinicDataModels.Enums;
|
||
using PolyclinicDataModels.Models;
|
||
using PolyclinicWebAppSuretor.Models;
|
||
using System.Diagnostics;
|
||
|
||
namespace PolyclinicWebAppSuretor.Controllers
|
||
{
|
||
public class HomeController : Controller
|
||
{
|
||
private readonly ILogger<HomeController> _logger;
|
||
private readonly IProcedureLogic _procedureLogic;
|
||
private readonly IMedicamentLogic _medicamentLogic;
|
||
private readonly IRecipeLogic _recipeLogic;
|
||
private readonly ISymptomLogic _symptomLogic;
|
||
private readonly ICourseLogic _courseLogic;
|
||
private readonly ISuretorReportLogic _suretorReportLogic;
|
||
private readonly IUserLogic _userLogic;
|
||
private readonly SendMailLogic _sendMailLogic;
|
||
|
||
public HomeController(ILogger<HomeController> logger,
|
||
IProcedureLogic procedureLogic,
|
||
IMedicamentLogic medicamentLogic,
|
||
IRecipeLogic recipeLogic,
|
||
ISymptomLogic symptomLogic,
|
||
ICourseLogic courseLogic,
|
||
ISuretorReportLogic suretorReportLogic,
|
||
IUserLogic userLogic,
|
||
SendMailLogic sendMailLogic)
|
||
{
|
||
_logger = logger;
|
||
_procedureLogic = procedureLogic;
|
||
_medicamentLogic = medicamentLogic;
|
||
_recipeLogic = recipeLogic;
|
||
_symptomLogic = symptomLogic;
|
||
_courseLogic = courseLogic;
|
||
_suretorReportLogic = suretorReportLogic;
|
||
_userLogic = userLogic;
|
||
_sendMailLogic = sendMailLogic;
|
||
}
|
||
|
||
public IActionResult Index()
|
||
{
|
||
return View();
|
||
}
|
||
|
||
public IActionResult Privacy()
|
||
{
|
||
return View();
|
||
}
|
||
|
||
/// <summary>
|
||
/// USER
|
||
/// </summary>
|
||
/// <param name="model"></param>
|
||
/// <returns></returns>
|
||
|
||
[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);
|
||
}
|
||
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);
|
||
return RedirectToAction("Login");
|
||
}
|
||
else
|
||
{
|
||
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);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// RECIPES
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
|
||
public IActionResult Recipes()
|
||
{
|
||
var currentUser = LoginManager.LogginedUser;
|
||
if (currentUser == null)
|
||
{
|
||
return RedirectToAction("Login", "Home");
|
||
}
|
||
List<RecipeViewModel> recipes = _recipeLogic.ReadList(null);
|
||
if (recipes == null)
|
||
{
|
||
recipes = new();
|
||
}
|
||
return View(recipes);
|
||
}
|
||
|
||
[HttpGet]
|
||
[HttpPost]
|
||
public IActionResult CreateRecipe(RecipeModel model, int[] selectedProcedures)
|
||
{
|
||
var currentUser = LoginManager.LogginedUser;
|
||
if (currentUser == null)
|
||
{
|
||
return RedirectToAction("Login", "Home");
|
||
}
|
||
ViewBag.Courses = _courseLogic.ReadList();
|
||
if (HttpContext.Request.Method == "GET")
|
||
{
|
||
ViewData["Title"] = "<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
||
model = new()
|
||
{
|
||
Procedures = _procedureLogic.ReadList().Select(x => (x, false)).ToList()
|
||
};
|
||
return View("CreateRecipe", model);
|
||
}
|
||
else
|
||
{
|
||
var allProcedures = _procedureLogic.ReadList(null);
|
||
|
||
RecipeBindingModel recipe = new RecipeBindingModel
|
||
{
|
||
ProceduresCount = model.RecipeViewModel.ProceduresCount,
|
||
Comment = model.RecipeViewModel.Comment,
|
||
CourseId = model.RecipeViewModel.CourseId,
|
||
RecipeProcedures = selectedProcedures
|
||
.ToDictionary(
|
||
x => x,
|
||
x => allProcedures.Where(y => y.Id == x) as IProcedureModel
|
||
)
|
||
};
|
||
|
||
_recipeLogic.Create(recipe);
|
||
return RedirectToAction("Recipes");
|
||
}
|
||
}
|
||
[HttpGet]
|
||
[HttpPost]
|
||
public IActionResult EditRecipe(int id, RecipeModel model, int[] selectedProcedures)
|
||
{
|
||
var currentUser = LoginManager.LogginedUser;
|
||
if (currentUser == null)
|
||
{
|
||
return RedirectToAction("Login", "Home");
|
||
}
|
||
ViewBag.Courses = _courseLogic.ReadList();
|
||
|
||
if (HttpContext.Request.Method == "GET")
|
||
{
|
||
var obj = _recipeLogic.ReadElement(new RecipeSearchModel { Id = id });
|
||
model = new()
|
||
{
|
||
RecipeViewModel = obj,
|
||
Procedures = _procedureLogic.ReadList().Select(x => (x, obj.RecipeProcedures.ContainsKey(x.Id))).ToList()
|
||
};
|
||
ViewData["Title"] = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
||
return View("CreateRecipe", model);
|
||
}
|
||
else
|
||
{
|
||
var allProcedures = _procedureLogic.ReadList(null);
|
||
|
||
RecipeBindingModel recipe = new RecipeBindingModel
|
||
{
|
||
Id = id,
|
||
ProceduresCount = model.RecipeViewModel.ProceduresCount,
|
||
Comment = model.RecipeViewModel.Comment,
|
||
CourseId = model.RecipeViewModel.CourseId,
|
||
RecipeProcedures = selectedProcedures
|
||
.ToDictionary(
|
||
x => x,
|
||
x => allProcedures.Where(y => y.Id == x) as IProcedureModel
|
||
)
|
||
};
|
||
_recipeLogic.Update(recipe);
|
||
return RedirectToAction("Recipes");
|
||
}
|
||
}
|
||
[HttpPost]
|
||
public IActionResult DeleteRecipe(int id)
|
||
{
|
||
var currentUser = LoginManager.LogginedUser;
|
||
if (currentUser == null)
|
||
{
|
||
return RedirectToAction("Login", "Home");
|
||
}
|
||
var obj = _recipeLogic.ReadElement(new RecipeSearchModel { Id = id });
|
||
if (obj != null)
|
||
{
|
||
_recipeLogic.Delete(new RecipeBindingModel { Id = obj.Id });
|
||
}
|
||
return RedirectToAction("Recipes");
|
||
}
|
||
|
||
/// <summary>
|
||
/// MEDICAMENTS
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
|
||
public IActionResult Medicaments()
|
||
{
|
||
var currentUser = LoginManager.LogginedUser;
|
||
if (currentUser == null)
|
||
{
|
||
return RedirectToAction("Login", "Home");
|
||
}
|
||
List<MedicamentViewModel> medicaments = _medicamentLogic.ReadList(null);
|
||
if (medicaments == null)
|
||
{
|
||
medicaments = new();
|
||
}
|
||
return View(medicaments);
|
||
}
|
||
|
||
[HttpGet]
|
||
[HttpPost]
|
||
public IActionResult CreateMedicament(MedicamentViewModel model)
|
||
{
|
||
var currentUser = LoginManager.LogginedUser;
|
||
if (currentUser == null)
|
||
{
|
||
return RedirectToAction("Login", "Home");
|
||
}
|
||
ViewBag.Procedures = _procedureLogic.ReadList(null);
|
||
ViewBag.Symptomes = _symptomLogic.ReadList(null);
|
||
if (HttpContext.Request.Method == "GET")
|
||
{
|
||
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");
|
||
}
|
||
}
|
||
|
||
[HttpGet]
|
||
[HttpPost]
|
||
public IActionResult EditMedicament(MedicamentViewModel model)
|
||
{
|
||
var currentUser = LoginManager.LogginedUser;
|
||
if (currentUser == null)
|
||
{
|
||
return RedirectToAction("Login", "User");
|
||
}
|
||
ViewBag.Procedures = _procedureLogic.ReadList(null);
|
||
ViewBag.Symptomes = _symptomLogic.ReadList(null);
|
||
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");
|
||
}
|
||
}
|
||
|
||
[HttpPost]
|
||
public IActionResult DeleteMedicament(int id)
|
||
{
|
||
var currentUser = LoginManager.LogginedUser;
|
||
if (currentUser == null)
|
||
{
|
||
return RedirectToAction("Login", "Home");
|
||
}
|
||
var obj = _medicamentLogic.ReadElement(new MedicamentSearchModel { Id = id });
|
||
if (obj != null)
|
||
{
|
||
_medicamentLogic.Delete(new MedicamentBindingModel { Id = obj.Id });
|
||
}
|
||
return RedirectToAction("Medicaments");
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// PROCEDURES
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
|
||
public IActionResult Procedures()
|
||
{
|
||
var currentUser = LoginManager.LogginedUser;
|
||
if (currentUser == null)
|
||
{
|
||
return RedirectToAction("Login", "Home");
|
||
}
|
||
List<ProcedureViewModel> procedure = _procedureLogic.ReadList(new ProcedureSearchModel { UserId = currentUser.Id});
|
||
if (procedure == null)
|
||
{
|
||
procedure = new();
|
||
}
|
||
return View(procedure);
|
||
}
|
||
|
||
[HttpGet]
|
||
[HttpPost]
|
||
public IActionResult CreateProcedure(ProcedureViewModel model)
|
||
{
|
||
var currentUser = LoginManager.LogginedUser;
|
||
if (currentUser == null)
|
||
{
|
||
return RedirectToAction("Login", "User");
|
||
}
|
||
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
|
||
{
|
||
Name = model.Name,
|
||
UserId = currentUser.Id,
|
||
Comment = model.Comment ?? string.Empty,
|
||
DateStartProcedure = model.DateStartProcedure,
|
||
DateStopProcedure = model.DateStopProcedure
|
||
};
|
||
_procedureLogic.Create(procedure);
|
||
return RedirectToAction("Procedures");
|
||
}
|
||
}
|
||
|
||
[HttpGet]
|
||
[HttpPost]
|
||
public IActionResult EditProcedure(ProcedureViewModel model)
|
||
{
|
||
var currentUser = LoginManager.LogginedUser;
|
||
if (currentUser == null)
|
||
{
|
||
return RedirectToAction("Login", "Home");
|
||
}
|
||
if (HttpContext.Request.Method == "GET")
|
||
{
|
||
var obj = _procedureLogic.ReadElement(new ProcedureSearchModel { Id = model.Id });
|
||
ViewData["Title"] = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
||
return View("CreateProcedure", obj);
|
||
}
|
||
else
|
||
{
|
||
ProcedureBindingModel procedure = new ProcedureBindingModel
|
||
{
|
||
Id = model.Id,
|
||
Name = model.Name,
|
||
Comment = model.Comment,
|
||
UserId = currentUser.Id,
|
||
DateStartProcedure = model.DateStartProcedure,
|
||
DateStopProcedure = model.DateStopProcedure
|
||
};
|
||
_procedureLogic.Update(procedure);
|
||
return RedirectToAction("Procedures");
|
||
}
|
||
}
|
||
|
||
[HttpPost]
|
||
public IActionResult DeleteProcedure(int id)
|
||
{
|
||
var currentUser = LoginManager.LogginedUser;
|
||
if (currentUser == null)
|
||
{
|
||
return RedirectToAction("Login", "Home");
|
||
}
|
||
var obj = _procedureLogic.ReadElement(new ProcedureSearchModel { Id = id });
|
||
if (obj != null)
|
||
{
|
||
_procedureLogic.Delete(new ProcedureBindingModel { Id = obj.Id });
|
||
}
|
||
return RedirectToAction("Procedures");
|
||
}
|
||
|
||
|
||
|
||
public IActionResult ListCoursesByProcedures()
|
||
{
|
||
var currentUser = LoginManager.LogginedUser;
|
||
if (currentUser == null)
|
||
{
|
||
return RedirectToAction("Login", "Home");
|
||
}
|
||
ViewBag.Procedures = _procedureLogic.ReadList(null);
|
||
return View();
|
||
}
|
||
|
||
[HttpPost]
|
||
public IActionResult CreateWordFile(int procedureId, string fileName, string fileFormat)
|
||
{
|
||
var currentUser = LoginManager.LogginedUser;
|
||
if (currentUser == null)
|
||
{
|
||
return RedirectToAction("Login", "Home");
|
||
}
|
||
var procedure = _procedureLogic.ReadElement(new ProcedureSearchModel { Id = procedureId });
|
||
ViewBag.Procedures = procedure;
|
||
|
||
fileName = fileName + $".{fileFormat}";
|
||
|
||
if (procedure == null)
|
||
{
|
||
return NotFound("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||
}
|
||
|
||
var report = new ReportBindingModel
|
||
{
|
||
FileName = fileName,
|
||
};
|
||
|
||
var procedureSearch = new ProcedureSearchModel { Id = procedureId };
|
||
|
||
procedureSearch.Name = procedure.Name;
|
||
|
||
if (fileFormat == "docx")
|
||
{
|
||
_suretorReportLogic.SaveCoursesByProcedureToWordFile(report, procedureSearch);
|
||
}
|
||
else if (fileFormat == "xlsx")
|
||
{
|
||
_suretorReportLogic.SaveCoursesByProcedureToExcelFile(report, procedureSearch);
|
||
}
|
||
|
||
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);
|
||
}
|
||
|
||
/// <summary>
|
||
// PROCEDURESREPORT
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
|
||
[HttpGet]
|
||
public IActionResult ProceduresReport()
|
||
{
|
||
var currentUser = LoginManager.LogginedUser;
|
||
if (currentUser == null)
|
||
{
|
||
return RedirectToAction("Login", "Home");
|
||
}
|
||
return View(new List<ReportProceduresViewModel>());
|
||
}
|
||
|
||
[HttpPost]
|
||
public IActionResult ProceduresReport(DateTime? dateFrom, DateTime? dateTo, string reportType)
|
||
{
|
||
var currentUser = LoginManager.LogginedUser;
|
||
if (currentUser == null)
|
||
{
|
||
return RedirectToAction("Login", "Home");
|
||
}
|
||
|
||
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();
|
||
}
|
||
|
||
if (reportType == "form")
|
||
{
|
||
return View(proceduresReport);
|
||
}
|
||
else if (reportType == "email")
|
||
{
|
||
var reportBindingModel = new ReportBindingModel
|
||
{
|
||
FileName = "ProceduresReport.pdf",
|
||
DateFrom = dateFrom,
|
||
DateTo = dateTo
|
||
};
|
||
|
||
_suretorReportLogic.SaveProceduresToPdfFile(reportBindingModel);
|
||
|
||
// <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>)
|
||
var fileName = "ProceduresReport.pdf";
|
||
var filePath = Path.Combine(Directory.GetCurrentDirectory(), fileName);
|
||
byte[] fileBytes = System.IO.File.ReadAllBytes(filePath);
|
||
|
||
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>());
|
||
}
|
||
else
|
||
{
|
||
return View(new List<ReportProceduresViewModel>());
|
||
}
|
||
}
|
||
|
||
[HttpGet]
|
||
[HttpPost]
|
||
public IActionResult AddSymptomToMedicament(AddSymptomToMedicamentModel model)
|
||
{
|
||
var currentUser = LoginManager.LogginedUser;
|
||
if (currentUser == null)
|
||
{
|
||
return RedirectToAction("Login", "Home");
|
||
}
|
||
|
||
var medicaments = _medicamentLogic.ReadList(null);
|
||
var symptomes = _symptomLogic.ReadList();
|
||
var linkedMedicaments = medicaments
|
||
.Where(x => x.SymptomId != null)
|
||
.Select(x => (x, _symptomLogic.ReadElement(new SymptomSearchModel { Id = x.SymptomId }))).ToList();
|
||
|
||
if (HttpContext.Request.Method == "GET")
|
||
{
|
||
model = new()
|
||
{
|
||
Medicaments = medicaments,
|
||
Symptoms = symptomes,
|
||
LinkedMedicaments = linkedMedicaments
|
||
};
|
||
|
||
return View(model);
|
||
}
|
||
else
|
||
{
|
||
var medicament = _medicamentLogic.ReadElement(new MedicamentSearchModel { Id = model.MedicamentId });
|
||
var medicamentBindingModel = new MedicamentBindingModel
|
||
{
|
||
Id = medicament.Id,
|
||
Name = medicament.Name,
|
||
Comment = medicament.Comment,
|
||
SymptomId = model.SymptomId,
|
||
ProcedureId = medicament.ProcedureId
|
||
};
|
||
_medicamentLogic.Update(medicamentBindingModel);
|
||
return RedirectToAction("AddSymptomToMedicament");
|
||
}
|
||
}
|
||
[HttpPost]
|
||
public IActionResult UnLinkCourse(int id)
|
||
{
|
||
var currentUser = LoginManager.LogginedUser;
|
||
if (currentUser == null)
|
||
{
|
||
return RedirectToAction("Login", "Home");
|
||
}
|
||
|
||
var medicament = _medicamentLogic.ReadElement(new MedicamentSearchModel { Id = id });
|
||
var medicamentBindingModel = new MedicamentBindingModel
|
||
{
|
||
Id = medicament.Id,
|
||
Name = medicament.Name,
|
||
Comment = medicament.Comment,
|
||
//SymptomId = null,
|
||
ProcedureId = medicament.ProcedureId
|
||
};
|
||
_medicamentLogic.Update(medicamentBindingModel);
|
||
return RedirectToAction("AddSymptomToMedicament");
|
||
}
|
||
|
||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||
public IActionResult Error()
|
||
{
|
||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||
}
|
||
}
|
||
}
|