This commit is contained in:
abazov73 2023-05-20 06:26:25 +04:00
commit f28ec3e2d1
6 changed files with 191 additions and 111 deletions

View File

@ -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);
}
}
}
}

View File

@ -18,13 +18,16 @@ namespace BankOperatorApp.Controllers
private readonly ICreditProgramLogic _creditProgramLogic; private readonly ICreditProgramLogic _creditProgramLogic;
private readonly ICurrencyLogic _currencyLogic; private readonly ICurrencyLogic _currencyLogic;
private readonly ICurrencyPurchaseLogic _currencyPurchaseLogic; private readonly ICurrencyPurchaseLogic _currencyPurchaseLogic;
private readonly IDealLogic _dealLogic;
private readonly IReportLogic _reportLogic; private readonly IReportLogic _reportLogic;
private readonly AbstractMailWorker _mailWorker; private readonly AbstractMailWorker _mailWorker;
public static BankOperatorViewModel? BankOperator { get; set; } = null;
public HomeController(ILogger<HomeController> logger, IBankOperatorLogic bankOperatorLogic, public HomeController(ILogger<HomeController> logger, IBankOperatorLogic bankOperatorLogic,
ICreditProgramLogic creditProgramLogic, ICurrencyLogic currencyLogic, ICreditProgramLogic creditProgramLogic, ICurrencyLogic currencyLogic,
ICurrencyPurchaseLogic currencyPurchaseLogic, IReportLogic reportLogic, AbstractMailWorker mailWorker) ICurrencyPurchaseLogic currencyPurchaseLogic, IReportLogic reportLogic,
IDealLogic dealLogic, AbstractMailWorker mailWorker)
{ {
_logger = logger; _logger = logger;
_bankOperatorLogic = bankOperatorLogic; _bankOperatorLogic = bankOperatorLogic;
@ -32,34 +35,35 @@ namespace BankOperatorApp.Controllers
_currencyLogic = currencyLogic; _currencyLogic = currencyLogic;
_currencyPurchaseLogic = currencyPurchaseLogic; _currencyPurchaseLogic = currencyPurchaseLogic;
_reportLogic = reportLogic; _reportLogic = reportLogic;
_dealLogic = dealLogic;
_mailWorker = mailWorker; _mailWorker = mailWorker;
} }
public IActionResult Index() public IActionResult Index()
{ {
if (APIClient.BankOperator == null) if (HomeController.BankOperator == null)
{ {
return Redirect("~/Home/Enter"); return Redirect("~/Home/Enter");
} }
return View(_currencyLogic.ReadList(new CurrencySearchModel { BankOperatorId = return View(_currencyLogic.ReadList(new CurrencySearchModel { BankOperatorId =
APIClient.BankOperator.Id })); HomeController.BankOperator.Id }));
} }
[HttpGet] [HttpGet]
public IActionResult Privacy() public IActionResult Privacy()
{ {
if (APIClient.BankOperator == null) if (HomeController.BankOperator == null)
{ {
return Redirect("~/Home/Enter"); return Redirect("~/Home/Enter");
} }
return View(APIClient.BankOperator); return View(HomeController.BankOperator);
} }
[HttpPost] [HttpPost]
public void Privacy(string login, string password, string lastname, public void Privacy(string login, string password, string lastname,
string firstname, string middleName) string firstname, string middleName)
{ {
if (APIClient.BankOperator == null) if (HomeController.BankOperator == null)
{ {
throw new Exception("Вы как суда попали? Суда вход только авторизованным"); throw new Exception("Вы как суда попали? Суда вход только авторизованным");
} }
@ -69,7 +73,7 @@ namespace BankOperatorApp.Controllers
} }
_bankOperatorLogic.Update(new BankOperatorBindingModel _bankOperatorLogic.Update(new BankOperatorBindingModel
{ {
Id = APIClient.BankOperator.Id, Id = HomeController.BankOperator.Id,
LastName = lastname, LastName = lastname,
FirstName = firstname, FirstName = firstname,
MiddleName = middleName, MiddleName = middleName,
@ -77,11 +81,11 @@ namespace BankOperatorApp.Controllers
Password = password Password = password
}); });
APIClient.BankOperator.LastName = lastname; HomeController.BankOperator.LastName = lastname;
APIClient.BankOperator.FirstName = firstname; HomeController.BankOperator.FirstName = firstname;
APIClient.BankOperator.MiddleName = middleName; HomeController.BankOperator.MiddleName = middleName;
APIClient.BankOperator.Login = login; HomeController.BankOperator.Login = login;
APIClient.BankOperator.Password = password; HomeController.BankOperator.Password = password;
Response.Redirect("Index"); Response.Redirect("Index");
} }
@ -105,11 +109,12 @@ namespace BankOperatorApp.Controllers
{ {
throw new Exception("Введите логин и пароль"); throw new Exception("Введите логин и пароль");
} }
APIClient.BankOperator = _bankOperatorLogic.ReadElement HomeController.BankOperator = _bankOperatorLogic.ReadElement
(new BankOperatorSearchModel { Login = login, Password = password }); (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"); Response.Redirect("Index");
} }
@ -150,25 +155,27 @@ namespace BankOperatorApp.Controllers
[HttpPost] [HttpPost]
public void CreateCurrency(string name) 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 _currencyLogic.Create(new CurrencyBindingModel
{ {
Name = name, Name = name,
BankOperatorId = APIClient.BankOperator.Id, BankOperatorId = HomeController.BankOperator.Id,
}); });
Response.Redirect("Index"); Response.Redirect("Index");
} }
public IActionResult CreditPrograms() public IActionResult CreditPrograms()
{ {
if (APIClient.BankOperator == null) if (HomeController.BankOperator == null)
{ {
return Redirect("~/Home/Enter"); return Redirect("~/Home/Enter");
} }
return View(_creditProgramLogic.ReadList(new CreditProgramSearchModel return View(_creditProgramLogic.ReadList(new CreditProgramSearchModel
{ BankOperatorId = APIClient.BankOperator.Id})); { BankOperatorId = HomeController.BankOperator.Id}));
} }
[HttpGet] [HttpGet]
public IActionResult CreateCreditProgram() public IActionResult CreateCreditProgram()
@ -179,9 +186,11 @@ namespace BankOperatorApp.Controllers
[HttpPost] [HttpPost]
public void CreateCreditProgram(List<int> currencies, string name, float percent) 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(); Dictionary<int, ICurrencyModel> CurrencyCreditPrograms = new();
foreach (int id in currencies) foreach (int id in currencies)
@ -190,7 +199,7 @@ namespace BankOperatorApp.Controllers
if (currency != null) CurrencyCreditPrograms.Add(currency.Id, currency); if (currency != null) CurrencyCreditPrograms.Add(currency.Id, currency);
} }
_creditProgramLogic.Create(new CreditProgramBindingModel { BankOperatorId = _creditProgramLogic.Create(new CreditProgramBindingModel { BankOperatorId =
APIClient.BankOperator.Id, HomeController.BankOperator.Id,
CreditProgramCurrencies = CurrencyCreditPrograms, Name = name, Percent = percent}); CreditProgramCurrencies = CurrencyCreditPrograms, Name = name, Percent = percent});
Response.Redirect("CreditPrograms"); Response.Redirect("CreditPrograms");
} }
@ -202,19 +211,23 @@ namespace BankOperatorApp.Controllers
[HttpGet] [HttpGet]
public IActionResult CurrencyPurchase() 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 return View(_currencyPurchaseLogic.ReadList
(new CurrencyPurchaseSearchModel { BankOperatorId = APIClient.BankOperator.Id })); (new CurrencyPurchaseSearchModel { BankOperatorId = HomeController.BankOperator.Id }));
} }
[HttpGet] [HttpGet]
public IActionResult CreateCurrencyPurchase() 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); ViewBag.Currencies = _currencyLogic.ReadList(null);
return View(); return View();
@ -222,13 +235,15 @@ namespace BankOperatorApp.Controllers
[HttpPost] [HttpPost]
public void CreateCurrencyPurchase(string amount, int currencyId) 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 _currencyPurchaseLogic.Create(new CurrencyPurchaseBindingModel
{ BankOperatorId = APIClient.BankOperator.Id, { BankOperatorId = HomeController.BankOperator.Id,
Amount = (float)Convert.ToDouble(amount), Amount = (float)Convert.ToDouble(amount),
CurrencyId = currencyId, CurrencyId = currencyId,
@ -238,18 +253,18 @@ namespace BankOperatorApp.Controllers
public IActionResult CurrencyPurchases() public IActionResult CurrencyPurchases()
{ {
if (APIClient.BankOperator == null) if (HomeController.BankOperator == null)
{ {
return Redirect("~/Home/Enter"); return Redirect("~/Home/Enter");
} }
return View(_currencyPurchaseLogic.ReadList(new CurrencyPurchaseSearchModel return View(_currencyPurchaseLogic.ReadList(new CurrencyPurchaseSearchModel
{ BankOperatorId = APIClient.BankOperator.Id })); { BankOperatorId = HomeController.BankOperator.Id }));
} }
[HttpGet] [HttpGet]
public IActionResult CurrencyReport() public IActionResult CurrencyReport()
{ {
if (APIClient.BankOperator == null) if (HomeController.BankOperator == null)
{ {
Response.WriteAsync($"<script language=\"javascript\">alert" + Response.WriteAsync($"<script language=\"javascript\">alert" +
$"('You need to login!');window.location.replace('/Home/Enter');" + $"('You need to login!');window.location.replace('/Home/Enter');" +
@ -295,7 +310,7 @@ namespace BankOperatorApp.Controllers
[HttpGet] [HttpGet]
public IActionResult CurrencyPurchasePaymentsReport() public IActionResult CurrencyPurchasePaymentsReport()
{ {
if (APIClient.BankOperator == null) if (HomeController.BankOperator == null)
{ {
Response.WriteAsync($"<script language=\"javascript\">alert" + Response.WriteAsync($"<script language=\"javascript\">alert" +
$"('You need to login!');window.location.replace('/Home/Enter');</script>"); $"('You need to login!');window.location.replace('/Home/Enter');</script>");
@ -307,7 +322,7 @@ namespace BankOperatorApp.Controllers
public IActionResult CurrencyPurchasePaymentsReport(DateTime dateFrom, public IActionResult CurrencyPurchasePaymentsReport(DateTime dateFrom,
DateTime dateTo, string reptype, string email, string fileName) DateTime dateTo, string reptype, string email, string fileName)
{ {
if (APIClient.BankOperator == null) if (HomeController.BankOperator == null)
{ {
Response.WriteAsync($"<script language=\"javascript\">" + Response.WriteAsync($"<script language=\"javascript\">" +
$"alert('You need to login!');window.location.replace('/Home/Enter');</script>"); $"alert('You need to login!');window.location.replace('/Home/Enter');</script>");
@ -329,7 +344,7 @@ namespace BankOperatorApp.Controllers
_mailWorker.MailSendAsync(new MailSendInfoBindingModel _mailWorker.MailSendAsync(new MailSendInfoBindingModel
{ {
Subject = "Отчёт по закупкам", Subject = "Отчёт по закупкам",
Text = "Для оператора " + APIClient.BankOperator.LastName + APIClient.BankOperator.FirstName, Text = "Для оператора " + HomeController.BankOperator.LastName + HomeController.BankOperator.FirstName,
MailAddress = email, MailAddress = email,
FileName = fileName, FileName = fileName,
Attachment = report Attachment = report
@ -344,5 +359,35 @@ namespace BankOperatorApp.Controllers
return Redirect("/"); 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("/");
}
} }
} }

View File

@ -33,6 +33,7 @@ builder.Services.AddTransient<ICurrencyLogic, CurrencyLogic>();
builder.Services.AddTransient<ICreditProgramLogic, CreditProgramLogic>(); builder.Services.AddTransient<ICreditProgramLogic, CreditProgramLogic>();
builder.Services.AddTransient<IBankOperatorLogic, BankOperatorLogic>(); builder.Services.AddTransient<IBankOperatorLogic, BankOperatorLogic>();
builder.Services.AddTransient<IReportLogic, ReportLogic>(); builder.Services.AddTransient<IReportLogic, ReportLogic>();
builder.Services.AddTransient<IDealLogic, DealLogic>();
builder.Services.AddControllersWithViews(); builder.Services.AddControllersWithViews();

View File

@ -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>

View 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>

View File

@ -33,6 +33,9 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="CurrencyPurchasePaymentsReport">Отчет по закупкам</a> <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="CurrencyPurchasePaymentsReport">Отчет по закупкам</a>
</li> </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"> <li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a> <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
</li> </li>