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 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)
{
_logger = logger;
@ -40,28 +38,28 @@ namespace OperatorApp.Controllers
public IActionResult Index()
{
if (HomeController.Operator == null)
if (APIClient.Operator == null)
{
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]
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>");
return Redirect("/Home/Enter");
}
return View(HomeController.Operator);
return View(APIClient.Operator);
}
[HttpPost]
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>");
return;
@ -72,7 +70,7 @@ namespace OperatorApp.Controllers
}
_operatorLogic.Update(new OperatorBindingModel
{
Id = HomeController.Operator.Id,
Id = APIClient.Operator.Id,
LastName = lastname,
FirstName = firstname,
MiddleName = middleName,
@ -80,11 +78,11 @@ namespace OperatorApp.Controllers
Password = password
});
HomeController.Operator.LastName = lastname;
HomeController.Operator.FirstName = firstname;
HomeController.Operator.MiddleName = middleName;
HomeController.Operator.Login = login;
HomeController.Operator.Password = password;
APIClient.Operator.LastName = lastname;
APIClient.Operator.FirstName = firstname;
APIClient.Operator.MiddleName = middleName;
APIClient.Operator.Login = login;
APIClient.Operator.Password = password;
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>");
return;
}
HomeController.Operator = _operatorLogic.ReadElement(new OperatorSearchModel { Login = login, Password = password });
if (HomeController.Operator == null)
APIClient.Operator = _operatorLogic.ReadElement(new OperatorSearchModel { Login = login, Password = password });
if (APIClient.Operator == null)
{
Response.WriteAsync($"<script language=\"javascript\">alert('Wrong login or password!');window.location.replace('/Home/Enter');</script>");
return;
@ -144,7 +142,7 @@ namespace OperatorApp.Controllers
[HttpGet]
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>");
return Redirect("/Home/Enter");
@ -155,7 +153,7 @@ namespace OperatorApp.Controllers
[HttpPost]
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>");
return;
@ -163,34 +161,34 @@ namespace OperatorApp.Controllers
_dealLogic.Create(new DealBindingModel
{
ClientId = clientid,
OperatorId = HomeController.Operator.Id,
OperatorId = APIClient.Operator.Id,
});
Response.Redirect("Index");
}
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>");
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]
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>");
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();
}
[HttpPost]
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>");
return;
@ -201,13 +199,13 @@ namespace OperatorApp.Controllers
var deal = _dealLogic.ReadElement(new DealSearchModel { Id = id });
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");
}
[HttpGet]
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>");
return Redirect("/Home/Enter");
@ -217,39 +215,39 @@ namespace OperatorApp.Controllers
[HttpGet]
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>");
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]
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>");
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();
}
[HttpPost]
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>");
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");
}
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>");
}
@ -260,12 +258,12 @@ namespace OperatorApp.Controllers
[HttpGet]
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>");
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();
}
@ -304,7 +302,7 @@ namespace OperatorApp.Controllers
[HttpGet]
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>");
return Redirect("/Home/Enter");
@ -314,7 +312,7 @@ namespace OperatorApp.Controllers
[HttpPost]
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>");
return Redirect("/Home/Enter");
@ -334,7 +332,7 @@ namespace OperatorApp.Controllers
_mailWorker.MailSendAsync(new MailSendInfoBindingModel
{
Subject = "Отчёт о закупках",
Text = "Для оператора " + HomeController.Operator.LastName + HomeController.Operator.FirstName,
Text = "Для оператора " + APIClient.Operator.LastName + APIClient.Operator.FirstName,
MailAddress = email,
FileName = fileName,
Attachment = report
@ -351,7 +349,7 @@ namespace OperatorApp.Controllers
[HttpGet]
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>");
return Redirect("/Home/Enter");
@ -363,7 +361,7 @@ namespace OperatorApp.Controllers
[HttpPost]
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>");
Redirect("/Home/Enter");

View File

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