Compare commits

..

No commits in common. "b550f63649f4a4e1634bb690dc77c5d80032a6ee" and "879a6536bc8d756f5b1fb52901426d56b688871f" have entirely different histories.

23 changed files with 58 additions and 248 deletions

View File

@ -3,7 +3,6 @@ using BankContracts.BusinessLogicsContracts;
using BankContracts.SearchModels;
using BankContracts.StoragesContracts;
using BankContracts.ViewModels;
using DocumentFormat.OpenXml.Wordprocessing;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
@ -35,18 +34,6 @@ namespace BankBusinessLogic.BusinessLogic
_logger.LogInformation("ReadList Count: {Count}", list.Count);
return list;
}
public List<CardViewModel>? ReadListByRequestId(CardSearchModel model)
{
_logger.LogInformation("ReadListByRequestId. Number: {Number}, Id: {Id}", model?.Number, model?.Id);
var list = _cardStorage.GetListForRequest(model);
if (list == null)
{
_logger.LogWarning("ReadListByRequestId return null list");
return null;
}
_logger.LogInformation("ReadListByRequestId Count: {Count}", list.Count);
return list;
}
public CardViewModel? ReadElement(CardSearchModel model)
{
_logger.LogInformation("ReadElement Number: {Number}, Id: {Id}", model?.Number, model?.Id);

View File

@ -47,19 +47,6 @@ namespace BankBusinessLogic.BusinessLogic
_logger.LogInformation("ReadElement find. Id: {Id}", element.Id);
return element;
}
public bool LinkOperationTransfer(int operationId, int transferId)
{
if (operationId <= 0 || transferId <= 0)
return false;
if (_operationStorage.LinkOperationTransfer(operationId, transferId))
{
_logger.LogWarning("link operation failed");
return false;
}
return true;
}
public bool Create(OperationBindingModel model)
{
CheckModel(model);

View File

@ -23,10 +23,10 @@ namespace BankBusinessLogic.BusinessLogic
_requestStorage = requestStorage;
}
public List<RequestViewModel>? ReadList(RequestSearchModel? model, int? clientId)
public List<RequestViewModel>? ReadList(RequestSearchModel? model)
{
_logger.LogInformation("ReadList. Id: {Id}", model?.Id);
var list = model == null ? _requestStorage.GetFullList(clientId) : _requestStorage.GetFilteredList(model);
var list = model == null ? _requestStorage.GetFullList() : _requestStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");

View File

@ -1,9 +1,7 @@
using BankClientApp.Models;
using BankContracts.BindingModels;
using BankContracts.SearchModels;
using BankContracts.ViewModels;
using BankDatabaseImplement.Models;
using BankDataModels.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using System.Diagnostics;
@ -185,21 +183,6 @@ namespace BankClientApp.Controllers
return result;
}
[HttpGet]
public List<CardViewModel>? GetCards(int requestId)
{
if (APIClient.Client == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
var result = APIClient.GetRequest<List<CardViewModel>>($"api/card/getcards?requestid={requestId}");
if (result == null)
{
return default;
}
return result;
}
[HttpGet]
public IActionResult CardDelete()
{
@ -352,24 +335,13 @@ namespace BankClientApp.Controllers
{
return Redirect("~/Home/Enter");
}
ViewBag.Operations = APIClient.GetRequest<List<OperationViewModel>>($"api/operation/getoperationlist?clientid={APIClient.Client.Id}");
ViewBag.Transfers = APIClient.GetRequest<List<TransferViewModel>>($"api/transfer/gettransferlist");
return View();
}
[HttpPost]
public void OperationTransfer(int operation, int transfer)
{
if (APIClient.Client == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
APIClient.PostRequest("api/operation/linkoperationtransfer", new OperationBindingModel
{
Id = operation,
TransferId = transfer,
});
Response.Redirect("Operation");
}
#endregion
@ -381,7 +353,7 @@ namespace BankClientApp.Controllers
{
return Redirect("~/Home/Enter");
}
return View(APIClient.GetRequest<List<RequestViewModel>>($"api/request/getrequestlist?clientid={APIClient.Client.Id}"));
return View(new List<RequestViewModel>());
}
[HttpGet]
@ -391,29 +363,10 @@ namespace BankClientApp.Controllers
{
return Redirect("~/Home/Enter");
}
ViewBag.Cards = APIClient.GetRequest<List<CardViewModel>>($"api/card/getcardlist?clientid={APIClient.Client.Id}");
ViewBag.Cards = new List<CardViewModel>();
return View();
}
[HttpPost]
public void RequestCreate(int sum, List<int> cards)
{
if (APIClient.Client == null)
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
Dictionary<int, ICardModel> a = new Dictionary<int, ICardModel>();
foreach(int card in cards)
{
a.Add(card, new CardSearchModel() { Id = card } as ICardModel);
}
APIClient.PostRequest("/api/request/createrequest", new RequestBindingModel
{
Sum = sum,
CardRequests = a,
Status = RequestStatus.Неизвестен
});
Response.Redirect("Request");
}
[HttpGet]
public IActionResult RequestUpdate()
{
@ -421,30 +374,11 @@ namespace BankClientApp.Controllers
{
return Redirect("~/Home/Enter");
}
ViewBag.Requests = APIClient.GetRequest<List<RequestViewModel>>($"api/request/getrequestlist?clientid={APIClient.Client.Id}");
ViewBag.Cards = APIClient.GetRequest<List<CardViewModel>>($"api/card/getcardlist?clientid={APIClient.Client.Id}");
ViewBag.Requests = new List<RequestViewModel>();
ViewBag.Cards = new List<CardViewModel>();
return View();
}
[HttpPost]
public void RequestUpdate(int sum, List<int> cards)
{
if (APIClient.Client == null)
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
Dictionary<int, ICardModel> a = new Dictionary<int, ICardModel>();
foreach (int card in cards)
{
a.Add(card, new CardSearchModel() { Id = card } as ICardModel);
}
APIClient.PostRequest("/api/request/updaterequest", new RequestBindingModel
{
Sum = sum,
CardRequests = a,
Status = RequestStatus.Неизвестен
});
Response.Redirect("Request");
}
[HttpGet]
public IActionResult RequestDelete()
{
@ -452,29 +386,13 @@ namespace BankClientApp.Controllers
{
return Redirect("~/Home/Enter");
}
ViewBag.Requests = APIClient.GetRequest<List<RequestViewModel>>($"api/request/getrequestlist?clientid={APIClient.Client.Id}");
ViewBag.Requests = new List<RequestViewModel>();
return View();
}
[HttpPost]
public void RequestDelete(int request)
{
if (APIClient.Client == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
APIClient.PostRequest("api/request/deleterequest", new
RequestBindingModel
{
Id = request,
});
Response.Redirect("Request");
}
#endregion
#endregion
#region//работа с отчетами
[HttpGet]
[HttpGet]
public IActionResult Report()
{
if (APIClient.Client == null)

View File

@ -17,7 +17,6 @@
<a asp-action="OperationCreate">Создать операцию</a>
<a asp-action="OperationUpdate">Обновить операцию</a>
<a asp-action="OperationDelete">Удалить операцию</a>
<a asp-action="OperationTransfer">Привязать перевод</a>
</p>
<table class="table">
<thead>

View File

@ -1,4 +1,6 @@
@{
//todo выводить список только для выбранного клиента
@{
ViewData["Title"] = "OperationTransfer";
}
<div class="text-center">
@ -76,7 +78,7 @@
<div class="row">
<div class="col-4"></div>
<div class="col-8"><input type="submit" value="Связать" class="btn btn-success" /></div>
<div class="col-8"><input type="submit" value="Связать" class="btn btn-danger" /></div>
</div>
</form>
@ -91,10 +93,10 @@
url: "/Home/GetTransfer",
data: { transferId: transfer },
success: function (result) {
$('#sum').val(result.Sum);
$('#transfersender-number').val(result.senderAccountNumber);
$('#transferrecipient-number').val(result.recipientAccountNumber);
$('#transferdate').val(result.transferTime);
$('#sum').val(result.item1.Sum);
$('#transfersender-number').val(result.item1.senderAccountNumber);
$('#transferrecipient-number').val(result.item1.recipientAccountNumber);
$('#transferdate').val(result.item1.transferTime);
}
});
};
@ -107,10 +109,10 @@
url: "/Home/GetOperation",
data: { operationId: operation },
success: function (result) {
$('#sum').val(result.Sum);
$('#operationsender-number').val(result.senderCardNumber);
$('#operationrecipient-number').val(result.recipientCardNumber);
$('#operationdate').val(result.operationTime);
$('#sum').val(result.item1.Sum);
$('#operationsender-number').val(result.item1.senderCardNumber);
$('#operationrecipient-number').val(result.item1.recipientCardNumber);
$('#operationdate').val(result.item1.transferTime);
}
});
};

