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-05-20 01:24:08 +04:00
|
|
|
|
using BankBusinessLogic.BusinessLogics;
|
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;
|
2023-05-20 04:36:30 +04:00
|
|
|
|
private readonly ICurrencyPurchaseLogic _currencyPurchaseLogic;
|
|
|
|
|
private readonly IReportLogic _reportLogic;
|
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,
|
2023-05-20 04:36:30 +04:00
|
|
|
|
ICurrencyPurchaseLogic currencyPurchaseLogic, IReportLogic reportLogic)
|
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-05-20 04:36:30 +04:00
|
|
|
|
_reportLogic = reportLogic;
|
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-20 02:17:15 +04:00
|
|
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(lastname) || string.IsNullOrEmpty(firstname))
|
2023-04-07 23:40:48 +04:00
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите логин, пароль и ФИО");
|
|
|
|
|
}
|
2023-05-20 01:24:08 +04:00
|
|
|
|
_bankOperatorLogic.Update(new BankOperatorBindingModel
|
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-20 01:24:08 +04:00
|
|
|
|
APIClient.BankOperator = _bankOperatorLogic.ReadElement
|
|
|
|
|
(new BankOperatorSearchModel { Login = login, Password = password });
|
2023-05-19 21:52:31 +04:00
|
|
|
|
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-20 01:24:08 +04:00
|
|
|
|
_bankOperatorLogic.Create(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-20 01:24:08 +04:00
|
|
|
|
_currencyLogic.Create(new CurrencyBindingModel
|
2023-04-07 23:40:48 +04:00
|
|
|
|
{
|
2023-05-19 21:52:31 +04:00
|
|
|
|
Name = name,
|
2023-05-20 01:24:08 +04:00
|
|
|
|
BankOperatorId = APIClient.BankOperator.Id,
|
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-20 01:24:08 +04:00
|
|
|
|
return View(_creditProgramLogic.ReadList(new CreditProgramSearchModel
|
|
|
|
|
{ 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-20 01:24:08 +04:00
|
|
|
|
ViewBag.Currencies = _currencyLogic.ReadList(null);
|
2023-04-07 23:40:48 +04:00
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
2023-05-20 01:24:08 +04:00
|
|
|
|
public void CreateCreditProgram(List<int> currencies, string name, float percent)
|
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();
|
2023-05-20 01:24:08 +04:00
|
|
|
|
foreach (int id in currencies)
|
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,
|
2023-05-20 01:24:08 +04:00
|
|
|
|
CreditProgramCurrencies = CurrencyCreditPrograms, Name = name, Percent = percent});
|
|
|
|
|
Response.Redirect("CreditPrograms");
|
2023-05-19 21:52:31 +04:00
|
|
|
|
}
|
|
|
|
|
[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("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
2023-05-20 02:10:55 +04:00
|
|
|
|
ViewBag.Currencies = _currencyLogic.ReadList(null);
|
2023-05-19 21:52:31 +04:00
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
2023-05-19 22:55:03 +04:00
|
|
|
|
public void CreateCurrencyPurchase(string amount, int currencyId)
|
2023-05-19 21:52:31 +04:00
|
|
|
|
{
|
|
|
|
|
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
|
2023-05-19 22:55:03 +04:00
|
|
|
|
{ BankOperatorId = APIClient.BankOperator.Id,
|
2023-05-19 21:52:31 +04:00
|
|
|
|
Amount = (float)Convert.ToDouble(amount),
|
2023-05-19 22:55:03 +04:00
|
|
|
|
CurrencyId = currencyId,
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("CurrencyPurchases");
|
2023-04-07 23:40:48 +04:00
|
|
|
|
}
|
2023-05-20 02:10:55 +04:00
|
|
|
|
|
|
|
|
|
public IActionResult CurrencyPurchases()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.BankOperator == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
return View(_currencyPurchaseLogic.ReadList(new CurrencyPurchaseSearchModel
|
|
|
|
|
{ BankOperatorId = APIClient.BankOperator.Id }));
|
|
|
|
|
}
|
2023-05-20 04:36:30 +04:00
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult CurrencyReport()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.BankOperator == null)
|
|
|
|
|
{
|
|
|
|
|
Response.WriteAsync($"<script language=\"javascript\">alert" +
|
|
|
|
|
$"('You need to login!');window.location.replace('/Home/Enter');" +
|
|
|
|
|
$"</script>");
|
|
|
|
|
return Redirect("/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
ViewBag.Currencies = _currencyLogic.ReadList(null);
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public IActionResult CurrencyReport(List<int> currencies, string doctype)
|
|
|
|
|
{
|
|
|
|
|
List<CurrencyBindingModel> currencyBindings = new List<CurrencyBindingModel>();
|
|
|
|
|
foreach (int currencyId in currencies)
|
|
|
|
|
{
|
|
|
|
|
var currencyView = _currencyLogic.ReadElement
|
|
|
|
|
(new CurrencySearchModel { Id = currencyId });
|
|
|
|
|
if (currencyView != null) currencyBindings.Add(new CurrencyBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = currencyView.Id,
|
|
|
|
|
BankOperatorId = currencyView.BankOperatorId,
|
|
|
|
|
Name = currencyView.Name,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (doctype.Equals("word"))
|
|
|
|
|
{
|
|
|
|
|
MemoryStream list = _reportLogic.SaveCurrencyTransfersToWord
|
|
|
|
|
(new ReportBindingModel { FileName = "test" }, currencyBindings);
|
|
|
|
|
return File(list, "application/vnd.openxmlformats-officedocument." +
|
|
|
|
|
"wordprocessingml.document", "testDoc.docx");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MemoryStream list = _reportLogic.SaveCurrencyTransfersToExcel
|
|
|
|
|
(new ReportBindingModel { FileName = "test" }, currencyBindings);
|
|
|
|
|
return File(list, "application/vnd.openxmlformats-officedocument." +
|
|
|
|
|
"spreadsheetml.sheet", "testExcel.xlsx");
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-07 19:49:24 +04:00
|
|
|
|
}
|
|
|
|
|
}
|