2023-04-02 01:17:44 +04:00
|
|
|
|
using BankYouBankruptCashierApp.Models;
|
|
|
|
|
using BankYouBankruptContracts.BindingModels;
|
|
|
|
|
using BankYouBankruptContracts.ViewModels;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
|
|
|
|
|
namespace BankYouBankruptCashierApp.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class HomeController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<HomeController> _logger;
|
|
|
|
|
|
|
|
|
|
public HomeController(ILogger<HomeController> logger)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-17 00:06:05 +04:00
|
|
|
|
//вытаскивает через API клиента Get-запросом список его собственных заказов
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Index()
|
2023-04-02 01:17:44 +04:00
|
|
|
|
{
|
|
|
|
|
if (APICashier.Cashier == null)
|
|
|
|
|
{
|
2023-05-17 00:06:05 +04:00
|
|
|
|
return Redirect("~/Home/Enter");
|
2023-04-02 01:17:44 +04:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-17 00:06:05 +04:00
|
|
|
|
return View(APICashier.GetRequest<List<AccountViewModel>>($"/api/Account/GetAllAccounts"));
|
2023-04-02 01:17:44 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//изменемение ланных Get-ом
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Privacy()
|
|
|
|
|
{
|
|
|
|
|
if (APICashier.Cashier == null)
|
|
|
|
|
{
|
2023-05-17 00:06:05 +04:00
|
|
|
|
return Redirect("~/Home/Enter");
|
2023-04-02 01:17:44 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return View(APICashier.Cashier);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//изменение данных Post-ом
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Privacy(string login, string password, string name, string surname, string patronymic, string telephone)
|
|
|
|
|
{
|
|
|
|
|
if (APICashier.Cashier == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как сюда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(name)
|
|
|
|
|
|| string.IsNullOrEmpty(surname) || string.IsNullOrEmpty(patronymic) || string.IsNullOrEmpty(telephone))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите логин, пароль, ФИО и телефон");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
APICashier.PostRequest("api/cashier/updatedata", new CashierBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = APICashier.Cashier.Id,
|
|
|
|
|
Name = name,
|
|
|
|
|
Surname = surname,
|
|
|
|
|
Patronymic = patronymic,
|
|
|
|
|
Telephone = telephone,
|
|
|
|
|
Email = login,
|
|
|
|
|
Password = password
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
APICashier.Cashier.Name = name;
|
|
|
|
|
APICashier.Cashier.Surname = surname;
|
|
|
|
|
APICashier.Cashier.Patronymic = patronymic;
|
|
|
|
|
APICashier.Cashier.Email = login;
|
|
|
|
|
APICashier.Cashier.Password = password;
|
|
|
|
|
APICashier.Cashier.Telephone = telephone;
|
|
|
|
|
|
|
|
|
|
Response.Redirect("Index");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
|
|
|
public IActionResult Error()
|
|
|
|
|
{
|
|
|
|
|
return View(new ErrorViewModel
|
|
|
|
|
{
|
|
|
|
|
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//просто открытие вьюхи
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Enter()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//отсылаем указанные данные на проверку
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Enter(string login, string password)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите логин и пароль");
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-17 00:06:05 +04:00
|
|
|
|
APICashier.Cashier = APICashier.GetRequest<CashierViewModel>($"/api/Cashier/Login?login={login}&password={password}");
|
2023-04-02 01:17:44 +04:00
|
|
|
|
|
|
|
|
|
if (APICashier.Cashier == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Неверный логин/пароль");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Response.Redirect("Index");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//просто открытие вьюхи
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Register()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Post-запрос по созданию нового пользователя
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Register(string login, string password, string name, string surname, string patronymic, string telephone)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(name)
|
|
|
|
|
|| string.IsNullOrEmpty(surname) || string.IsNullOrEmpty(patronymic) || string.IsNullOrEmpty(telephone))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите логин, пароль, ФИО и телефон");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
APICashier.PostRequest("api/client/register", new CashierBindingModel
|
|
|
|
|
{
|
|
|
|
|
Name = name,
|
|
|
|
|
Surname = surname,
|
|
|
|
|
Patronymic = patronymic,
|
|
|
|
|
Email = login,
|
|
|
|
|
Password = password,
|
|
|
|
|
Telephone = telephone
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//переход на вкладку "Enter", чтобы пользователь сразу смог зайти
|
|
|
|
|
Response.Redirect("Enter");
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-17 00:59:57 +04:00
|
|
|
|
//открытие счёта. Получаем и передаём список изделий во вьюху?
|
|
|
|
|
[HttpGet]
|
2023-04-02 01:17:44 +04:00
|
|
|
|
public IActionResult Create()
|
|
|
|
|
{
|
2023-05-17 00:59:57 +04:00
|
|
|
|
ViewBag.Clients = APICashier.GetRequest<List<ClientViewModel>>("/api/Client/GetAllClients");
|
2023-04-02 01:17:44 +04:00
|
|
|
|
|
|
|
|
|
return View();
|
2023-05-17 00:59:57 +04:00
|
|
|
|
}
|
2023-04-02 01:17:44 +04:00
|
|
|
|
|
|
|
|
|
//создание заказа Post-запросом
|
|
|
|
|
[HttpPost]
|
2023-05-17 00:59:57 +04:00
|
|
|
|
public void Create(int clientId, string accountNumber, string password, int balance)
|
2023-04-02 01:17:44 +04:00
|
|
|
|
{
|
|
|
|
|
if (APICashier.Cashier == null)
|
|
|
|
|
{
|
2023-05-17 00:59:57 +04:00
|
|
|
|
throw new Exception("Вы как сюда попали? Суда вход только авторизованным");
|
2023-04-02 01:17:44 +04:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-17 00:59:57 +04:00
|
|
|
|
if (clientId <= 0)
|
2023-04-02 01:17:44 +04:00
|
|
|
|
{
|
2023-05-17 00:59:57 +04:00
|
|
|
|
throw new Exception("Некоректный ID клиента!");
|
2023-04-02 01:17:44 +04:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-17 00:59:57 +04:00
|
|
|
|
if (string.IsNullOrEmpty(accountNumber) && accountNumber.Length < 8)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Некорректный номер счёта");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(password) && password.Length < 6)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Некорректный пароль");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
APICashier.PostRequest("/api/Account/Register", new AccountBindingModel
|
2023-04-02 01:17:44 +04:00
|
|
|
|
{
|
2023-05-17 00:59:57 +04:00
|
|
|
|
CashierId = APICashier.Cashier.Id,
|
|
|
|
|
ClientId = clientId,
|
|
|
|
|
AccountNumber = accountNumber,
|
|
|
|
|
PasswordAccount = password,
|
|
|
|
|
Balance = balance,
|
|
|
|
|
DateOpen = DateTime.Now
|
2023-04-02 01:17:44 +04:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Response.Redirect("Index");
|
|
|
|
|
}
|
2023-04-03 17:22:59 +04:00
|
|
|
|
|
|
|
|
|
//открытие формы отчёта. Получаем и передаём список изделий во вьюху?
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult CreateReport()
|
|
|
|
|
{
|
2023-05-17 00:06:05 +04:00
|
|
|
|
ViewBag.Accountes = APICashier.GetRequest<List<AccountViewModel>>("api/main/getaccountlist");
|
2023-04-03 17:22:59 +04:00
|
|
|
|
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//создание отчёта Post-запросом
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateReport(DateTime DateFrom, DateTime DateTo)
|
|
|
|
|
{
|
|
|
|
|
if (APICashier.Cashier == null)
|
|
|
|
|
{
|
2023-05-17 00:06:05 +04:00
|
|
|
|
throw new Exception("Вы как сюда попали? Суда вход только авторизованным");
|
2023-04-03 17:22:59 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (DateFrom > DateTo)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Дата начала периода не может быть позже даты конца периода");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
APICashier.PostRequest("api/main/createreport", new ReportBindingModel
|
|
|
|
|
{
|
|
|
|
|
FileName = APICashier.Cashier.Surname
|
|
|
|
|
|
|
|
|
|
//TODO
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Response.Redirect("Index");
|
|
|
|
|
}
|
2023-05-17 17:13:57 +04:00
|
|
|
|
|
|
|
|
|
//для страницы "Заявки на снятие"
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Debiting()
|
|
|
|
|
{
|
|
|
|
|
if (APICashier.Cashier == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как сюда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return View(APICashier.GetRequest<List<DebitingViewModel>>($"/api/Account/FindOpenDebiting"));
|
|
|
|
|
}
|
2023-04-03 17:22:59 +04:00
|
|
|
|
}
|
2023-04-02 01:17:44 +04:00
|
|
|
|
}
|