Compare commits

..

No commits in common. "f28ec3e2d1f8ba043fd95c63bb396ff8cb6e0a2a" and "56f7e44dd496efe1e1b1ef67b9d9a15826d8cfcd" have entirely different histories.

3 changed files with 113 additions and 39 deletions

View File

@ -0,0 +1,74 @@
using System.Net.Http.Headers;
using System.Text;
using BankContracts.ViewModels;
using Newtonsoft.Json;
namespace OperatorApp
{
public class APIClient
{
private static readonly HttpClient _client = new();
public static OperatorViewModel? Operator { 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

@ -24,8 +24,6 @@ namespace OperatorApp.Controllers
private readonly ICurrencyLogic _currencyLogic; private readonly ICurrencyLogic _currencyLogic;
private readonly AbstractMailWorker _mailWorker; private readonly AbstractMailWorker _mailWorker;
public static OperatorViewModel? Operator;
public HomeController(ILogger<HomeController> logger, IDealLogic dealLogic, IPaymentLogic paymentLogic, ITransferLogic transferLogic, IOperatorLogic operatorLogic, IReportLogic reportLogic, ICurrencyLogic currencyLogic, AbstractMailWorker mailWorker) public HomeController(ILogger<HomeController> logger, IDealLogic dealLogic, IPaymentLogic paymentLogic, ITransferLogic transferLogic, IOperatorLogic operatorLogic, IReportLogic reportLogic, ICurrencyLogic currencyLogic, AbstractMailWorker mailWorker)
{ {
_logger = logger; _logger = logger;
@ -40,28 +38,28 @@ namespace OperatorApp.Controllers
public IActionResult Index() public IActionResult Index()
{ {
if (HomeController.Operator == null) if (APIClient.Operator == null)
{ {
return Redirect("~/Home/Enter"); return Redirect("~/Home/Enter");
} }
return View(_dealLogic.ReadList(new DealSearchModel { OperatorId = HomeController.Operator.Id })); return View(_dealLogic.ReadList(new DealSearchModel { OperatorId = APIClient.Operator.Id }));
} }
[HttpGet] [HttpGet]
public IActionResult Privacy() public IActionResult Privacy()
{ {
if (HomeController.Operator == null) if (APIClient.Operator == null)
{ {
Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>"); Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
return Redirect("/Home/Enter"); return Redirect("/Home/Enter");
} }
return View(HomeController.Operator); return View(APIClient.Operator);
} }
[HttpPost] [HttpPost]
public void Privacy(string login, string password, string lastname, string firstname, string middleName) public void Privacy(string login, string password, string lastname, string firstname, string middleName)
{ {
if (HomeController.Operator == null) if (APIClient.Operator == null)
{ {
Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>"); Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
return; return;
@ -72,7 +70,7 @@ namespace OperatorApp.Controllers
} }
_operatorLogic.Update(new OperatorBindingModel _operatorLogic.Update(new OperatorBindingModel
{ {
Id = HomeController.Operator.Id, Id = APIClient.Operator.Id,
LastName = lastname, LastName = lastname,
FirstName = firstname, FirstName = firstname,
MiddleName = middleName, MiddleName = middleName,
@ -80,11 +78,11 @@ namespace OperatorApp.Controllers
Password = password Password = password
}); });
HomeController.Operator.LastName = lastname; APIClient.Operator.LastName = lastname;
HomeController.Operator.FirstName = firstname; APIClient.Operator.FirstName = firstname;
HomeController.Operator.MiddleName = middleName; APIClient.Operator.MiddleName = middleName;
HomeController.Operator.Login = login; APIClient.Operator.Login = login;
HomeController.Operator.Password = password; APIClient.Operator.Password = password;
Response.Redirect("Index"); Response.Redirect("Index");
} }
@ -108,8 +106,8 @@ namespace OperatorApp.Controllers
Response.WriteAsync($"<script language=\"javascript\">alert('Input login and password!');window.location.replace('/Home/Enter');</script>"); Response.WriteAsync($"<script language=\"javascript\">alert('Input login and password!');window.location.replace('/Home/Enter');</script>");
return; return;
} }
HomeController.Operator = _operatorLogic.ReadElement(new OperatorSearchModel { Login = login, Password = password }); APIClient.Operator = _operatorLogic.ReadElement(new OperatorSearchModel { Login = login, Password = password });
if (HomeController.Operator == null) if (APIClient.Operator == null)
{ {
Response.WriteAsync($"<script language=\"javascript\">alert('Wrong login or password!');window.location.replace('/Home/Enter');</script>"); Response.WriteAsync($"<script language=\"javascript\">alert('Wrong login or password!');window.location.replace('/Home/Enter');</script>");
return; return;
@ -144,7 +142,7 @@ namespace OperatorApp.Controllers
[HttpGet] [HttpGet]
public IActionResult CreateDeal() public IActionResult CreateDeal()
{ {
if (HomeController.Operator == null) if (APIClient.Operator == null)
{ {
Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>"); Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
return Redirect("/Home/Enter"); return Redirect("/Home/Enter");
@ -155,7 +153,7 @@ namespace OperatorApp.Controllers
[HttpPost] [HttpPost]
public void CreateDeal(int clientid) public void CreateDeal(int clientid)
{ {
if (HomeController.Operator == null) if (APIClient.Operator == null)
{ {
Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>"); Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
return; return;
@ -163,34 +161,34 @@ namespace OperatorApp.Controllers
_dealLogic.Create(new DealBindingModel _dealLogic.Create(new DealBindingModel
{ {
ClientId = clientid, ClientId = clientid,
OperatorId = HomeController.Operator.Id, OperatorId = APIClient.Operator.Id,
}); });
Response.Redirect("Index"); Response.Redirect("Index");
} }
public IActionResult Payments() public IActionResult Payments()
{ {
if (HomeController.Operator == null) if (APIClient.Operator == null)
{ {
Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>"); Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
return Redirect("/Home/Enter"); return Redirect("/Home/Enter");
} }
return View(_paymentLogic.ReadList(new PaymentSearchModel { OperatorId = HomeController.Operator.Id })); return View(_paymentLogic.ReadList(new PaymentSearchModel { OperatorId = APIClient.Operator.Id }));
} }
[HttpGet] [HttpGet]
public IActionResult CreatePayment() public IActionResult CreatePayment()
{ {
if (HomeController.Operator == null) if (APIClient.Operator == null)
{ {
Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>"); Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
return Redirect("/Home/Enter"); return Redirect("/Home/Enter");
} }
ViewBag.Deals = _dealLogic.ReadList(new DealSearchModel { OperatorId = HomeController.Operator.Id }); ViewBag.Deals = _dealLogic.ReadList(new DealSearchModel { OperatorId = APIClient.Operator.Id });
return View(); return View();
} }
[HttpPost] [HttpPost]
public void CreatePayment(List<int> deals) public void CreatePayment(List<int> deals)
{ {
if (HomeController.Operator == null) if (APIClient.Operator == null)
{ {
Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>"); Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
return; return;
@ -201,13 +199,13 @@ namespace OperatorApp.Controllers
var deal = _dealLogic.ReadElement(new DealSearchModel { Id = id }); var deal = _dealLogic.ReadElement(new DealSearchModel { Id = id });
if (deal != null) DealPayments.Add(deal.Id, deal); if (deal != null) DealPayments.Add(deal.Id, deal);
} }
_paymentLogic.Create(new PaymentBindingModel { OperatorId = HomeController.Operator.Id, DealPayments = DealPayments, }); _paymentLogic.Create(new PaymentBindingModel { OperatorId = APIClient.Operator.Id, DealPayments = DealPayments, });
Response.Redirect("Payments"); Response.Redirect("Payments");
} }
[HttpGet] [HttpGet]
public IActionResult Payment(int id) public IActionResult Payment(int id)
{ {
if (HomeController.Operator == null) if (APIClient.Operator == null)
{ {
Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>"); Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
return Redirect("/Home/Enter"); return Redirect("/Home/Enter");
@ -217,39 +215,39 @@ namespace OperatorApp.Controllers
[HttpGet] [HttpGet]
public IActionResult Transfers() public IActionResult Transfers()
{ {
if (HomeController.Operator == null) if (APIClient.Operator == null)
{ {
Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>"); Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
return Redirect("/Home/Enter"); return Redirect("/Home/Enter");
} }
return View(_transferLogic.ReadList(new TransferSearchModel { OperatorId = HomeController.Operator.Id })); return View(_transferLogic.ReadList(new TransferSearchModel { OperatorId = APIClient.Operator.Id }));
} }
[HttpGet] [HttpGet]
public IActionResult CreateTransfer() public IActionResult CreateTransfer()
{ {
if (HomeController.Operator == null) if (APIClient.Operator == null)
{ {
Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>"); Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
return Redirect("/Home/Enter"); return Redirect("/Home/Enter");
} }
ViewBag.Payments = _paymentLogic.ReadList(new PaymentSearchModel { OperatorId = HomeController.Operator.Id }); ViewBag.Payments = _paymentLogic.ReadList(new PaymentSearchModel { OperatorId = APIClient.Operator.Id });
return View(); return View();
} }
[HttpPost] [HttpPost]
public void CreateTransfer(string amount, int payment) public void CreateTransfer(string amount, int payment)
{ {
if (HomeController.Operator == null) if (APIClient.Operator == null)
{ {
Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>"); Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
return; return;
} }
_transferLogic.Create(new TransferBindingModel { OperatorId = HomeController.Operator.Id, Amount = (float)Convert.ToDouble(amount), PaymentId = payment }); _transferLogic.Create(new TransferBindingModel { OperatorId = APIClient.Operator.Id, Amount = (float)Convert.ToDouble(amount), PaymentId = payment });
Response.Redirect("Transfers"); Response.Redirect("Transfers");
} }
public void DeleteTransfer(int id) public void DeleteTransfer(int id)
{ {
if (HomeController.Operator == null) if (APIClient.Operator == null)
{ {
Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>"); Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
} }
@ -260,12 +258,12 @@ namespace OperatorApp.Controllers
[HttpGet] [HttpGet]
public IActionResult PaymentsReport() public IActionResult PaymentsReport()
{ {
if (HomeController.Operator == null) if (APIClient.Operator == null)
{ {
Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>"); Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
return Redirect("/Home/Enter"); return Redirect("/Home/Enter");
} }
ViewBag.Payments = _paymentLogic.ReadList(new PaymentSearchModel { OperatorId = HomeController.Operator.Id }); ViewBag.Payments = _paymentLogic.ReadList(new PaymentSearchModel { OperatorId = APIClient.Operator.Id });
return View(); return View();
} }
@ -304,7 +302,7 @@ namespace OperatorApp.Controllers
[HttpGet] [HttpGet]
public IActionResult TransfersReport() public IActionResult TransfersReport()
{ {
if (HomeController.Operator == null) if (APIClient.Operator == null)
{ {
Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>"); Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
return Redirect("/Home/Enter"); return Redirect("/Home/Enter");
@ -314,7 +312,7 @@ namespace OperatorApp.Controllers
[HttpPost] [HttpPost]
public IActionResult TransfersReport(DateTime dateFrom, DateTime dateTo, string reptype, string email, string fileName) public IActionResult TransfersReport(DateTime dateFrom, DateTime dateTo, string reptype, string email, string fileName)
{ {
if (HomeController.Operator == null) if (APIClient.Operator == null)
{ {
Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>"); Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
return Redirect("/Home/Enter"); return Redirect("/Home/Enter");
@ -334,7 +332,7 @@ namespace OperatorApp.Controllers
_mailWorker.MailSendAsync(new MailSendInfoBindingModel _mailWorker.MailSendAsync(new MailSendInfoBindingModel
{ {
Subject = "Отчёт о закупках", Subject = "Отчёт о закупках",
Text = "Для оператора " + HomeController.Operator.LastName + HomeController.Operator.FirstName, Text = "Для оператора " + APIClient.Operator.LastName + APIClient.Operator.FirstName,
MailAddress = email, MailAddress = email,
FileName = fileName, FileName = fileName,
Attachment = report Attachment = report
@ -351,7 +349,7 @@ namespace OperatorApp.Controllers
[HttpGet] [HttpGet]
public IActionResult AddCurrenciesToPayment() public IActionResult AddCurrenciesToPayment()
{ {
if (HomeController.Operator == null) if (APIClient.Operator == null)
{ {
Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>"); Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
return Redirect("/Home/Enter"); return Redirect("/Home/Enter");
@ -363,7 +361,7 @@ namespace OperatorApp.Controllers
[HttpPost] [HttpPost]
public void AddCurrenciesToPayment(int payment, List<int> currencies) public void AddCurrenciesToPayment(int payment, List<int> currencies)
{ {
if (HomeController.Operator == null) if (APIClient.Operator == null)
{ {
Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>"); Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
Redirect("/Home/Enter"); Redirect("/Home/Enter");

View File

@ -54,6 +54,8 @@ catch (Exception ex)
logger?.LogError(ex, "Îøèáêà ðàáîòû ñ ïî÷òîé"); logger?.LogError(ex, "Îøèáêà ðàáîòû ñ ïî÷òîé");
} }
APIClient.Connect(builder.Configuration);
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment()) if (!app.Environment.IsDevelopment())
{ {