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]
|
2023-05-17 19:18:50 +04:00
|
|
|
|
public void Privacy(string login, string password, string name, string surname, string patronymic, string telephone, string email)
|
2023-04-02 01:17:44 +04:00
|
|
|
|
{
|
|
|
|
|
if (APICashier.Cashier == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как сюда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(name)
|
2023-05-17 19:18:50 +04:00
|
|
|
|
|| string.IsNullOrEmpty(surname) || string.IsNullOrEmpty(patronymic)
|
|
|
|
|
|| string.IsNullOrEmpty(telephone) || string.IsNullOrEmpty(email))
|
2023-04-02 01:17:44 +04:00
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите логин, пароль, ФИО и телефон");
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-17 19:18:50 +04:00
|
|
|
|
APICashier.PostRequest("/api/Cashier/UpdateData", new CashierBindingModel
|
2023-04-02 01:17:44 +04:00
|
|
|
|
{
|
|
|
|
|
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;
|
2023-05-17 19:18:50 +04:00
|
|
|
|
APICashier.Cashier.Email = email;
|
2023-04-02 01:17:44 +04:00
|
|
|
|
|
|
|
|
|
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("Введите логин, пароль, ФИО и телефон");
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-17 19:29:33 +04:00
|
|
|
|
APICashier.PostRequest("/api/Cashier/Register", new CashierBindingModel
|
2023-04-02 01:17:44 +04:00
|
|
|
|
{
|
|
|
|
|
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-05-17 17:42:40 +04:00
|
|
|
|
|
|
|
|
|
//для страницы "Заявки на зачисление"
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Crediting()
|
|
|
|
|
{
|
|
|
|
|
if (APICashier.Cashier == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как сюда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return View(APICashier.GetRequest<List<CreditingViewModel>>($"/api/Account/FindOpenCrediting"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//для страницы "Переводы"
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult MoneyTransfers()
|
|
|
|
|
{
|
|
|
|
|
if (APICashier.Cashier == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как сюда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return View(APICashier.GetRequest<List<DebitingViewModel>>($"/api/Account/FindOpenDebiting"));
|
|
|
|
|
}
|
2023-05-17 18:26:43 +04:00
|
|
|
|
|
2023-05-17 19:18:50 +04:00
|
|
|
|
//открытие вьюхи одобрения заявки на зачисление
|
2023-05-17 18:26:43 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult CloseCrediting()
|
|
|
|
|
{
|
|
|
|
|
ViewBag.Creditings = APICashier.GetRequest<List<CreditingViewModel>>("/api/Account/FindOpenCrediting");
|
|
|
|
|
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-17 19:18:50 +04:00
|
|
|
|
//одобрения заявки на зачисление Post-запросом
|
2023-05-17 18:26:43 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CloseCrediting(int creditingId)
|
|
|
|
|
{
|
|
|
|
|
if (APICashier.Cashier == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как сюда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(creditingId < 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Некорректный номер заявки на зачисление");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//получаем необходимые данные для запроса
|
|
|
|
|
APICashier.Crediting = APICashier.GetRequest<CreditingViewModel>($"/api/Account/FindCrediting?id={creditingId}");
|
|
|
|
|
|
|
|
|
|
APICashier.Card = APICashier.GetRequest<CardViewModel>($"/api/Card/FindCard?id={APICashier.Crediting.CardId}");
|
|
|
|
|
|
|
|
|
|
APICashier.PostRequest("/api/Account/CloseCrediting", new MoneyTransferBindingModel
|
|
|
|
|
{
|
|
|
|
|
CashierId = APICashier.Cashier.Id,
|
|
|
|
|
CreditingId = creditingId,
|
|
|
|
|
Sum = APICashier.Crediting.Sum,
|
|
|
|
|
AccountPayeeId = APICashier.Card.AccountId
|
|
|
|
|
});
|
|
|
|
|
|
2023-05-17 19:18:50 +04:00
|
|
|
|
//очистка данных
|
|
|
|
|
APICashier.Crediting = null;
|
|
|
|
|
APICashier.Card = null;
|
|
|
|
|
|
2023-05-17 18:26:43 +04:00
|
|
|
|
Response.Redirect("Crediting");
|
|
|
|
|
}
|
2023-05-17 19:18:50 +04:00
|
|
|
|
|
|
|
|
|
//открытие вьюхи одобрения заявки на снятие
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult CloseDebiting()
|
|
|
|
|
{
|
|
|
|
|
ViewBag.Debitings = APICashier.GetRequest<List<DebitingViewModel>>("/api/Account/FindOpenDebiting");
|
|
|
|
|
|
2023-05-17 20:56:10 +04:00
|
|
|
|
ViewBag.Accounts = APICashier.GetRequest<List<AccountViewModel>>("/api/Account/GetAllAccounts");
|
|
|
|
|
|
2023-05-17 19:18:50 +04:00
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//одобрения заявки на снятие Post-запросом
|
|
|
|
|
[HttpPost]
|
2023-05-17 20:56:10 +04:00
|
|
|
|
public void CloseDebiting(int debitingId, int accountId)
|
2023-05-17 19:18:50 +04:00
|
|
|
|
{
|
|
|
|
|
if (APICashier.Cashier == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как сюда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (debitingId < 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Некорректный номер заявки на снятие");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//получаем необходимые данные для запроса
|
|
|
|
|
APICashier.Debiting = APICashier.GetRequest<DebitingViewModel>($"/api/Account/FindDebiting?id={debitingId}");
|
|
|
|
|
|
|
|
|
|
APICashier.Card = APICashier.GetRequest<CardViewModel>($"/api/Card/FindCard?id={APICashier.Debiting.CardId}");
|
|
|
|
|
|
|
|
|
|
APICashier.PostRequest("/api/Account/CloseDebiting", new CashWithdrawalBindingModel
|
|
|
|
|
{
|
|
|
|
|
CashierId = APICashier.Cashier.Id,
|
|
|
|
|
DebitingId = debitingId,
|
|
|
|
|
Sum = APICashier.Debiting.Sum,
|
2023-05-17 20:56:10 +04:00
|
|
|
|
AccountId = accountId
|
2023-05-17 19:18:50 +04:00
|
|
|
|
});
|
|
|
|
|
|
2023-05-17 20:46:40 +04:00
|
|
|
|
APICashier.Debiting = null;
|
|
|
|
|
APICashier.Card = null;
|
|
|
|
|
|
2023-05-17 19:18:50 +04:00
|
|
|
|
Response.Redirect("Debiting");
|
|
|
|
|
}
|
2023-05-17 20:46:40 +04:00
|
|
|
|
|
|
|
|
|
//получение номера запрашиваемого счёта для снятия
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public string GetAccountNumber(int debitingId)
|
|
|
|
|
{
|
|
|
|
|
APICashier.Debiting = APICashier.GetRequest<DebitingViewModel>($"/api/Account/FindDebiting?id={debitingId}");
|
|
|
|
|
|
|
|
|
|
APICashier.Card = APICashier.GetRequest<CardViewModel>($"/api/Card/FindCard?id={APICashier.Debiting.CardId}");
|
|
|
|
|
|
|
|
|
|
APICashier.Account = APICashier.GetRequest<AccountViewModel>($"/api/Account/GetAccount?accountId={APICashier.Card.AccountId}");
|
|
|
|
|
|
|
|
|
|
string AccountNumber = APICashier.Account.AccountNumber;
|
|
|
|
|
|
|
|
|
|
APICashier.Debiting = null;
|
|
|
|
|
APICashier.Card = null;
|
|
|
|
|
APICashier.Account = null;
|
|
|
|
|
|
|
|
|
|
return AccountNumber;
|
|
|
|
|
}
|
2023-04-03 17:22:59 +04:00
|
|
|
|
}
|
2023-04-02 01:17:44 +04:00
|
|
|
|
}
|