Переход на прямое подключение веб-приложения к логике, вместо использования Rest проекта

This commit is contained in:
abazov73 2023-05-17 11:10:25 +04:00
parent 4898fbe7b1
commit 050a46e3d1
3 changed files with 37 additions and 26 deletions

View File

@ -1,4 +1,6 @@
using BankContracts.BindingModels; using BankContracts.BindingModels;
using BankContracts.BusinessLogicsContracts;
using BankContracts.SearchModels;
using BankContracts.ViewModels; using BankContracts.ViewModels;
using BankDatabaseImplement.Models; using BankDatabaseImplement.Models;
using BankDataModels.Models; using BankDataModels.Models;
@ -12,10 +14,18 @@ namespace OperatorApp.Controllers
public class HomeController : Controller public class HomeController : Controller
{ {
private readonly ILogger<HomeController> _logger; private readonly ILogger<HomeController> _logger;
private readonly IDealLogic _dealLogic;
private readonly IPaymentLogic _paymentLogic;
private readonly ITransferLogic _transferLogic;
private readonly IOperatorLogic _operatorLogic;
public HomeController(ILogger<HomeController> logger) public HomeController(ILogger<HomeController> logger, IDealLogic dealLogic, IPaymentLogic paymentLogic, ITransferLogic transferLogic, IOperatorLogic operatorLogic)
{ {
_logger = logger; _logger = logger;
_dealLogic = dealLogic;
_paymentLogic = paymentLogic;
_transferLogic = transferLogic;
_operatorLogic = operatorLogic;
} }
public IActionResult Index() public IActionResult Index()
@ -24,7 +34,7 @@ namespace OperatorApp.Controllers
{ {
return Redirect("~/Home/Enter"); return Redirect("~/Home/Enter");
} }
return View(APIClient.GetRequest<List<DealViewModel>>($"api/deal/getdeals?operatorId={APIClient.Operator.Id}")); return View(_dealLogic.ReadList(new DealSearchModel { OperatorId = APIClient.Operator.Id}));
} }
[HttpGet] [HttpGet]
@ -48,7 +58,7 @@ namespace OperatorApp.Controllers
{ {
throw new Exception("Введите логин, пароль и ФИО"); throw new Exception("Введите логин, пароль и ФИО");
} }
APIClient.PostRequest("api/operator/updateoperator", new OperatorBindingModel _operatorLogic.Update(new OperatorBindingModel
{ {
Id = APIClient.Operator.Id, Id = APIClient.Operator.Id,
LastName = lastname, LastName = lastname,
@ -85,7 +95,7 @@ namespace OperatorApp.Controllers
{ {
throw new Exception("Введите логин и пароль"); throw new Exception("Введите логин и пароль");
} }
APIClient.Operator = APIClient.GetRequest<OperatorViewModel>($"api/operator/login?login={login}&password={password}"); APIClient.Operator = _operatorLogic.ReadElement(new OperatorSearchModel { Login = login, Password = password});
if (APIClient.Operator == null) if (APIClient.Operator == null)
{ {
throw new Exception("Неверный логин/пароль"); throw new Exception("Неверный логин/пароль");
@ -106,7 +116,7 @@ namespace OperatorApp.Controllers
{ {
throw new Exception("Введите логин, пароль и ФИО"); throw new Exception("Введите логин, пароль и ФИО");
} }
APIClient.PostRequest("api/operator/createoperator", new OperatorBindingModel _operatorLogic.Create(new OperatorBindingModel
{ {
LastName = lastname, LastName = lastname,
FirstName = firstname, FirstName = firstname,
@ -130,7 +140,7 @@ namespace OperatorApp.Controllers
{ {
throw new Exception("Вы как суда попали? Суда вход только авторизованным"); throw new Exception("Вы как суда попали? Суда вход только авторизованным");
} }
APIClient.PostRequest("api/deal/createdeal", new DealBindingModel _dealLogic.Create(new DealBindingModel
{ {
ClientId = clientid, ClientId = clientid,
OperatorId = APIClient.Operator.Id, OperatorId = APIClient.Operator.Id,
@ -143,12 +153,12 @@ namespace OperatorApp.Controllers
{ {
return Redirect("~/Home/Enter"); return Redirect("~/Home/Enter");
} }
return View(APIClient.GetRequest<List<PaymentViewModel>>($"api/payment/getpayments?operatorId={APIClient.Operator.Id}")); return View(_paymentLogic.ReadList(new PaymentSearchModel { OperatorId = APIClient.Operator.Id}));
} }
[HttpGet] [HttpGet]
public IActionResult CreatePayment() public IActionResult CreatePayment()
{ {
ViewBag.Deals = APIClient.GetRequest<List<DealViewModel>>("api/deal/getdealslist"); ViewBag.Deals = _dealLogic.ReadList(new DealSearchModel { OperatorId = APIClient.Operator.Id});
return View(); return View();
} }
[HttpPost] [HttpPost]
@ -158,27 +168,13 @@ namespace OperatorApp.Controllers
{ {
throw new Exception("Вы как суда попали? Суда вход только авторизованным"); throw new Exception("Вы как суда попали? Суда вход только авторизованным");
} }
Dictionary<int, IDealModel> DealPayments = new();
Dictionary<int, ICurrencyModel> CurrencyPayments = new();
//foreach (int id in deals)
//{
// var deal = APIClient.GetRequest<DealViewModel>($"api/deal/getdeal?id={id}");
// if (deal != null) CurrencyPayments.Add(deal.Id, deal as IModel);
//}
APIClient.PostRequest("api/payment/createpayment", new PaymentBindingModel
{
OperatorId = APIClient.Operator.Id,
});
var payments = APIClient.GetRequest<List<PaymentViewModel>>("api/payment/getpaymentslist");
int addedPaymentId = payments == null ? 1 : payments[payments.Count - 1].Id;
foreach (int id in deals) foreach (int id in deals)
{ {
var deal = APIClient.GetRequest<DealViewModel>($"api/deal/getdeal?id={id}"); var deal = _dealLogic.ReadElement(new DealSearchModel { Id = id});
if (deal != null) if (deal != null) DealPayments.Add(deal.Id, deal);
{
APIClient.PostRequest<DealViewModel>($"api/payment/adddealtopayment?paymentId={addedPaymentId}", deal);
}
} }
_paymentLogic.Create(new PaymentBindingModel { OperatorId = APIClient.Operator.Id, DealPayments = DealPayments, });
Response.Redirect("Payments"); Response.Redirect("Payments");
} }
} }

View File

@ -15,6 +15,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\BankBusinessLogic\BankBusinessLogic.csproj" />
<ProjectReference Include="..\BankContracts\BankContracts.csproj" /> <ProjectReference Include="..\BankContracts\BankContracts.csproj" />
<ProjectReference Include="..\BankDatabaseImplement\BankDatabaseImplement.csproj" /> <ProjectReference Include="..\BankDatabaseImplement\BankDatabaseImplement.csproj" />
</ItemGroup> </ItemGroup>

View File

@ -1,3 +1,7 @@
using BankBusinessLogic.BusinessLogics;
using BankContracts.BusinessLogicsContracts;
using BankContracts.StoragesContracts;
using BankDatabaseImplement.Implements;
using OperatorApp; using OperatorApp;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@ -5,6 +9,16 @@ var builder = WebApplication.CreateBuilder(args);
// Add services to the container. // Add services to the container.
builder.Services.AddControllersWithViews(); builder.Services.AddControllersWithViews();
builder.Services.AddTransient<IDealStorage, DealStorage>();
builder.Services.AddTransient<IPaymentStorage, PaymentStorage>();
builder.Services.AddTransient<ITransferStorage, TransferStorage>();
builder.Services.AddTransient<IOperatorStorage, OperatorStorage>();
builder.Services.AddTransient<IDealLogic, DealLogic>();
builder.Services.AddTransient<IPaymentLogic, PaymentLogic>();
builder.Services.AddTransient<ITransferLogic, TransferLogic>();
builder.Services.AddTransient<IOperatorLogic, OperatorLogic>();
var app = builder.Build(); var app = builder.Build();
APIClient.Connect(builder.Configuration); APIClient.Connect(builder.Configuration);