Работают формы входа, регистрации, редактирования пользователя и круды для карт
This commit is contained in:
parent
6a7b0c75d2
commit
bac9650d98
@ -1,5 +1,7 @@
|
||||
using BankContracts.ViewModels;
|
||||
using Newtonsoft.Json;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
|
||||
namespace BankClientApp
|
||||
{
|
||||
@ -14,5 +16,31 @@ namespace BankClientApp
|
||||
_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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
using BankClientApp.Models;
|
||||
using BankContracts.BindingModels;
|
||||
using BankContracts.ViewModels;
|
||||
using BankDatabaseImplement.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||
using System.Diagnostics;
|
||||
@ -15,13 +17,39 @@ namespace BankClientApp.Controllers
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View(new List<CardViewModel>());
|
||||
}
|
||||
#region//Клиенты
|
||||
[HttpGet]
|
||||
public IActionResult Privacy()
|
||||
{
|
||||
return View(new ClientViewModel());
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(APIClient.Client);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Privacy(string login, string password, string fio)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
|
||||
{
|
||||
throw new Exception("Введите логин, пароль и ФИО");
|
||||
}
|
||||
APIClient.PostRequest("api/client/updateclient", new ClientBindingModel
|
||||
{
|
||||
Id = APIClient.Client.Id,
|
||||
Fio = fio,
|
||||
Email = login,
|
||||
Password = password
|
||||
});
|
||||
APIClient.Client.Fio = fio;
|
||||
APIClient.Client.Email = login;
|
||||
APIClient.Client.Password = password;
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@ -30,41 +58,176 @@ namespace BankClientApp.Controllers
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Enter(string login, string password)
|
||||
{
|
||||
if (string.IsNullOrEmpty(login) ||
|
||||
string.IsNullOrEmpty(password))
|
||||
{
|
||||
throw new Exception("Введите логин и пароль");
|
||||
}
|
||||
APIClient.Client = APIClient.GetRequest<ClientViewModel>($"api/client/login?login={login}&password={password}");
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Неверный логин/пароль");
|
||||
}
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Register()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Register(string login, string password, string fio)
|
||||
{
|
||||
if (string.IsNullOrEmpty(login) ||
|
||||
string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
|
||||
{
|
||||
throw new Exception("Введите логин, пароль и ФИО");
|
||||
}
|
||||
APIClient.PostRequest("api/client/register", new ClientBindingModel
|
||||
{
|
||||
Fio = fio,
|
||||
Email = login,
|
||||
Password = password
|
||||
});
|
||||
Response.Redirect("Enter");
|
||||
return;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region//работа с картами
|
||||
public IActionResult Index()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(APIClient.GetRequest<List<CardViewModel>>($"api/card/getcardlist?clientid={APIClient.Client.Id}"));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult CardCreate()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CardCreate(string number, string cvv, string pin)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
APIClient.PostRequest("api/card/createcard", new
|
||||
CardBindingModel
|
||||
{
|
||||
ClientId = APIClient.Client.Id,
|
||||
Number = number,
|
||||
Cvv = cvv,
|
||||
Pin = pin
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult CardUpdate()
|
||||
{
|
||||
ViewBag.Cards = new List<CardViewModel>();
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Cards = APIClient.GetRequest<List<CardViewModel>>($"api/card/getcardlist?clientid={APIClient.Client.Id}");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CardUpdate(int card, string number, string cvv, string pin, DateTime expirationdate)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
APIClient.PostRequest("api/card/updatecard", new
|
||||
CardBindingModel
|
||||
{
|
||||
Id = card,
|
||||
ClientId = APIClient.Client.Id,
|
||||
Number = number,
|
||||
Cvv = cvv,
|
||||
Pin = pin,
|
||||
ExpirationDate = expirationdate
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public CardViewModel? GetCard(int cardId)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
var result = APIClient.GetRequest<CardViewModel>($"api/card/getcard?cardid={cardId}");
|
||||
if (result == null)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult CardDelete()
|
||||
{
|
||||
ViewBag.Cards = new List<CardViewModel>();
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Cards = APIClient.GetRequest<List<CardViewModel>>($"api/card/getcardlist?clientid={APIClient.Client.Id}");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CardDelete(int card)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
APIClient.PostRequest("api/card/deletecard", new
|
||||
CardBindingModel
|
||||
{
|
||||
Id = card,
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region//работа с операциями
|
||||
[HttpGet]
|
||||
public IActionResult Operation()
|
||||
{
|
||||
return View(new List<OperationViewModel>());
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(APIClient.GetRequest<List<OperationViewModel>>($"api/operation/getoperationlist?clientid={APIClient.Client.Id}"));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult OperationCreate()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Cards = new List<CardViewModel>();
|
||||
return View();
|
||||
}
|
||||
@ -72,6 +235,10 @@ namespace BankClientApp.Controllers
|
||||
[HttpGet]
|
||||
public IActionResult OperationUpdate()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Operations = new List<OperationViewModel>();
|
||||
ViewBag.Cards = new List<CardViewModel>();
|
||||
return View();
|
||||
@ -80,6 +247,10 @@ namespace BankClientApp.Controllers
|
||||
[HttpGet]
|
||||
public IActionResult OperationDelete()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Operations = new List<OperationViewModel>();
|
||||
return View();
|
||||
}
|
||||
@ -87,18 +258,32 @@ namespace BankClientApp.Controllers
|
||||
[HttpGet]
|
||||
public IActionResult OperationTransfer()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region//работа с заявками
|
||||
[HttpGet]
|
||||
public IActionResult Request()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(new List<RequestViewModel>());
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult RequestCreate()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Cards = new List<CardViewModel>();
|
||||
return View();
|
||||
}
|
||||
@ -106,6 +291,10 @@ namespace BankClientApp.Controllers
|
||||
[HttpGet]
|
||||
public IActionResult RequestUpdate()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Requests = new List<RequestViewModel>();
|
||||
ViewBag.Cards = new List<CardViewModel>();
|
||||
return View();
|
||||
@ -114,27 +303,44 @@ namespace BankClientApp.Controllers
|
||||
[HttpGet]
|
||||
public IActionResult RequestDelete()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Requests = new List<RequestViewModel>();
|
||||
return View();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region//работа с отчетами
|
||||
[HttpGet]
|
||||
public IActionResult Report()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult TransferListReport()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Cards = new List<CardViewModel>();
|
||||
return View();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region//ошибки
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -4,7 +4,9 @@ var builder = WebApplication.CreateBuilder(args);
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllersWithViews();
|
||||
var app = builder.Build();
|
||||
|
||||
APIClient.Connect(builder.Configuration);
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (!app.Environment.IsDevelopment())
|
||||
{
|
||||
|
@ -46,10 +46,10 @@
|
||||
url: "/Home/GetCard",
|
||||
data: { cardId: card },
|
||||
success: function (result) {
|
||||
$('#number').val(result.item1.number);
|
||||
$('#cvv').val(result.item1.cvv);
|
||||
$('#pin').val(result.item1.pin);
|
||||
$('#expirationdate').val(result.item1.expirationDate);
|
||||
$('#number').val(result.number);
|
||||
$('#cvv').val(result.cvv);
|
||||
$('#pin').val(result.pin);
|
||||
$('#expirationdate').val(result.expirationDate);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
@ -8,11 +8,11 @@
|
||||
</div>
|
||||
<div class="text-center">
|
||||
@{
|
||||
// if (Model == null)
|
||||
// {
|
||||
// <h3 class="display-4">Авторизируйтесь</h3>
|
||||
// return;
|
||||
// }
|
||||
if (Model == null)
|
||||
{
|
||||
<h3 class="display-4">авторизируйтесь</h3>
|
||||
return;
|
||||
}
|
||||
<p>
|
||||
<a asp-action="CardCreate">Создать карту</a>
|
||||
<a asp-action="CardUpdate">Обновить карту</a>
|
||||
@ -39,9 +39,6 @@
|
||||
<th>
|
||||
Держатель карты
|
||||
</th>
|
||||
<th>
|
||||
Номер счета
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -72,10 +69,6 @@
|
||||
@Html.DisplayFor(modelItem =>
|
||||
item.ClientName)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem =>
|
||||
item.AccountNumber)
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
|
@ -7,8 +7,8 @@
|
||||
</div>
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Email:</div>
|
||||
<div class="col-8"><input type="text" name="email" /></div>
|
||||
<div class="col-4">Логин:</div>
|
||||
<div class="col-8"><input type="text" name="login" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Пароль:</div>
|
||||
|
@ -24,8 +24,5 @@ namespace BankContracts.ViewModels
|
||||
public int ClientId { get; set; }
|
||||
[DisplayName("Держатель карты")]
|
||||
public string ClientName { get; set; } = string.Empty;
|
||||
public int? AccountId { get; set; }
|
||||
[DisplayName("Номер счета")]
|
||||
public string AccountNumber { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
@ -40,14 +40,15 @@ namespace BankDatabaseImplement.Models
|
||||
public static Card? Create(CardBindingModel model)
|
||||
{
|
||||
if (model == null) return null;
|
||||
DateTime tmp = DateTime.Now;
|
||||
return new Card
|
||||
{
|
||||
Id = model.Id,
|
||||
Number = model.Number,
|
||||
Cvv = model.Cvv,
|
||||
Pin = model.Pin,
|
||||
ReleaseDate = DateTime.Now,
|
||||
ExpirationDate = DateTime.Now.AddYears(3),
|
||||
ReleaseDate = new DateTime(tmp.Year, tmp.Month, tmp.Day, tmp.Hour, tmp.Minute, 0, tmp.Kind),
|
||||
ExpirationDate = new DateTime(tmp.Year + 3, tmp.Month, tmp.Day, tmp.Hour, tmp.Minute, 0, tmp.Kind),
|
||||
ClientId = model.ClientId,
|
||||
};
|
||||
}
|
||||
@ -58,7 +59,6 @@ namespace BankDatabaseImplement.Models
|
||||
Number = model.Number;
|
||||
Cvv = model.Cvv;
|
||||
Pin = model.Pin;
|
||||
ReleaseDate = model.ReleaseDate;
|
||||
ExpirationDate = model.ExpirationDate;
|
||||
ClientId = model.ClientId;
|
||||
}
|
||||
|
@ -19,11 +19,14 @@ namespace BankRestApi.Controllers
|
||||
_logic = Card;
|
||||
}
|
||||
[HttpGet]
|
||||
public List<CardViewModel>? GetCardList()
|
||||
public List<CardViewModel>? GetCardList(int clientId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadList(null);
|
||||
return _logic.ReadList(new CardSearchModel
|
||||
{
|
||||
ClientId = clientId,
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -33,18 +36,18 @@ namespace BankRestApi.Controllers
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public CardViewModel? GetCard(int CardId)
|
||||
public CardViewModel? GetCard(int cardId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadElement(new CardSearchModel
|
||||
{
|
||||
Id = CardId
|
||||
Id = cardId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения менеджера по Id={Id}", CardId);
|
||||
_logger.LogError(ex, "Ошибка получения менеджера по Id={Id}", cardId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@ -63,7 +66,7 @@ namespace BankRestApi.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
[HttpPost]
|
||||
public void UpdateCard(CardBindingModel model)
|
||||
{
|
||||
try
|
||||
@ -77,7 +80,7 @@ namespace BankRestApi.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
[HttpPost]
|
||||
public void DeleteCard(CardBindingModel model)
|
||||
{
|
||||
try
|
||||
|
@ -81,7 +81,7 @@ namespace BankRestApi.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
[HttpPost]
|
||||
public void UpdateClient(ClientBindingModel model)
|
||||
{
|
||||
try
|
||||
@ -95,7 +95,7 @@ namespace BankRestApi.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
[HttpPost]
|
||||
public void DeleteClient(ClientBindingModel model)
|
||||
{
|
||||
try
|
||||
|
@ -63,7 +63,7 @@ namespace BankRestApi.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
[HttpPost]
|
||||
public void UpdateOperation(OperationBindingModel model)
|
||||
{
|
||||
try
|
||||
@ -77,7 +77,7 @@ namespace BankRestApi.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
[HttpPost]
|
||||
public void DeleteOperation(OperationBindingModel model)
|
||||
{
|
||||
try
|
||||
|
@ -63,7 +63,7 @@ namespace BankRestApi.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
[HttpPost]
|
||||
public void UpdateRequest(RequestBindingModel model)
|
||||
{
|
||||
try
|
||||
@ -77,7 +77,7 @@ namespace BankRestApi.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
[HttpPost]
|
||||
public void DeleteRequest(RequestBindingModel model)
|
||||
{
|
||||
try
|
||||
|
Loading…
Reference in New Issue
Block a user