501 lines
17 KiB
C#
501 lines
17 KiB
C#
using BankYouBankruptCashierApp.Models;
|
||
using BankYouBankruptContracts.BindingModels;
|
||
using BankYouBankruptContracts.ViewModels;
|
||
using BankYouBankruptContracts.ViewModels.Client.Default;
|
||
using BankYouBankruptDataModels.Enums;
|
||
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;
|
||
}
|
||
|
||
//вытаскивает через API клиента Get-запросом список его собственных заказов
|
||
[HttpGet]
|
||
public IActionResult Index()
|
||
{
|
||
if (APICashier.Cashier == null)
|
||
{
|
||
return Redirect("~/Home/Enter");
|
||
}
|
||
|
||
return View(APICashier.GetRequest<List<AccountViewModel>>($"/api/Account/GetAllAccounts"));
|
||
}
|
||
|
||
//изменемение ланных Get-ом
|
||
[HttpGet]
|
||
public IActionResult Privacy()
|
||
{
|
||
if (APICashier.Cashier == null)
|
||
{
|
||
return Redirect("~/Home/Enter");
|
||
}
|
||
|
||
return View(APICashier.Cashier);
|
||
}
|
||
|
||
//изменение данных Post-ом
|
||
[HttpPost]
|
||
public void Privacy(string login, string password, string name, string surname, string patronymic, string telephone, string email)
|
||
{
|
||
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) || string.IsNullOrEmpty(email))
|
||
{
|
||
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;
|
||
APICashier.Cashier.Email = email;
|
||
|
||
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("Введите логин и пароль");
|
||
}
|
||
|
||
APICashier.Cashier = APICashier.GetRequest<CashierViewModel>($"/api/Cashier/Login?login={login}&password={password}");
|
||
|
||
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/Cashier/Register", new CashierBindingModel
|
||
{
|
||
Name = name,
|
||
Surname = surname,
|
||
Patronymic = patronymic,
|
||
Email = login,
|
||
Password = password,
|
||
Telephone = telephone
|
||
});
|
||
|
||
//переход на вкладку "Enter", чтобы пользователь сразу смог зайти
|
||
Response.Redirect("Enter");
|
||
|
||
return;
|
||
}
|
||
|
||
//открытие счёта. Получаем и передаём список изделий во вьюху?
|
||
[HttpGet]
|
||
public IActionResult CreateAccount()
|
||
{
|
||
if (APICashier.Cashier == null)
|
||
{
|
||
return Redirect("~/Home/Enter");
|
||
}
|
||
|
||
//запрашиваем список в формате вспомогательной вьюшки из-за работы select в asp net
|
||
ViewBag.Clients = APICashier.GetRequest<List<ClientViewModel>>($"/api/Client/GetAllClients").Select(x => new ClientSelectViewModel
|
||
{
|
||
Id = x.Id,
|
||
FullName = x.Surname + " " + x.Name + " " + x.Patronymic
|
||
}).ToList();
|
||
|
||
return View();
|
||
}
|
||
|
||
//создание заказа Post-запросом
|
||
[HttpPost]
|
||
public void CreateAccount(int clientId, string accountNumber, string password, int balance)
|
||
{
|
||
if (APICashier.Cashier == null)
|
||
{
|
||
throw new Exception("Вы как сюда попали? Суда вход только авторизованным");
|
||
}
|
||
|
||
if (clientId <= 0)
|
||
{
|
||
throw new Exception("Некоректный ID клиента!");
|
||
}
|
||
|
||
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
|
||
{
|
||
CashierId = APICashier.Cashier.Id,
|
||
ClientId = clientId,
|
||
AccountNumber = accountNumber,
|
||
PasswordAccount = password,
|
||
Balance = balance,
|
||
DateOpen = DateTime.Now
|
||
});
|
||
|
||
Response.Redirect("Index");
|
||
}
|
||
|
||
//для страницы "Заявки на снятие"
|
||
[HttpGet]
|
||
public IActionResult Debiting()
|
||
{
|
||
if (APICashier.Cashier == null)
|
||
{
|
||
throw new Exception("Вы как сюда попали? Суда вход только авторизованным");
|
||
}
|
||
|
||
return View(APICashier.GetRequest<List<DebitingViewModel>>($"/api/Account/FindOpenDebiting"));
|
||
}
|
||
|
||
//для страницы "Заявки на зачисление"
|
||
[HttpGet]
|
||
public IActionResult Crediting()
|
||
{
|
||
if (APICashier.Cashier == null)
|
||
{
|
||
throw new Exception("Вы как сюда попали? Суда вход только авторизованным");
|
||
}
|
||
|
||
return View(APICashier.GetRequest<List<CreditingViewModel>>($"/api/Account/FindOpenCrediting"));
|
||
}
|
||
|
||
//открытие вьюхи одобрения заявки на зачисление
|
||
[HttpGet]
|
||
public IActionResult CloseCrediting()
|
||
{
|
||
if (APICashier.Cashier == null)
|
||
{
|
||
return Redirect("~/Home/Enter");
|
||
}
|
||
|
||
ViewBag.Creditings = APICashier.GetRequest<List<CreditingViewModel>>("/api/Account/FindOpenCrediting");
|
||
|
||
ViewBag.Accounts = APICashier.GetRequest<List<AccountViewModel>>("/api/Account/GetAllAccounts");
|
||
|
||
return View();
|
||
}
|
||
|
||
//одобрения заявки на зачисление Post-запросом
|
||
[HttpPost]
|
||
public void CloseCrediting(int creditingId, int accountPayeeId)
|
||
{
|
||
if (APICashier.Cashier == null)
|
||
{
|
||
throw new Exception("Вы как сюда попали? Суда вход только авторизованным");
|
||
}
|
||
|
||
if(creditingId < 0)
|
||
{
|
||
throw new Exception("Некорректный номер заявки на зачисление");
|
||
}
|
||
|
||
if (accountPayeeId < 0)
|
||
{
|
||
throw new Exception("Некорректный id счёта для зацисления средств");
|
||
}
|
||
|
||
//получаем необходимые данные для запроса
|
||
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 = accountPayeeId
|
||
});
|
||
|
||
//очистка данных
|
||
APICashier.Crediting = null;
|
||
APICashier.Card = null;
|
||
|
||
Response.Redirect("Crediting");
|
||
}
|
||
|
||
//открытие вьюхи одобрения заявки на снятие
|
||
[HttpGet]
|
||
public IActionResult CloseDebiting()
|
||
{
|
||
if (APICashier.Cashier == null)
|
||
{
|
||
return Redirect("~/Home/Enter");
|
||
}
|
||
|
||
ViewBag.Debitings = APICashier.GetRequest<List<DebitingViewModel>>("/api/Account/FindOpenDebiting");
|
||
|
||
ViewBag.Accounts = APICashier.GetRequest<List<AccountViewModel>>("/api/Account/GetAllAccounts");
|
||
|
||
return View();
|
||
}
|
||
|
||
//одобрения заявки на снятие Post-запросом
|
||
[HttpPost]
|
||
public void CloseDebiting(int debitingId, int accountId)
|
||
{
|
||
if (APICashier.Cashier == null)
|
||
{
|
||
throw new Exception("Вы как сюда попали? Суда вход только авторизованным");
|
||
}
|
||
|
||
if (debitingId < 0)
|
||
{
|
||
throw new Exception("Некорректный номер заявки на снятие");
|
||
}
|
||
|
||
if (accountId < 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,
|
||
AccountId = accountId
|
||
});
|
||
|
||
APICashier.Debiting = null;
|
||
APICashier.Card = null;
|
||
|
||
Response.Redirect("Debiting");
|
||
}
|
||
|
||
//получение номера запрашиваемого счёта для снятия
|
||
[HttpPost]
|
||
public string GetAccountNumber(int id)
|
||
{
|
||
if (APICashier.Cashier == null)
|
||
{
|
||
throw new Exception("Вы как сюда попали? Суда вход только авторизованным");
|
||
}
|
||
|
||
APICashier.Debiting = APICashier.GetRequest<DebitingViewModel>($"/api/Account/FindDebiting?id={id}");
|
||
|
||
APICashier.Crediting = APICashier.GetRequest<CreditingViewModel>($"/api/Account/FindDebiting?id={id}");
|
||
|
||
if(APICashier.Debiting == null)
|
||
{
|
||
APICashier.Card = APICashier.GetRequest<CardViewModel>($"/api/Card/FindCard?id={APICashier.Crediting.CardId}");
|
||
}
|
||
else
|
||
{
|
||
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;
|
||
}
|
||
|
||
[HttpGet]
|
||
public IActionResult MoneyTransfers()
|
||
{
|
||
if (APICashier.Cashier == null)
|
||
{
|
||
return Redirect("~/Home/Enter");
|
||
}
|
||
|
||
ViewBag.Accounts = APICashier.GetRequest<List<AccountViewModel>>("/api/Account/GetAllAccounts");
|
||
|
||
return View();
|
||
}
|
||
|
||
[HttpPost]
|
||
public void MoneyTransfers(int accountSenderId, int accountPayeeId, int sumMoneyTransfer)
|
||
{
|
||
if (APICashier.Cashier == null)
|
||
{
|
||
throw new Exception("Вы как сюда попали? Суда вход только авторизованным");
|
||
}
|
||
|
||
if (accountSenderId < 0)
|
||
{
|
||
throw new Exception("Некорректный id счёта отправителя");
|
||
}
|
||
|
||
if (accountPayeeId < 0)
|
||
{
|
||
throw new Exception("Некорректный id счёта получателя");
|
||
}
|
||
|
||
APICashier.PostRequest("/api/Account/CloseCrediting", new MoneyTransferBindingModel
|
||
{
|
||
CashierId = APICashier.Cashier.Id,
|
||
Sum = sumMoneyTransfer,
|
||
AccountPayeeId = accountPayeeId,
|
||
AccountSenderId = accountSenderId
|
||
});
|
||
|
||
Response.Redirect("Index");
|
||
}
|
||
|
||
[HttpGet]
|
||
public IActionResult ReportWithAccounts()
|
||
{
|
||
if (APICashier.Cashier == null)
|
||
{
|
||
return Redirect("~/Home/Enter");
|
||
}
|
||
|
||
ViewBag.Accounts = APICashier.GetRequest<List<AccountViewModel>>("/api/Account/GetAllAccounts");
|
||
|
||
return View(new List<ReportCashierAccountsViewModel>());
|
||
}
|
||
|
||
[HttpPost]
|
||
public IActionResult ReportWithAccounts(string accountId)
|
||
{
|
||
if (APICashier.Cashier == null)
|
||
{
|
||
return Redirect("~/Home/Enter");
|
||
}
|
||
|
||
ViewBag.Accounts = APICashier.GetRequest<List<AccountViewModel>>("/api/Account/GetAllAccounts");
|
||
var cashWithdrawals = APICashier.GetRequest<List<CashWithdrawalViewModel>>("api/Account/FindAllCashWithdrawal").Where(x => x.AccountId == int.Parse(accountId))
|
||
.Select(x => new ReportCashierAccountsViewModel
|
||
{
|
||
CashierSurname = x.SurmaneCashier,
|
||
Sum = x.Sum,
|
||
AccountSenderNumber = x.AccountNumber,
|
||
DateOperation = x.DateOperation,
|
||
typeOperation = TypeOperationEnum.Снятие
|
||
});
|
||
|
||
var moneyTransfers = APICashier.GetRequest<List<MoneyTransferViewModel>>("/api/Account/FindAllMoneyTransfer").Where(x => (x.AccountPayeeId == int.Parse(accountId) || x.AccountSenderId == int.Parse(accountId)))
|
||
.Select(x => new ReportCashierAccountsViewModel
|
||
{
|
||
CashierSurname = x.CashierSurname,
|
||
Sum = x.Sum,
|
||
AccountPayeeNumber = x.AccountPayeeNumber,
|
||
AccountSenderNumber = x.AccountSenderNumber != null ? x.AccountSenderNumber : "---",
|
||
DateOperation = x.DateOperation,
|
||
typeOperation = x.AccountSenderId.HasValue ? TypeOperationEnum.Перевод : TypeOperationEnum.Пополнение
|
||
});
|
||
|
||
return View(cashWithdrawals.Concat(moneyTransfers).OrderBy(x => x.DateOperation).ToList());
|
||
}
|
||
|
||
#region Получение отчёта PDF
|
||
|
||
[HttpGet]
|
||
public IActionResult CreateReport()
|
||
{
|
||
if (APICashier.Cashier == null)
|
||
{
|
||
return Redirect("~/Home/Enter");
|
||
}
|
||
|
||
//запрашиваем список в формате вспомогательной вьюшки из-за работы select в asp net
|
||
ViewBag.Clients = APICashier.GetRequest<List<ClientViewModel>>($"/api/Client/GetAllClients").Select(x => new ClientSelectViewModel
|
||
{
|
||
Id = x.Id,
|
||
FullName = x.Surname + " " + x.Name + " " + x.Patronymic
|
||
}).ToList();
|
||
|
||
return View();
|
||
}
|
||
|
||
[HttpPost]
|
||
public void CreateReport(int clientId, DateTime dateFrom, DateTime dateTo)
|
||
{
|
||
if (APICashier.Cashier == null)
|
||
{
|
||
throw new Exception("Не авторизованы");
|
||
}
|
||
|
||
APICashier.PostRequest("api/Report/CreateCashierReport", new ReportSupportBindingModel()
|
||
{
|
||
ClientId = clientId,
|
||
DateFrom = dateFrom,
|
||
DateTo = dateTo
|
||
});
|
||
|
||
Response.Redirect("Index");
|
||
}
|
||
|
||
#endregion
|
||
}
|
||
} |