Homecontroller без отчетов у оператора банка.

This commit is contained in:
ksenianeva 2023-05-19 21:52:31 +04:00
parent 3d87a14772
commit fceffcf0b6
2 changed files with 108 additions and 39 deletions

View File

@ -9,7 +9,7 @@ namespace BankOperatorApp
{ {
private static readonly HttpClient _client = new(); private static readonly HttpClient _client = new();
public static OperatorViewModel? Operator { get; set; } = null; public static BankOperatorViewModel? BankOperator { get; set; } = null;
public static void Connect(IConfiguration configuration) public static void Connect(IConfiguration configuration)
{ {

View File

@ -3,51 +3,67 @@ using BankContracts.ViewModels;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using BankOperatorApp.Models; using BankOperatorApp.Models;
using System.Diagnostics; using System.Diagnostics;
using BankContracts.BusinessLogicsContracts;
using BankContracts.SearchModels;
using BankDataModels.Models;
namespace BankOperatorApp.Controllers namespace BankOperatorApp.Controllers
{ {
public class HomeController : Controller public class HomeController : Controller
{ {
private readonly ILogger<HomeController> _logger; private readonly ILogger<HomeController> _logger;
private readonly IBankOperatorLogic _bankOperatorLogic;
private readonly ICreditProgramLogic _creditProgramLogic;
private readonly ICurrencyLogic _currencyLogic;
private ICurrencyPurchaseLogic _currencyPurchaseLogic;
public HomeController(ILogger<HomeController> logger) public HomeController(ILogger<HomeController> logger, IBankOperatorLogic bankOperatorLogic,
ICreditProgramLogic creditProgramLogic, ICurrencyLogic currencyLogic,
ICurrencyPurchaseLogic currencyPurchaseLogic)
{ {
_logger = logger; _logger = logger;
_bankOperatorLogic = bankOperatorLogic;
_creditProgramLogic = creditProgramLogic;
_currencyLogic = currencyLogic;
_currencyPurchaseLogic = currencyPurchaseLogic;
} }
public IActionResult Index() public IActionResult Index()
{ {
if (APIClient.Operator == null) if (APIClient.BankOperator == null)
{ {
return Redirect("~/Home/Enter"); return Redirect("~/Home/Enter");
} }
return View(APIClient.GetRequest<List<DealViewModel>>($"api/deal/getdeals?operatorId={APIClient.Operator.Id}")); return View(_currencyLogic.ReadList(new CurrencySearchModel { BankOperatorId =
APIClient.BankOperator.Id }));
} }
[HttpGet] [HttpGet]
public IActionResult Privacy() public IActionResult Privacy()
{ {
if (APIClient.Operator == null) if (APIClient.BankOperator == null)
{ {
return Redirect("~/Home/Enter"); return Redirect("~/Home/Enter");
} }
return View(APIClient.Operator); return View(APIClient.BankOperator);
} }
[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 (APIClient.Operator == null) if (APIClient.BankOperator == null)
{ {
throw new Exception("Вы как суда попали? Суда вход только авторизованным"); throw new Exception("Вы как суда попали? Суда вход только авторизованным");
} }
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(lastname) || string.IsNullOrEmpty(firstname) || string.IsNullOrEmpty(middleName)) if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)
|| string.IsNullOrEmpty(lastname) || string.IsNullOrEmpty(firstname) || string.IsNullOrEmpty(middleName))
{ {
throw new Exception("Введите логин, пароль и ФИО"); throw new Exception("Введите логин, пароль и ФИО");
} }
APIClient.PostRequest("api/operator/updateoperator", new OperatorBindingModel APIClient.PostRequest("api/bankoperator/updatebankoperator", new OperatorBindingModel
{ {
Id = APIClient.Operator.Id, Id = APIClient.BankOperator.Id,
LastName = lastname, LastName = lastname,
FirstName = firstname, FirstName = firstname,
MiddleName = middleName, MiddleName = middleName,
@ -55,18 +71,19 @@ namespace BankOperatorApp.Controllers
Password = password Password = password
}); });
APIClient.Operator.LastName = lastname; APIClient.BankOperator.LastName = lastname;
APIClient.Operator.FirstName = firstname; APIClient.BankOperator.FirstName = firstname;
APIClient.Operator.MiddleName = middleName; APIClient.BankOperator.MiddleName = middleName;
APIClient.Operator.Login = login; APIClient.BankOperator.Login = login;
APIClient.Operator.Password = password; APIClient.BankOperator.Password = password;
Response.Redirect("Index"); Response.Redirect("Index");
} }
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error() public IActionResult Error()
{ {
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); return View(new ErrorViewModel { RequestId =
Activity.Current?.Id ?? HttpContext.TraceIdentifier });
} }
[HttpGet] [HttpGet]
@ -82,8 +99,10 @@ namespace BankOperatorApp.Controllers
{ {
throw new Exception("Введите логин и пароль"); throw new Exception("Введите логин и пароль");
} }
APIClient.Operator = APIClient.GetRequest<OperatorViewModel>($"api/operator/login?login={login}&password={password}"); APIClient.BankOperator = APIClient.
if (APIClient.Operator == null) GetRequest<BankOperatorViewModel>
($"api/bankoperator/login?login={login}&password={password}");
if (APIClient.BankOperator == null)
{ {
throw new Exception("Неверный логин/пароль"); throw new Exception("Неверный логин/пароль");
} }
@ -97,13 +116,16 @@ namespace BankOperatorApp.Controllers
} }
[HttpPost] [HttpPost]
public void Register(string login, string password, string lastname, string firstname, string middleName) public void Register(string login, string password,
string lastname, string firstname, string middleName)
{ {
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(lastname) || string.IsNullOrEmpty(firstname) || string.IsNullOrEmpty(middleName)) if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)
|| string.IsNullOrEmpty(lastname) || string.IsNullOrEmpty(firstname)
|| string.IsNullOrEmpty(middleName))
{ {
throw new Exception("Введите логин, пароль и ФИО"); throw new Exception("Введите логин, пароль и ФИО");
} }
APIClient.PostRequest("api/operator/createoperator", new OperatorBindingModel APIClient.PostRequest("api/bankoperator/createbankoperator", new BankOperatorBindingModel
{ {
LastName = lastname, LastName = lastname,
FirstName = firstname, FirstName = firstname,
@ -115,52 +137,99 @@ namespace BankOperatorApp.Controllers
return; return;
} }
[HttpGet] [HttpGet]
public IActionResult CreateDeal() public IActionResult CreateCurrency()
{ {
return View(); return View();
} }
[HttpPost] [HttpPost]
public void CreateDeal(int clientid) public void CreateCurrency(string name)
{ {
if (APIClient.Operator == null) if (APIClient.BankOperator == null)
{ {
throw new Exception("Вы как суда попали? Суда вход только авторизованным"); throw new Exception("Вы как суда попали? Суда вход только авторизованным");
} }
APIClient.PostRequest("api/deal/createdeal", new DealBindingModel APIClient.PostRequest("api/currency/createcurrency", new CurrencyBindingModel
{ {
ClientId = clientid, BankOperatorId = APIClient.BankOperator.Id,
OperatorId = APIClient.Operator.Id, Name = name,
}); });
Response.Redirect("Index"); Response.Redirect("Index");
} }
public IActionResult Payments() public IActionResult CreditPrograms()
{ {
if (APIClient.Operator == null) if (APIClient.BankOperator == null)
{ {
return Redirect("~/Home/Enter"); return Redirect("~/Home/Enter");
} }
return View(APIClient.GetRequest<List<PaymentViewModel>>($"api/payment/getpayments?operatorId={APIClient.Operator.Id}")); return View(APIClient.GetRequest
<List<PaymentViewModel>>
($"api/creditprogram/getcreditprograms?bankoperatorId={APIClient.BankOperator.Id}"));
} }
[HttpGet] [HttpGet]
public IActionResult CreatePayment() public IActionResult CreateCreditProgram()
{ {
ViewBag.Deals = APIClient.GetRequest<List<DealViewModel>>("api/deal/getdealslist"); ViewBag.Currencies = APIClient.GetRequest<List<CurrencyViewModel>>
("api/currency/getcurrencieslist");
return View(); return View();
} }
[HttpPost] [HttpPost]
public void CreatePayment(int clientid) public void CreateCreditProgram(List<int> currenciess)
{ {
if (APIClient.Operator == null) if (APIClient.BankOperator == null)
{ {
throw new Exception("Вы как суда попали? Суда вход только авторизованным"); throw new Exception("Вы как суда попали? Суда вход только авторизованным");
} }
APIClient.PostRequest("api/deal/createdeal", new PaymentBindingModel Dictionary<int, ICurrencyModel> CurrencyCreditPrograms = new();
foreach (int id in currenciess)
{ {
var currency = _currencyLogic.ReadElement(new CurrencySearchModel { Id = id });
if (currency != null) CurrencyCreditPrograms.Add(currency.Id, currency);
}
_creditProgramLogic.Create(new CreditProgramBindingModel { BankOperatorId =
APIClient.BankOperator.Id,
CreditProgramCurrencies = CurrencyCreditPrograms, });
Response.Redirect("Payments");
}
[HttpGet]
public IActionResult CreditProgram(int id)
{
return View(_creditProgramLogic.ReadElement(new CreditProgramSearchModel { Id = id }));
}
[HttpGet]
public IActionResult CurrencyPurchase()
{
if (APIClient.BankOperator == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
return View(_currencyPurchaseLogic.ReadList
(new CurrencyPurchaseSearchModel { BankOperatorId = APIClient.BankOperator.Id }));
}
[HttpGet]
public IActionResult CreateCurrencyPurchase()
{
if (APIClient.BankOperator == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
ViewBag.Currency = _currencyLogic.ReadList
(new CurrencySearchModel { BankOperatorId = APIClient.BankOperator.Id });
return View();
}
[HttpPost]
public void CreateCurrencyPurchasr(string amount, int currencyId)
{
if (APIClient.BankOperator == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
OperatorId = APIClient.Operator.Id, _currencyPurchaseLogic.Create(new CurrencyPurchaseBindingModel
}); { BankOperatorId = APIClient.BankOperator.Id,
Response.Redirect("Index"); Amount = (float)Convert.ToDouble(amount),
CurrencyId = currencyId });
Response.Redirect("Transfers");
} }
} }
} }