View File

@ -41,22 +41,22 @@
<script>
function check() {
var cards = $('#cards').val();
var request = $('#request').val();
$("#cards option:selected").removeAttr("selected");
if (cards && request) {
if (cards) {
$.ajax({
method: "GET",
url: "/Home/GetCards",
data: { requestId: request },
data: { serviceId: service },
success: function (result) {
$.map(result, function (n) {
console.log(result.item2);
$('#name').val(result.item1.serviceName);
$('#price').val(result.item1.price);
$.map(result.item2, function (n) {
console.log("#" + n);
$(`option[data-name=${n}]`).attr("selected", "selected")
});
}
});
$.ajax({
});
};
}

View File

@ -14,6 +14,5 @@ namespace BankContracts.BindingModels
public DateTime OperationTime { get; set; }
public int? SenderCardId { get; set; }
public int RecipientCardId { get; set; }
public int? TransferId { get; set; }
}
}

View File

@ -13,7 +13,6 @@ namespace BankContracts.BusinessLogicsContracts
{
List<OperationViewModel>? ReadList(OperationSearchModel? model, int? clientId);
OperationViewModel? ReadElement(OperationSearchModel model);
bool LinkOperationTransfer(int operationId, int transferId);
bool Create(OperationBindingModel model);
bool Update(OperationBindingModel model);
bool Delete(OperationBindingModel model);

View File

@ -11,7 +11,7 @@ namespace BankContracts.BusinessLogicsContracts
{
public interface IRequestLogic
{
List<RequestViewModel>? ReadList(RequestSearchModel? model, int? clientId);
List<RequestViewModel>? ReadList(RequestSearchModel? model);
RequestViewModel? ReadElement(RequestSearchModel model);
bool Create(RequestBindingModel model);
bool Update(RequestBindingModel model);

View File

@ -14,6 +14,5 @@ namespace BankContracts.SearchModels
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
public List<int>? SelectedCardIds { get; set; }
public int? RequestId { get; set; }
}
}

View File

@ -13,7 +13,6 @@ namespace BankContracts.StoragesContracts
{
List<CardViewModel> GetFullList();
List<CardViewModel> GetFilteredList(CardSearchModel model);
List<CardViewModel> GetListForRequest(CardSearchModel model);
List<ReportTransfersViewModel> GetReportTransfersList(CardSearchModel model);
List<ReportOperationsRequestsViewModel> GetReportOperationsRequestsList(CardSearchModel model);
CardViewModel? GetElement(CardSearchModel model);

View File

@ -17,7 +17,5 @@ namespace BankContracts.StoragesContracts
OperationViewModel? Insert(OperationBindingModel model);
OperationViewModel? Update(OperationBindingModel model);
OperationViewModel? Delete(OperationBindingModel model);
bool LinkOperationTransfer(int oprationId, int transferId);
}
}

View File

@ -11,7 +11,7 @@ namespace BankContracts.StoragesContracts
{
public interface IRequestStorage
{
List<RequestViewModel> GetFullList(int? clientId);
List<RequestViewModel> GetFullList();
List<RequestViewModel> GetFilteredList(RequestSearchModel model);
RequestViewModel? GetElement(RequestSearchModel model);
RequestViewModel? Insert(RequestBindingModel model);

View File

@ -30,15 +30,6 @@ namespace BankDatabaseImplement.Implements
.ToList();
}
public List<CardViewModel> GetListForRequest(CardSearchModel model)
{
using var context = new BankDatabase();
return context.CardRequests
.Include(x => x.Card).Include(x => x.Request)
.Where(x => x.RequestId==model.RequestId)
.Select(x => x.Card.GetViewModel).ToList();
}
public List<ReportTransfersViewModel> GetReportTransfersList(CardSearchModel model)
{
using var context = new BankDatabase();

View File

@ -18,7 +18,7 @@ namespace BankDatabaseImplement.Implements
{
using var context = new BankDatabase();
if (clientId != null) {
return context.Operations.Include(x => x.SenderCard).Include(x => x.RecipientCard).Include(x => x.Transfer)
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();
@ -29,7 +29,7 @@ namespace BankDatabaseImplement.Implements
public List<OperationViewModel> GetFilteredList(OperationSearchModel model)
{
using var context = new BankDatabase();
return context.Operations.Include(x => x.SenderCard).Include(x => x.RecipientCard).Include(x => x.Transfer)
return context.Operations.Include(x => x.SenderCard).Include(x => x.RecipientCard)
.Where(x => (
(!model.Id.HasValue || x.Id == model.Id) &&
(!model.DateFrom.HasValue || x.OperationTime >= model.DateFrom ) &&
@ -40,7 +40,7 @@ namespace BankDatabaseImplement.Implements
{
if (!model.Id.HasValue) return null;
using var context = new BankDatabase();
return context.Operations.Include(x => x.SenderCard).Include(x => x.RecipientCard).Include(x => x.Transfer)
return context.Operations.Include(x => x.SenderCard).Include(x => x.RecipientCard)
.FirstOrDefault(x => ((model.Id.HasValue && x.Id == model.Id)
))?.GetViewModel;
}
@ -59,7 +59,7 @@ namespace BankDatabaseImplement.Implements
public OperationViewModel? Update(OperationBindingModel model)
{
using var context = new BankDatabase();
var operation = context.Operations.Include(x => x.SenderCard).Include(x => x.RecipientCard).Include(x => x.Transfer).FirstOrDefault(x => x.Id == model.Id);
var operation = context.Operations.Include(x => x.SenderCard).Include(x => x.RecipientCard).FirstOrDefault(x => x.Id == model.Id);
if (operation == null)
{
return null;
@ -71,7 +71,7 @@ namespace BankDatabaseImplement.Implements
public OperationViewModel? Delete(OperationBindingModel model)
{
using var context = new BankDatabase();
var operation = context.Operations.Include(x => x.SenderCard).Include(x => x.RecipientCard).Include(x => x.Transfer).FirstOrDefault(rec => rec.Id == model.Id);
var operation = context.Operations.Include(x => x.SenderCard).Include(x => x.RecipientCard).FirstOrDefault(rec => rec.Id == model.Id);
if (operation != null)
{
context.Operations.Remove(operation);
@ -80,26 +80,5 @@ namespace BankDatabaseImplement.Implements
}
return null;
}
public bool LinkOperationTransfer(int operationId, int transferId)
{
using var context = new BankDatabase();
var transfer = context.Transfers.Include(x => x.SenderAccount).Include(x => x.RecipientAccount).Include(x => x.Operation).FirstOrDefault(rec => rec.Id == transferId);
if (transfer == null || operationId <= 0)
{
return false;
}
var newTransfer = new TransferBindingModel
{
Sum = transfer.Sum,
TransferTime = transfer.TransferTime,
OperationId = operationId,
SenderAccountId = transfer.SenderAccountId,
RecipientAccountId = transfer.RecipientAccountId,
};
transfer.Update(newTransfer);
context.SaveChanges();
return true;
}
}
}

View File

@ -15,23 +15,14 @@ namespace BankDatabaseImplement.Implements
{
public class RequestStorage : IRequestStorage
{
public List<RequestViewModel> GetFullList(int? clientId)
public List<RequestViewModel> GetFullList()
{
using var context = new BankDatabase();
if (clientId == null)
{
return context.Requests
.Include(x => x.Cards)
.ThenInclude(x => x.Card)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
return context.CardRequests
.Include(x => x.Card)
.Include(x => x.Request)
.Where(x => x.Card.ClientId == clientId)
.Select(x => x.Request.GetViewModel).Distinct()
return context.Requests
.Include(x => x.Cards)
.ThenInclude(x => x.Card)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public List<RequestViewModel> GetFilteredList(RequestSearchModel model)

View File

@ -47,7 +47,7 @@ namespace BankDatabaseImplement.Migrations
b.HasIndex("ManagerId");
b.ToTable("Accounts", (string)null);
b.ToTable("Accounts");
});
modelBuilder.Entity("BankDatabaseImplement.Models.AccountWithdrawal", b =>
@ -73,7 +73,7 @@ namespace BankDatabaseImplement.Migrations
b.HasIndex("WithdrawalId");
b.ToTable("AccountWithdrawals", (string)null);
b.ToTable("AccountWithdrawals");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Card", b =>
@ -109,7 +109,7 @@ namespace BankDatabaseImplement.Migrations
b.HasIndex("ClientId");
b.ToTable("Cards", (string)null);
b.ToTable("Cards");
});
modelBuilder.Entity("BankDatabaseImplement.Models.CardRequest", b =>
@ -132,7 +132,7 @@ namespace BankDatabaseImplement.Migrations
b.HasIndex("RequestId");
b.ToTable("CardRequests", (string)null);
b.ToTable("CardRequests");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Client", b =>
@ -157,7 +157,7 @@ namespace BankDatabaseImplement.Migrations
b.HasKey("Id");
b.ToTable("Clients", (string)null);
b.ToTable("Clients");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Manager", b =>
@ -182,7 +182,7 @@ namespace BankDatabaseImplement.Migrations
b.HasKey("Id");
b.ToTable("Managers", (string)null);
b.ToTable("Managers");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Operation", b =>
@ -212,7 +212,7 @@ namespace BankDatabaseImplement.Migrations
b.HasIndex("SenderCardId");
b.ToTable("Operations", (string)null);
b.ToTable("Operations");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Request", b =>
@ -234,7 +234,7 @@ namespace BankDatabaseImplement.Migrations
b.HasKey("Id");
b.ToTable("Requests", (string)null);
b.ToTable("Requests");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Transfer", b =>
@ -270,7 +270,7 @@ namespace BankDatabaseImplement.Migrations
b.HasIndex("SenderAccountId");
b.ToTable("Transfers", (string)null);
b.ToTable("Transfers");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Withdrawal", b =>
@ -293,7 +293,7 @@ namespace BankDatabaseImplement.Migrations
.IsUnique()
.HasFilter("[RequestId] IS NOT NULL");
b.ToTable("Withdrawals", (string)null);
b.ToTable("Withdrawals");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Account", b =>

View File

@ -25,7 +25,7 @@ namespace BankDatabaseImplement.Models
[Required]
public int RecipientCardId { get; set; }
public virtual Card? RecipientCard { get; private set; }
public virtual Transfer? Transfer { get; private set; } = null;
public virtual Transfer? Transfer { get; private set; }
public static Operation? Create(OperationBindingModel model)
{
@ -46,7 +46,7 @@ namespace BankDatabaseImplement.Models
Sum = model.Sum;
SenderCardId = model.SenderCardId;
RecipientCardId = model.RecipientCardId;
}
}
public OperationViewModel GetViewModel => new()
{
@ -57,7 +57,6 @@ namespace BankDatabaseImplement.Models
RecipientCardId = RecipientCardId,
SenderCardNumber = SenderCard?.Number ?? string.Empty,
RecipientCardNumber = RecipientCard?.Number ?? string.Empty,
TransferId = Transfer?.Id,
};
}
}

View File

@ -31,7 +31,7 @@ namespace BankDatabaseImplement.Models
{
if (_cardRequests == null)
{
_cardRequests = Cards.ToDictionary(card => card.CardId, card => card.Card as ICardModel);
_cardRequests = Cards.ToDictionary(recPC => recPC.CardId, recPC => recPC.Card as ICardModel);
}
return _cardRequests;
}
@ -74,11 +74,6 @@ namespace BankDatabaseImplement.Models
{ // удалили те, которых нет в модели
context.CardRequests.RemoveRange(CardRequests.Where(rec => !model.CardRequests.ContainsKey(rec.CardId)));
context.SaveChanges();
foreach (var updateCards in CardRequests)
{
model.CardRequests.Remove(updateCards.CardId);
}
context.SaveChanges();
}
var Request = context.Requests.First(x => x.Id == Id);
foreach (var request in model.CardRequests)

View File

@ -2,7 +2,6 @@
using BankContracts.BusinessLogicsContracts;
using BankContracts.SearchModels;
using BankContracts.ViewModels;
using BankDatabaseImplement.Models;
using Microsoft.AspNetCore.Mvc;
namespace BankRestApi.Controllers
@ -36,23 +35,6 @@ namespace BankRestApi.Controllers
}
}
[HttpPost]
public List<CardViewModel>? GetCards(int requestId)
{
try
{
return _logic.ReadList(new CardSearchModel
{
RequestId = requestId,
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка менеджеров");
throw;
}
}
[HttpGet]
public CardViewModel? GetCard(int cardId)
{

View File

@ -19,7 +19,7 @@ namespace BankRestApi.Controllers
_logic = Operation;
}
[HttpGet]
public List<OperationViewModel>? GetOperationList(int? clientId)
public List<OperationViewModel>? GetOperationList(int clientId)
{
try
{
@ -90,19 +90,5 @@ namespace BankRestApi.Controllers
throw;
}
}
[HttpPost]
public void LinkOperationTransfer(OperationBindingModel model)
{
try
{
_logic.LinkOperationTransfer(model.Id, (int)model.TransferId);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при связывании операции с переводом");
throw;
}
}
}
}

View File

@ -19,11 +19,11 @@ namespace BankRestApi.Controllers
_logic = Request;
}
[HttpGet]
public List<RequestViewModel>? GetRequestList(int clientId)
public List<RequestViewModel>? GetRequestList()
{
try
{
return _logic.ReadList(null, clientId);
return _logic.ReadList(null);
}
catch (Exception ex)
{