Формы для операций, кроме связи с переводами, работают
This commit is contained in:
parent
bac9650d98
commit
a655f961e7
@ -22,10 +22,10 @@ namespace BankBusinessLogic.BusinessLogic
|
||||
_operationStorage = operationStorage;
|
||||
}
|
||||
|
||||
public List<OperationViewModel>? ReadList(OperationSearchModel? model)
|
||||
public List<OperationViewModel>? ReadList(OperationSearchModel? model, int? clientId)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id: {Id}", model?.Id);
|
||||
var list = model == null ? _operationStorage.GetFullList() : _operationStorage.GetFilteredList(model);
|
||||
var list = model == null ? _operationStorage.GetFullList(clientId) : _operationStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
|
@ -228,10 +228,31 @@ namespace BankClientApp.Controllers
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Cards = new List<CardViewModel>();
|
||||
List<CardViewModel>? list = APIClient.GetRequest<List<CardViewModel>>($"api/card/getcardlist?clientid={APIClient.Client.Id}");
|
||||
ViewBag.Cards = list;
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void OperationCreate(int sum, int? sendercard, int recipientcard)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
if (sendercard == recipientcard)
|
||||
throw new Exception("Зачем в отправителе и получателе одну и ту же карту указали??? Думаете нам в банке заняться нечем?");
|
||||
APIClient.PostRequest("api/operation/createoperation", new
|
||||
OperationBindingModel
|
||||
{
|
||||
Sum = sum,
|
||||
SenderCardId = sendercard,
|
||||
RecipientCardId = recipientcard,
|
||||
});
|
||||
Response.Redirect("Operation");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult OperationUpdate()
|
||||
{
|
||||
@ -239,11 +260,48 @@ namespace BankClientApp.Controllers
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Operations = new List<OperationViewModel>();
|
||||
ViewBag.Cards = new List<CardViewModel>();
|
||||
ViewBag.Operations = APIClient.GetRequest<List<OperationViewModel>>($"api/operation/getoperationlist?clientid={APIClient.Client.Id}");
|
||||
ViewBag.Cards = APIClient.GetRequest<List<CardViewModel>>($"api/card/getcardlist?clientid={APIClient.Client.Id}");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void OperationUpdate(int operation, int sum, int? sendercard, int recipientcard)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
if (sendercard == recipientcard)
|
||||
{
|
||||
throw new Exception("Зачем в отправителе и получателе одну и ту же карту указали??? Думаете нам в банке заняться нечем?");
|
||||
}
|
||||
APIClient.PostRequest("api/operation/updateoperation", new
|
||||
OperationBindingModel
|
||||
{
|
||||
Id = operation,
|
||||
Sum = sum,
|
||||
SenderCardId = sendercard,
|
||||
RecipientCardId = recipientcard,
|
||||
});
|
||||
Response.Redirect("Operation");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public OperationViewModel? GetOperation(int operationId)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
var result = APIClient.GetRequest<OperationViewModel>($"api/operation/getoperation?operationid={operationId}");
|
||||
if (result == null)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult OperationDelete()
|
||||
{
|
||||
@ -251,10 +309,25 @@ namespace BankClientApp.Controllers
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Operations = new List<OperationViewModel>();
|
||||
ViewBag.Operations = APIClient.GetRequest<List<OperationViewModel>>($"api/operation/getoperationlist?clientid={APIClient.Client.Id}");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void OperationDelete(int operation)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
APIClient.PostRequest("api/operation/deleteoperation", new
|
||||
OperationBindingModel
|
||||
{
|
||||
Id = operation,
|
||||
});
|
||||
Response.Redirect("Operation");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult OperationTransfer()
|
||||
{
|
||||
@ -264,6 +337,12 @@ namespace BankClientApp.Controllers
|
||||
}
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void OperationTransfer(int operation, int transfer)
|
||||
{
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region//работа с заявками
|
||||
|
@ -36,6 +36,9 @@
|
||||
<th>
|
||||
Получатель
|
||||
</th>
|
||||
<th>
|
||||
Номер перевода
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -62,6 +65,10 @@
|
||||
@Html.DisplayFor(modelItem =>
|
||||
item.RecipientCardNumber)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem =>
|
||||
item.TransferId)
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
|
@ -8,7 +8,7 @@
|
||||
<div class="row">
|
||||
<div class="col-4">Сумма:</div>
|
||||
<div class="col-8">
|
||||
<input type="text" name="sum" id="sum" />
|
||||
<input type="number" name="sum" id="sum" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
|
@ -9,7 +9,7 @@
|
||||
<div class="row">
|
||||
<div class="col-4">Операция:</div>
|
||||
<div class="col-8">
|
||||
<select id="operation" name="operation" class="form-control" asp-items="@(new SelectList(@ViewBag.Operations, "Id", "Id"))"></select>
|
||||
<select id="operation" name="operation" class="form-control" asp-items="@(new SelectList(@ViewBag.Operations, "Id", "Id" ))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
@ -34,4 +34,29 @@
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
|
||||
</div>
|
||||
</form>
|
||||
</form>
|
||||
|
||||
@section Scripts
|
||||
{
|
||||
<script>
|
||||
function check() {
|
||||
var operation = $('#operation').val();
|
||||
if (operation) {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: "/Home/GetOperation",
|
||||
data: { operationId: operation },
|
||||
success: function (result) {
|
||||
$('#sum').val(result.sum);
|
||||
$('#sendercard').val(result.senderCardId);
|
||||
$('#recipientcard').val(result.recipientCardId);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
check();
|
||||
$('#card').on('change', function () {
|
||||
check();
|
||||
});
|
||||
</script>
|
||||
}
|
@ -11,7 +11,7 @@ namespace BankContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IOperationLogic
|
||||
{
|
||||
List<OperationViewModel>? ReadList(OperationSearchModel? model);
|
||||
List<OperationViewModel>? ReadList(OperationSearchModel? model, int? clientId);
|
||||
OperationViewModel? ReadElement(OperationSearchModel model);
|
||||
bool Create(OperationBindingModel model);
|
||||
bool Update(OperationBindingModel model);
|
||||
|
@ -11,7 +11,7 @@ namespace BankContracts.StoragesContracts
|
||||
{
|
||||
public interface IOperationStorage
|
||||
{
|
||||
List<OperationViewModel> GetFullList();
|
||||
List<OperationViewModel> GetFullList(int? clientId = null);
|
||||
List<OperationViewModel> GetFilteredList(OperationSearchModel model);
|
||||
OperationViewModel? GetElement(OperationSearchModel model);
|
||||
OperationViewModel? Insert(OperationBindingModel model);
|
||||
|
@ -22,5 +22,6 @@ namespace BankContracts.ViewModels
|
||||
public int RecipientCardId { get; set; }
|
||||
[DisplayName("Номер карты получателя")]
|
||||
public string RecipientCardNumber { get; set; } = string.Empty;
|
||||
public int? TransferId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -14,11 +14,17 @@ namespace BankDatabaseImplement.Implements
|
||||
{
|
||||
public class OperationStorage : IOperationStorage
|
||||
{
|
||||
public List<OperationViewModel> GetFullList()
|
||||
public List<OperationViewModel> GetFullList(int? clientId = null)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
if (clientId != null) {
|
||||
return context.Operations.Include(x => x.SenderCard).Include(x => x.RecipientCard)
|
||||
//todo узнать у ростислава по поводу фильтрации
|
||||
.Where(x => (x.SenderCard != null && x.SenderCard.ClientId == clientId) || (x.RecipientCard != null && x.RecipientCard.ClientId == clientId))
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
return context.Operations.Include(x => x.SenderCard).Include(x => x.RecipientCard)
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
public List<OperationViewModel> GetFilteredList(OperationSearchModel model)
|
||||
{
|
||||
|
@ -44,7 +44,6 @@ namespace BankDatabaseImplement.Models
|
||||
{
|
||||
if (model == null) return;
|
||||
Sum = model.Sum;
|
||||
OperationTime = model.OperationTime;
|
||||
SenderCardId = model.SenderCardId;
|
||||
RecipientCardId = model.RecipientCardId;
|
||||
}
|
||||
|
@ -55,7 +55,6 @@ namespace BankDatabaseImplement.Models
|
||||
public void Update(RequestBindingModel model)
|
||||
{
|
||||
Sum = model.Sum;
|
||||
RequestTime = model.RequestTime;
|
||||
Status = model.Status;
|
||||
}
|
||||
|
||||
|
@ -19,11 +19,11 @@ namespace BankRestApi.Controllers
|
||||
_logic = Operation;
|
||||
}
|
||||
[HttpGet]
|
||||
public List<OperationViewModel>? GetOperationList()
|
||||
public List<OperationViewModel>? GetOperationList(int clientId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadList(null);
|
||||
return _logic.ReadList(null, clientId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user