2024-05-01 03:06:53 +04:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2024-05-29 23:12:32 +04:00
|
|
|
|
using VeterinaryClinicBusinessLogics.MailWorker;
|
2024-05-29 11:23:13 +04:00
|
|
|
|
using VeterinaryClinicContracts.BindingModels;
|
|
|
|
|
using VeterinaryClinicContracts.BusinessLogicsContracts;
|
|
|
|
|
using VeterinaryClinicContracts.SearchModels;
|
|
|
|
|
using VeterinaryClinicDataModels.Enums;
|
2024-05-01 03:06:53 +04:00
|
|
|
|
using VeterinaryClinicWebApp.Models;
|
|
|
|
|
|
|
|
|
|
namespace VeterinaryClinicWebApp.Controllers;
|
|
|
|
|
|
|
|
|
|
public class HomeController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<HomeController> _logger;
|
|
|
|
|
|
2024-05-29 11:23:13 +04:00
|
|
|
|
private readonly IUserLogic _userLogic;
|
|
|
|
|
|
2024-05-29 23:12:32 +04:00
|
|
|
|
private readonly IAnimalLogic _animalLogic;
|
|
|
|
|
|
|
|
|
|
private readonly IReportLogic _reportLogic;
|
|
|
|
|
|
|
|
|
|
private readonly AbstractMailWorker _mailLogic;
|
|
|
|
|
|
|
|
|
|
public HomeController(ILogger<HomeController> logger,
|
|
|
|
|
IUserLogic userLogic,
|
|
|
|
|
IAnimalLogic animalLogic,
|
|
|
|
|
IReportLogic reportLogic,
|
|
|
|
|
AbstractMailWorker mailLogic)
|
2024-05-01 03:06:53 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
2024-05-29 11:23:13 +04:00
|
|
|
|
_userLogic = userLogic;
|
2024-05-29 23:12:32 +04:00
|
|
|
|
_animalLogic = animalLogic;
|
|
|
|
|
_reportLogic = reportLogic;
|
|
|
|
|
_mailLogic = mailLogic;
|
2024-05-01 03:06:53 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-29 11:23:13 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Index()
|
2024-05-01 03:06:53 +04:00
|
|
|
|
{
|
2024-05-29 11:23:13 +04:00
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
2024-05-01 03:06:53 +04:00
|
|
|
|
|
2024-05-29 11:23:13 +04:00
|
|
|
|
return View(APIClient.User);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Privacy()
|
2024-05-01 03:06:53 +04:00
|
|
|
|
{
|
2024-05-29 11:23:13 +04:00
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return View(APIClient.User);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Privacy(string fullname, UserRole role, string phone, string email, string password) {
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(fullname) || string.IsNullOrEmpty(phone) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
|
|
|
|
}
|
2024-05-01 03:06:53 +04:00
|
|
|
|
|
2024-05-29 11:23:13 +04:00
|
|
|
|
_userLogic.Update(new UserBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = APIClient.User.Id,
|
|
|
|
|
FullName = fullname,
|
|
|
|
|
Role = role,
|
|
|
|
|
Phone = phone,
|
|
|
|
|
Email = email,
|
|
|
|
|
Password = password
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
APIClient.User.FullName = fullname;
|
|
|
|
|
APIClient.User.Role = role;
|
|
|
|
|
APIClient.User.Phone = phone;
|
|
|
|
|
APIClient.User.Email = email;
|
|
|
|
|
APIClient.User.Password = password;
|
|
|
|
|
|
|
|
|
|
Response.Redirect("Privacy");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Enter()
|
2024-05-01 23:10:05 +04:00
|
|
|
|
{
|
2024-05-29 11:23:13 +04:00
|
|
|
|
if (APIClient.User != null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("<22><> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Enter(string email, string password)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
APIClient.User = _userLogic.ReadElement(new UserSearchModel
|
|
|
|
|
{
|
|
|
|
|
Email = email,
|
|
|
|
|
Password = password
|
|
|
|
|
});
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>/<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Response.Redirect("Index");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet]
|
2024-05-01 23:10:05 +04:00
|
|
|
|
public IActionResult Register()
|
|
|
|
|
{
|
2024-05-29 11:23:13 +04:00
|
|
|
|
if (APIClient.User != null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("<22><> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-01 23:10:05 +04:00
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-29 11:23:13 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Register(string fullname, UserRole role, string phone, string email, string password)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(fullname) || string.IsNullOrEmpty(phone) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_userLogic.Create(new UserBindingModel
|
|
|
|
|
{
|
|
|
|
|
FullName = fullname,
|
|
|
|
|
Role = role,
|
|
|
|
|
Phone = phone,
|
|
|
|
|
Email = email,
|
|
|
|
|
Password = password
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Response.Redirect("Enter");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-29 16:14:54 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public void Logout()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
|
|
|
|
}
|
2024-05-29 11:23:13 +04:00
|
|
|
|
|
2024-05-29 16:14:54 +04:00
|
|
|
|
APIClient.User = null;
|
|
|
|
|
Response.Redirect("Enter");
|
|
|
|
|
}
|
2024-05-29 11:23:13 +04:00
|
|
|
|
|
2024-05-29 16:14:54 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
2024-05-29 23:12:32 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Reports()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public IActionResult Reports(DateTime dateFrom, DateTime dateTo)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dateFrom == DateTime.MinValue || dateTo == DateTime.MinValue)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var data = _reportLogic.GetVisitsInfo(new ReportBindingModel
|
|
|
|
|
{
|
|
|
|
|
DateFrom = dateFrom,
|
|
|
|
|
DateTo = dateTo,
|
|
|
|
|
UserId = APIClient.User.Id
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return View(data);
|
|
|
|
|
}
|
2024-05-29 11:23:13 +04:00
|
|
|
|
|
2024-05-29 16:14:54 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Word
|
|
|
|
|
/// </summary>
|
2024-05-29 23:12:32 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateReportWord()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_reportLogic.SaveAnimalServicesToWordFile(new ReportBindingModel
|
|
|
|
|
{
|
|
|
|
|
FileName = $@"D:\ {DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss")}.docx",
|
|
|
|
|
UserId = APIClient.User.Id
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Response.Redirect("/Home/Reports");
|
|
|
|
|
}
|
2024-05-29 11:23:13 +04:00
|
|
|
|
|
2024-05-29 16:14:54 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Excel
|
|
|
|
|
/// </summary>
|
2024-05-29 23:12:32 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateReportExcel()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_reportLogic.SaveAnimalServicesToExcelFile(new ReportBindingModel
|
|
|
|
|
{
|
|
|
|
|
FileName = $@"D:\ {DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss")}.xlsx",
|
|
|
|
|
UserId = APIClient.User.Id
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Response.Redirect("/Home/Reports");
|
|
|
|
|
}
|
2024-05-29 11:23:13 +04:00
|
|
|
|
|
2024-05-29 16:14:54 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Pdf
|
|
|
|
|
/// </summary>
|
2024-05-29 23:12:32 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateReportPdf(DateTime dateFrom, DateTime dateTo)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dateFrom == DateTime.MinValue || dateTo == DateTime.MinValue)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_reportLogic.SaveVisitsInfoToPdfFile(new ReportBindingModel
|
|
|
|
|
{
|
|
|
|
|
FileName = $@"D:\ {DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss")}.pdf",
|
|
|
|
|
UserId = APIClient.User.Id,
|
|
|
|
|
DateFrom = dateFrom,
|
|
|
|
|
DateTo = dateTo
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Response.Redirect("/Home/Reports");
|
|
|
|
|
}
|
2024-05-29 11:23:13 +04:00
|
|
|
|
|
2024-05-29 16:14:54 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
2024-05-29 23:12:32 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void SendReport(IFormFile fileUpload)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fileUpload == null || fileUpload.Length <= 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("<22><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD>!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
var uploadPath = @"D:\";
|
|
|
|
|
var fileName = Path.GetFileName(fileUpload.FileName);
|
|
|
|
|
var fullPath = Path.Combine(uploadPath, fileName);
|
|
|
|
|
|
|
|
|
|
_mailLogic.MailSendAsync(new MailSendInfoBindingModel
|
|
|
|
|
{
|
|
|
|
|
MailAddress = APIClient.User.Email,
|
|
|
|
|
Subject = $"{fileName.Split('.')[0]}",
|
|
|
|
|
Text = $"<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> {DateTime.Now}",
|
|
|
|
|
Path = fullPath
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Response.Redirect("/Home/Reports");
|
|
|
|
|
}
|
2024-05-29 16:14:54 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
2024-05-01 03:06:53 +04:00
|
|
|
|
public IActionResult Error()
|
|
|
|
|
{
|
|
|
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
|
|
|
}
|
|
|
|
|
}
|