Merge branch 'main' of http://student.git.athene.tech/Andrey_Abazov/CourseWork_Bank
This commit is contained in:
commit
f28ec3e2d1
@ -1,74 +0,0 @@
|
||||
using BankContracts.ViewModels;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace BankOperatorApp
|
||||
{
|
||||
public class APIClient
|
||||
{
|
||||
private static readonly HttpClient _client = new();
|
||||
|
||||
public static BankOperatorViewModel? BankOperator { get; set; } = null;
|
||||
|
||||
public static void Connect(IConfiguration configuration)
|
||||
{
|
||||
_client.BaseAddress = new Uri(configuration["IPAddress"]);
|
||||
_client.DefaultRequestHeaders.Accept.Clear();
|
||||
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
}
|
||||
|
||||
public static T? GetRequest<T>(string requestUrl)
|
||||
{
|
||||
var response = _client.GetAsync(requestUrl);
|
||||
var result = response.Result.Content.ReadAsStringAsync().Result;
|
||||
if (response.Result.IsSuccessStatusCode)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(result);
|
||||
}
|
||||
}
|
||||
|
||||
public static void PostRequest<T>(string requestUrl, T model)
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(model);
|
||||
var data = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
|
||||
var response = _client.PostAsync(requestUrl, data);
|
||||
|
||||
var result = response.Result.Content.ReadAsStringAsync().Result;
|
||||
if (!response.Result.IsSuccessStatusCode)
|
||||
{
|
||||
throw new Exception(result);
|
||||
}
|
||||
}
|
||||
|
||||
public static void PatchRequest<T>(string requestUrl, T model)
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(model);
|
||||
var data = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
|
||||
var response = _client.PatchAsync(requestUrl, data);
|
||||
|
||||
var result = response.Result.Content.ReadAsStringAsync().Result;
|
||||
if (!response.Result.IsSuccessStatusCode)
|
||||
{
|
||||
throw new Exception(result);
|
||||
}
|
||||
}
|
||||
|
||||
public static void DeleteRequest<T>(string requestUrl)
|
||||
{
|
||||
var response = _client.DeleteAsync(requestUrl);
|
||||
|
||||
var result = response.Result.Content.ReadAsStringAsync().Result;
|
||||
if (!response.Result.IsSuccessStatusCode)
|
||||
{
|
||||
throw new Exception(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -18,13 +18,16 @@ namespace BankOperatorApp.Controllers
|
||||
private readonly ICreditProgramLogic _creditProgramLogic;
|
||||
private readonly ICurrencyLogic _currencyLogic;
|
||||
private readonly ICurrencyPurchaseLogic _currencyPurchaseLogic;
|
||||
private readonly IDealLogic _dealLogic;
|
||||
private readonly IReportLogic _reportLogic;
|
||||
private readonly AbstractMailWorker _mailWorker;
|
||||
public static BankOperatorViewModel? BankOperator { get; set; } = null;
|
||||
|
||||
|
||||
public HomeController(ILogger<HomeController> logger, IBankOperatorLogic bankOperatorLogic,
|
||||
ICreditProgramLogic creditProgramLogic, ICurrencyLogic currencyLogic,
|
||||
ICurrencyPurchaseLogic currencyPurchaseLogic, IReportLogic reportLogic, AbstractMailWorker mailWorker)
|
||||
ICurrencyPurchaseLogic currencyPurchaseLogic, IReportLogic reportLogic,
|
||||
IDealLogic dealLogic, AbstractMailWorker mailWorker)
|
||||
{
|
||||
_logger = logger;
|
||||
_bankOperatorLogic = bankOperatorLogic;
|
||||
@ -32,34 +35,35 @@ namespace BankOperatorApp.Controllers
|
||||
_currencyLogic = currencyLogic;
|
||||
_currencyPurchaseLogic = currencyPurchaseLogic;
|
||||
_reportLogic = reportLogic;
|
||||
_dealLogic = dealLogic;
|
||||
_mailWorker = mailWorker;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
if (APIClient.BankOperator == null)
|
||||
if (HomeController.BankOperator == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(_currencyLogic.ReadList(new CurrencySearchModel { BankOperatorId =
|
||||
APIClient.BankOperator.Id }));
|
||||
HomeController.BankOperator.Id }));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Privacy()
|
||||
{
|
||||
if (APIClient.BankOperator == null)
|
||||
if (HomeController.BankOperator == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(APIClient.BankOperator);
|
||||
return View(HomeController.BankOperator);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Privacy(string login, string password, string lastname,
|
||||
string firstname, string middleName)
|
||||
{
|
||||
if (APIClient.BankOperator == null)
|
||||
if (HomeController.BankOperator == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
@ -69,7 +73,7 @@ namespace BankOperatorApp.Controllers
|
||||
}
|
||||
_bankOperatorLogic.Update(new BankOperatorBindingModel
|
||||
{
|
||||
Id = APIClient.BankOperator.Id,
|
||||
Id = HomeController.BankOperator.Id,
|
||||
LastName = lastname,
|
||||
FirstName = firstname,
|
||||
MiddleName = middleName,
|
||||
@ -77,11 +81,11 @@ namespace BankOperatorApp.Controllers
|
||||
Password = password
|
||||
});
|
||||
|
||||
APIClient.BankOperator.LastName = lastname;
|
||||
APIClient.BankOperator.FirstName = firstname;
|
||||
APIClient.BankOperator.MiddleName = middleName;
|
||||
APIClient.BankOperator.Login = login;
|
||||
APIClient.BankOperator.Password = password;
|
||||
HomeController.BankOperator.LastName = lastname;
|
||||
HomeController.BankOperator.FirstName = firstname;
|
||||
HomeController.BankOperator.MiddleName = middleName;
|
||||
HomeController.BankOperator.Login = login;
|
||||
HomeController.BankOperator.Password = password;
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
@ -105,11 +109,12 @@ namespace BankOperatorApp.Controllers
|
||||
{
|
||||
throw new Exception("Введите логин и пароль");
|
||||
}
|
||||
APIClient.BankOperator = _bankOperatorLogic.ReadElement
|
||||
HomeController.BankOperator = _bankOperatorLogic.ReadElement
|
||||
(new BankOperatorSearchModel { Login = login, Password = password });
|
||||
if (APIClient.BankOperator == null)
|
||||
if (HomeController.BankOperator == null)
|
||||
{
|
||||
throw new Exception("Неверный логин/пароль");
|
||||
Response.WriteAsync($"<script language=\"javascript\">alert('Wrong login or password!');window.location.replace('/Home/Enter');</script>");
|
||||
return;
|
||||
}
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
@ -150,25 +155,27 @@ namespace BankOperatorApp.Controllers
|
||||
[HttpPost]
|
||||
public void CreateCurrency(string name)
|
||||
{
|
||||
if (APIClient.BankOperator == null)
|
||||
if (HomeController.BankOperator == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
Response.WriteAsync($"<script language=\"javascript\">" +
|
||||
$"alert('You need to login!');window.location.replace('/Home/Enter');</script>");
|
||||
Redirect("/Home/Enter");
|
||||
}
|
||||
_currencyLogic.Create(new CurrencyBindingModel
|
||||
{
|
||||
Name = name,
|
||||
BankOperatorId = APIClient.BankOperator.Id,
|
||||
BankOperatorId = HomeController.BankOperator.Id,
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
public IActionResult CreditPrograms()
|
||||
{
|
||||
if (APIClient.BankOperator == null)
|
||||
if (HomeController.BankOperator == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(_creditProgramLogic.ReadList(new CreditProgramSearchModel
|
||||
{ BankOperatorId = APIClient.BankOperator.Id}));
|
||||
{ BankOperatorId = HomeController.BankOperator.Id}));
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult CreateCreditProgram()
|
||||
@ -179,9 +186,11 @@ namespace BankOperatorApp.Controllers
|
||||
[HttpPost]
|
||||
public void CreateCreditProgram(List<int> currencies, string name, float percent)
|
||||
{
|
||||
if (APIClient.BankOperator == null)
|
||||
if (HomeController.BankOperator == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
Response.WriteAsync($"<script language=\"javascript\">" +
|
||||
$"alert('You need to login!');window.location.replace('/Home/Enter');</script>");
|
||||
Redirect("/Home/Enter");
|
||||
}
|
||||
Dictionary<int, ICurrencyModel> CurrencyCreditPrograms = new();
|
||||
foreach (int id in currencies)
|
||||
@ -190,7 +199,7 @@ namespace BankOperatorApp.Controllers
|
||||
if (currency != null) CurrencyCreditPrograms.Add(currency.Id, currency);
|
||||
}
|
||||
_creditProgramLogic.Create(new CreditProgramBindingModel { BankOperatorId =
|
||||
APIClient.BankOperator.Id,
|
||||
HomeController.BankOperator.Id,
|
||||
CreditProgramCurrencies = CurrencyCreditPrograms, Name = name, Percent = percent});
|
||||
Response.Redirect("CreditPrograms");
|
||||
}
|
||||
@ -202,19 +211,23 @@ namespace BankOperatorApp.Controllers
|
||||
[HttpGet]
|
||||
public IActionResult CurrencyPurchase()
|
||||
{
|
||||
if (APIClient.BankOperator == null)
|
||||
if (HomeController.BankOperator == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
Response.WriteAsync($"<script language=\"javascript\">" +
|
||||
$"alert('You need to login!');window.location.replace('/Home/Enter');</script>");
|
||||
return Redirect("/Home/Enter");
|
||||
}
|
||||
return View(_currencyPurchaseLogic.ReadList
|
||||
(new CurrencyPurchaseSearchModel { BankOperatorId = APIClient.BankOperator.Id }));
|
||||
(new CurrencyPurchaseSearchModel { BankOperatorId = HomeController.BankOperator.Id }));
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult CreateCurrencyPurchase()
|
||||
{
|
||||
if (APIClient.BankOperator == null)
|
||||
if (HomeController.BankOperator == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
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();
|
||||
@ -222,13 +235,15 @@ namespace BankOperatorApp.Controllers
|
||||
[HttpPost]
|
||||
public void CreateCurrencyPurchase(string amount, int currencyId)
|
||||
{
|
||||
if (APIClient.BankOperator == null)
|
||||
if (HomeController.BankOperator == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
Response.WriteAsync($"<script language=\"javascript\">" +
|
||||
$"alert('You need to login!');window.location.replace('/Home/Enter');</script>");
|
||||
Redirect("/Home/Enter");
|
||||
}
|
||||
|
||||
_currencyPurchaseLogic.Create(new CurrencyPurchaseBindingModel
|
||||
{ BankOperatorId = APIClient.BankOperator.Id,
|
||||
{ BankOperatorId = HomeController.BankOperator.Id,
|
||||
Amount = (float)Convert.ToDouble(amount),
|
||||
CurrencyId = currencyId,
|
||||
|
||||
@ -238,18 +253,18 @@ namespace BankOperatorApp.Controllers
|
||||
|
||||
public IActionResult CurrencyPurchases()
|
||||
{
|
||||
if (APIClient.BankOperator == null)
|
||||
if (HomeController.BankOperator == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(_currencyPurchaseLogic.ReadList(new CurrencyPurchaseSearchModel
|
||||
{ BankOperatorId = APIClient.BankOperator.Id }));
|
||||
{ BankOperatorId = HomeController.BankOperator.Id }));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult CurrencyReport()
|
||||
{
|
||||
if (APIClient.BankOperator == null)
|
||||
if (HomeController.BankOperator == null)
|
||||
{
|
||||
Response.WriteAsync($"<script language=\"javascript\">alert" +
|
||||
$"('You need to login!');window.location.replace('/Home/Enter');" +
|
||||
@ -295,7 +310,7 @@ namespace BankOperatorApp.Controllers
|
||||
[HttpGet]
|
||||
public IActionResult CurrencyPurchasePaymentsReport()
|
||||
{
|
||||
if (APIClient.BankOperator == null)
|
||||
if (HomeController.BankOperator == null)
|
||||
{
|
||||
Response.WriteAsync($"<script language=\"javascript\">alert" +
|
||||
$"('You need to login!');window.location.replace('/Home/Enter');</script>");
|
||||
@ -307,7 +322,7 @@ namespace BankOperatorApp.Controllers
|
||||
public IActionResult CurrencyPurchasePaymentsReport(DateTime dateFrom,
|
||||
DateTime dateTo, string reptype, string email, string fileName)
|
||||
{
|
||||
if (APIClient.BankOperator == null)
|
||||
if (HomeController.BankOperator == null)
|
||||
{
|
||||
Response.WriteAsync($"<script language=\"javascript\">" +
|
||||
$"alert('You need to login!');window.location.replace('/Home/Enter');</script>");
|
||||
@ -329,7 +344,7 @@ namespace BankOperatorApp.Controllers
|
||||
_mailWorker.MailSendAsync(new MailSendInfoBindingModel
|
||||
{
|
||||
Subject = "Отчёт по закупкам",
|
||||
Text = "Для оператора " + APIClient.BankOperator.LastName + APIClient.BankOperator.FirstName,
|
||||
Text = "Для оператора " + HomeController.BankOperator.LastName + HomeController.BankOperator.FirstName,
|
||||
MailAddress = email,
|
||||
FileName = fileName,
|
||||
Attachment = report
|
||||
@ -344,5 +359,35 @@ namespace BankOperatorApp.Controllers
|
||||
return Redirect("/");
|
||||
}
|
||||
}
|
||||
|
||||
public IActionResult AddDealsToCreditProgram()
|
||||
{
|
||||
if (HomeController.BankOperator == null)
|
||||
{
|
||||
Response.WriteAsync($"<script language=\"javascript\">" +
|
||||
$"alert('You need to login!');window.location.replace('/Home/Enter');</script>");
|
||||
return Redirect("/Home/Enter");
|
||||
}
|
||||
ViewBag.CreditPrograms = _creditProgramLogic.ReadList(new CreditProgramSearchModel { BankOperatorId = HomeController.BankOperator.Id});
|
||||
ViewBag.Deals = _dealLogic.ReadList(null);
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void AddDealsToCreditProgram(int creditProgram, List<int> deals)
|
||||
{
|
||||
if (HomeController.BankOperator == null)
|
||||
{
|
||||
Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
|
||||
Redirect("/Home/Enter");
|
||||
}
|
||||
foreach (var dealId in deals)
|
||||
{
|
||||
var deal = _dealLogic.ReadElement(new DealSearchModel { Id = dealId });
|
||||
if (deal != null) _dealLogic.Update(new DealBindingModel { Id = deal.Id, ClientId = deal.ClientId, CreditProgramId = creditProgram });
|
||||
}
|
||||
Response.WriteAsync($"<script language=\"javascript\">alert('Success!');window.location.replace('/');</script>");
|
||||
Redirect("/");
|
||||
}
|
||||
}
|
||||
}
|
@ -33,6 +33,7 @@ builder.Services.AddTransient<ICurrencyLogic, CurrencyLogic>();
|
||||
builder.Services.AddTransient<ICreditProgramLogic, CreditProgramLogic>();
|
||||
builder.Services.AddTransient<IBankOperatorLogic, BankOperatorLogic>();
|
||||
builder.Services.AddTransient<IReportLogic, ReportLogic>();
|
||||
builder.Services.AddTransient<IDealLogic, DealLogic>();
|
||||
|
||||
builder.Services.AddControllersWithViews();
|
||||
|
||||
|
@ -0,0 +1,24 @@
|
||||
@{
|
||||
ViewData["Title"] = "CreatePayment";
|
||||
}
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Привязка сделок</h2>
|
||||
</div>
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Выплата:</div>
|
||||
<div class="col-8">
|
||||
<select id="creditProgram" name="creditProgram" class="form-control" required asp-items="@(new SelectList(@ViewBag.CreditPrograms,"Id", "Name"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Сделки:</div>
|
||||
<div class="col-8">
|
||||
<select id="deals" name="deals" class="form-control" required multiple asp-items="@(new SelectList(@ViewBag.Deals,"Id", "DealDate"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div>
|
||||
</div>
|
||||
</form>
|
81
Bank/BankOperatorApp/Views/Home/ViewReport.cshtml
Normal file
81
Bank/BankOperatorApp/Views/Home/ViewReport.cshtml
Normal file
@ -0,0 +1,81 @@
|
||||
@using BankContracts.ViewModels
|
||||
|
||||
@model List<ReportCurrencyPurchasePaymentViewModel>
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "View Report";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">Отчёт о закупках</h1>
|
||||
<h1 class="display4">C @ViewBag.DateFrom по @ViewBag.DateTo</h1>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="text-center">
|
||||
@{
|
||||
if (Model == null)
|
||||
{
|
||||
<h3 class="display-4">Авторизируйтесь</h3>
|
||||
return;
|
||||
}
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Номер закупки
|
||||
</th>
|
||||
<th>
|
||||
Дата закупки
|
||||
</th>
|
||||
<th>
|
||||
Валюта
|
||||
</th>
|
||||
<th>
|
||||
Номер выплаты
|
||||
</th>
|
||||
<th>
|
||||
Дата выплаты
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
Закупка №@item.CurrencyPurchaseId
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.PurchaseDate)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.CurrencyName)
|
||||
</td>
|
||||
<td>
|
||||
</td>
|
||||
<td>
|
||||
</td>
|
||||
</tr>
|
||||
@foreach (var payment in item.Payments)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
</td>
|
||||
<td>
|
||||
</td>
|
||||
<td>
|
||||
</td>
|
||||
<td>
|
||||
Выплата №@payment.PaymentId
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => payment.PaymentDate)
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
</div>
|
@ -33,6 +33,9 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="CurrencyPurchasePaymentsReport">Отчет по закупкам</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="AddDealsToCreditProgram">Привязка "сделка-программа"</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
|
||||
</li>
|
||||
|
Loading…
Reference in New Issue
Block a user