2023-04-07 23:40:48 +04:00
|
|
|
|
using BankContracts.BindingModels;
|
|
|
|
|
using BankContracts.ViewModels;
|
2023-04-07 19:49:24 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2023-04-07 23:40:48 +04:00
|
|
|
|
using BankOperatorApp.Models;
|
2023-04-07 19:49:24 +04:00
|
|
|
|
using System.Diagnostics;
|
2023-05-19 21:52:31 +04:00
|
|
|
|
using BankContracts.BusinessLogicsContracts;
|
|
|
|
|
using BankContracts.SearchModels;
|
|
|
|
|
using BankDataModels.Models;
|
2023-04-07 19:49:24 +04:00
|
|
|
|
|
|
|
|
|
namespace BankOperatorApp.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class HomeController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<HomeController> _logger;
|
2023-05-19 21:52:31 +04:00
|
|
|
|
private readonly IBankOperatorLogic _bankOperatorLogic;
|
|
|
|
|
private readonly ICreditProgramLogic _creditProgramLogic;
|
|
|
|
|
private readonly ICurrencyLogic _currencyLogic;
|
|
|
|
|
private ICurrencyPurchaseLogic _currencyPurchaseLogic;
|
2023-04-07 19:49:24 +04:00
|
|
|
|
|
2023-05-19 21:52:31 +04:00
|
|
|
|
public HomeController(ILogger<HomeController> logger, IBankOperatorLogic bankOperatorLogic,
|
|
|
|
|
ICreditProgramLogic creditProgramLogic, ICurrencyLogic currencyLogic,
|
|
|
|
|
ICurrencyPurchaseLogic currencyPurchaseLogic)
|
2023-04-07 19:49:24 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
2023-05-19 21:52:31 +04:00
|
|
|
|
_bankOperatorLogic = bankOperatorLogic;
|
|
|
|
|
_creditProgramLogic = creditProgramLogic;
|
|
|
|
|
_currencyLogic = currencyLogic;
|
|
|
|
|
_currencyPurchaseLogic = currencyPurchaseLogic;
|
2023-04-07 19:49:24 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult Index()
|
|
|
|
|
{
|
2023-05-19 21:52:31 +04:00
|
|
|
|
if (APIClient.BankOperator == null)
|
2023-04-07 23:40:48 +04:00
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
2023-05-19 21:52:31 +04:00
|
|
|
|
return View(_currencyLogic.ReadList(new CurrencySearchModel { BankOperatorId =
|
|
|
|
|
APIClient.BankOperator.Id }));
|
2023-04-07 19:49:24 +04:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-07 23:40:48 +04:00
|
|
|
|
[HttpGet]
|
2023-04-07 19:49:24 +04:00
|
|
|
|
public IActionResult Privacy()
|
|
|
|
|
{
|
2023-05-19 21:52:31 +04:00
|
|
|
|
if (APIClient.BankOperator == null)
|
2023-04-07 23:40:48 +04:00
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
2023-05-19 21:52:31 +04:00
|
|
|
|
return View(APIClient.BankOperator);
|
2023-04-07 23:40:48 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2023-05-19 21:52:31 +04:00
|
|
|
|
public void Privacy(string login, string password, string lastname,
|
|
|
|
|
string firstname, string middleName)
|
2023-04-07 23:40:48 +04:00
|
|
|
|
{
|
2023-05-19 21:52:31 +04:00
|
|
|
|
if (APIClient.BankOperator == null)
|
2023-04-07 23:40:48 +04:00
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
2023-05-19 21:52:31 +04:00
|
|
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)
|
|
|
|
|
|| string.IsNullOrEmpty(lastname) || string.IsNullOrEmpty(firstname) || string.IsNullOrEmpty(middleName))
|
2023-04-07 23:40:48 +04:00
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите логин, пароль и ФИО");
|
|
|
|
|
}
|
2023-05-19 21:52:31 +04:00
|
|
|
|
APIClient.PostRequest("api/bankoperator/updatebankoperator", new OperatorBindingModel
|
2023-04-07 23:40:48 +04:00
|
|
|
|
{
|
2023-05-19 21:52:31 +04:00
|
|
|
|
Id = APIClient.BankOperator.Id,
|
2023-04-07 23:40:48 +04:00
|
|
|
|
LastName = lastname,
|
|
|
|
|
FirstName = firstname,
|
|
|
|
|
MiddleName = middleName,
|
|
|
|
|
Login = login,
|
|
|
|
|
Password = password
|
|
|
|
|
});
|
|
|
|
|
|
2023-05-19 21:52:31 +04:00
|
|
|
|
APIClient.BankOperator.LastName = lastname;
|
|
|
|
|
APIClient.BankOperator.FirstName = firstname;
|
|
|
|
|
APIClient.BankOperator.MiddleName = middleName;
|
|
|
|
|
APIClient.BankOperator.Login = login;
|
|
|
|
|
APIClient.BankOperator.Password = password;
|
2023-04-07 23:40:48 +04:00
|
|
|
|
Response.Redirect("Index");
|
2023-04-07 19:49:24 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
|
|
|
public IActionResult Error()
|
|
|
|
|
{
|
2023-05-19 21:52:31 +04:00
|
|
|
|
return View(new ErrorViewModel { RequestId =
|
|
|
|
|
Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
2023-04-07 19:49:24 +04:00
|
|
|
|
}
|
2023-04-07 23:40:48 +04:00
|
|
|
|
|
|
|
|
|
[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-19 21:52:31 +04:00
|
|
|
|
APIClient.BankOperator = APIClient.
|
|
|
|
|
GetRequest<BankOperatorViewModel>
|
|
|
|
|
($"api/bankoperator/login?login={login}&password={password}");
|
|
|
|
|
if (APIClient.BankOperator == null)
|
2023-04-07 23:40:48 +04:00
|
|
|
|
{
|
|
|
|
|
throw new Exception("Неверный логин/пароль");
|
|
|
|
|
}
|
|
|
|
|
Response.Redirect("Index");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Register()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2023-05-19 21:52:31 +04:00
|
|
|
|
public void Register(string login, string password,
|
|
|
|
|
string lastname, string firstname, string middleName)
|
2023-04-07 23:40:48 +04:00
|
|
|
|
{
|
2023-05-19 21:52:31 +04:00
|
|
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)
|
|
|
|
|
|| string.IsNullOrEmpty(lastname) || string.IsNullOrEmpty(firstname)
|
|
|
|
|
|| string.IsNullOrEmpty(middleName))
|
2023-04-07 23:40:48 +04:00
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите логин, пароль и ФИО");
|
|
|
|
|
}
|
2023-05-19 21:52:31 +04:00
|
|
|
|
APIClient.PostRequest("api/bankoperator/createbankoperator", new BankOperatorBindingModel
|
2023-04-07 23:40:48 +04:00
|
|
|
|
{
|
|
|
|
|
LastName = lastname,
|
|
|
|
|
FirstName = firstname,
|
|
|
|
|
MiddleName = middleName,
|
|
|
|
|
Login = login,
|
|
|
|
|
Password = password
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("Enter");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
2023-05-19 21:52:31 +04:00
|
|
|
|
public IActionResult CreateCurrency()
|
2023-04-07 23:40:48 +04:00
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2023-05-19 21:52:31 +04:00
|
|
|
|
public void CreateCurrency(string name)
|
2023-04-07 23:40:48 +04:00
|
|
|
|
{
|
2023-05-19 21:52:31 +04:00
|
|
|
|
if (APIClient.BankOperator == null)
|
2023-04-07 23:40:48 +04:00
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
2023-05-19 21:52:31 +04:00
|
|
|
|
APIClient.PostRequest("api/currency/createcurrency", new CurrencyBindingModel
|
2023-04-07 23:40:48 +04:00
|
|
|
|
{
|
2023-05-19 21:52:31 +04:00
|
|
|
|
BankOperatorId = APIClient.BankOperator.Id,
|
|
|
|
|
Name = name,
|
2023-04-07 23:40:48 +04:00
|
|
|
|
});
|
|
|
|
|
Response.Redirect("Index");
|
|
|
|
|
}
|
2023-05-19 21:52:31 +04:00
|
|
|
|
public IActionResult CreditPrograms()
|
2023-04-07 23:40:48 +04:00
|
|
|
|
{
|
2023-05-19 21:52:31 +04:00
|
|
|
|
if (APIClient.BankOperator == null)
|
2023-04-07 23:40:48 +04:00
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
2023-05-19 21:52:31 +04:00
|
|
|
|
return View(APIClient.GetRequest
|
|
|
|
|
<List<PaymentViewModel>>
|
|
|
|
|
($"api/creditprogram/getcreditprograms?bankoperatorId={APIClient.BankOperator.Id}"));
|
2023-04-07 23:40:48 +04:00
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
2023-05-19 21:52:31 +04:00
|
|
|
|
public IActionResult CreateCreditProgram()
|
2023-04-07 23:40:48 +04:00
|
|
|
|
{
|
2023-05-19 21:52:31 +04:00
|
|
|
|
ViewBag.Currencies = APIClient.GetRequest<List<CurrencyViewModel>>
|
|
|
|
|
("api/currency/getcurrencieslist");
|
2023-04-07 23:40:48 +04:00
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
2023-05-19 21:52:31 +04:00
|
|
|
|
public void CreateCreditProgram(List<int> currenciess)
|
2023-04-07 23:40:48 +04:00
|
|
|
|
{
|
2023-05-19 21:52:31 +04:00
|
|
|
|
if (APIClient.BankOperator == null)
|
2023-04-07 23:40:48 +04:00
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
2023-05-19 21:52:31 +04:00
|
|
|
|
Dictionary<int, ICurrencyModel> CurrencyCreditPrograms = new();
|
|
|
|
|
foreach (int id in currenciess)
|
2023-04-07 23:40:48 +04:00
|
|
|
|
{
|
2023-05-19 21:52:31 +04:00
|
|
|
|
var currency = _currencyLogic.ReadElement(new CurrencySearchModel { Id = id });
|
|
|
|
|
if (currency != null) CurrencyCreditPrograms.Add(currency.Id, currency);
|
|
|
|
|
}
|
|
|
|
|
_creditProgramLogic.Create(new CreditProgramBindingModel { BankOperatorId =
|
|
|
|
|
APIClient.BankOperator.Id,
|
|
|
|
|
CreditProgramCurrencies = CurrencyCreditPrograms, });
|
|
|
|
|
Response.Redirect("Payments");
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult CreditProgram(int id)
|
|
|
|
|
{
|
|
|
|
|
return View(_creditProgramLogic.ReadElement(new CreditProgramSearchModel { Id = id }));
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult CurrencyPurchase()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.BankOperator == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
return View(_currencyPurchaseLogic.ReadList
|
|
|
|
|
(new CurrencyPurchaseSearchModel { BankOperatorId = APIClient.BankOperator.Id }));
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult CreateCurrencyPurchase()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.BankOperator == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
ViewBag.Currency = _currencyLogic.ReadList
|
|
|
|
|
(new CurrencySearchModel { BankOperatorId = APIClient.BankOperator.Id });
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateCurrencyPurchasr(string amount, int currencyId)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.BankOperator == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
2023-04-07 23:40:48 +04:00
|
|
|
|
|
2023-05-19 21:52:31 +04:00
|
|
|
|
_currencyPurchaseLogic.Create(new CurrencyPurchaseBindingModel
|
|
|
|
|
{ BankOperatorId = APIClient.BankOperator.Id,
|
|
|
|
|
Amount = (float)Convert.ToDouble(amount),
|
|
|
|
|
CurrencyId = currencyId });
|
|
|
|
|
Response.Redirect("Transfers");
|
2023-04-07 23:40:48 +04:00
|
|
|
|
}
|
2023-04-07 19:49:24 +04:00
|
|
|
|
}
|
|
|
|
|
}
|