From b5647466b45387e6f541395a39350cb4cb4fe080 Mon Sep 17 00:00:00 2001 From: Artyom_Yashin Date: Thu, 2 May 2024 16:00:38 +0400 Subject: [PATCH] =?UTF-8?q?=D0=95=D1=89=D0=B5=20=D0=BF=D0=BE=D1=84=D0=B8?= =?UTF-8?q?=D0=BA=D1=81=D0=B8=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Views/Home/OperationUpdate.cshtml | 4 ++-- .../BindingModels/RequestBindingModel.cs | 2 +- .../ViewModels/RequestViewModel.cs | 2 +- Bank/BankDataModels/Models/IRequestModel.cs | 2 +- .../Models/CardRequest.cs | 2 -- Bank/BankDatabaseImplement/Models/Request.cs | 19 +++++-------------- 6 files changed, 10 insertions(+), 21 deletions(-) diff --git a/Bank/BankClientApp/Views/Home/OperationUpdate.cshtml b/Bank/BankClientApp/Views/Home/OperationUpdate.cshtml index b8278fb..c99667b 100644 --- a/Bank/BankClientApp/Views/Home/OperationUpdate.cshtml +++ b/Bank/BankClientApp/Views/Home/OperationUpdate.cshtml @@ -7,9 +7,9 @@
-
Карта:
+
Операция:
- +
diff --git a/Bank/BankContracts/BindingModels/RequestBindingModel.cs b/Bank/BankContracts/BindingModels/RequestBindingModel.cs index 387eeff..654fba9 100644 --- a/Bank/BankContracts/BindingModels/RequestBindingModel.cs +++ b/Bank/BankContracts/BindingModels/RequestBindingModel.cs @@ -13,6 +13,6 @@ namespace BankContracts.BindingModels public int Sum { get; set; } public DateTime RequestTime { get; set; } public RequestStatus Status { get; set; } - public Dictionary CardRequests { get; set; } = new(); + public Dictionary CardRequests { get; set; } = new(); } } diff --git a/Bank/BankContracts/ViewModels/RequestViewModel.cs b/Bank/BankContracts/ViewModels/RequestViewModel.cs index a8e20ec..7fdf810 100644 --- a/Bank/BankContracts/ViewModels/RequestViewModel.cs +++ b/Bank/BankContracts/ViewModels/RequestViewModel.cs @@ -18,6 +18,6 @@ namespace BankContracts.ViewModels public DateTime RequestTime { get; set; } [DisplayName("Статус заявки")] public RequestStatus Status { get; set; } - public Dictionary CardRequests { get; set; } = new(); + public Dictionary CardRequests { get; set; } = new(); } } diff --git a/Bank/BankDataModels/Models/IRequestModel.cs b/Bank/BankDataModels/Models/IRequestModel.cs index 90b5372..070c34c 100644 --- a/Bank/BankDataModels/Models/IRequestModel.cs +++ b/Bank/BankDataModels/Models/IRequestModel.cs @@ -11,6 +11,6 @@ namespace BankDataModels.Models int Sum { get; set; } DateTime RequestTime { get; set; } RequestStatus Status { get; set; } - Dictionary CardRequests { get; } + Dictionary CardRequests { get; } } } diff --git a/Bank/BankDatabaseImplement/Models/CardRequest.cs b/Bank/BankDatabaseImplement/Models/CardRequest.cs index c6c3d18..119bb1b 100644 --- a/Bank/BankDatabaseImplement/Models/CardRequest.cs +++ b/Bank/BankDatabaseImplement/Models/CardRequest.cs @@ -14,8 +14,6 @@ namespace BankDatabaseImplement.Models public int CardId { get; set; } [Required] public int RequestId { get; set; } - [Required] - public int Sum { get; set; } public virtual Card Card { get; set; } = new(); public virtual Request Request { get; set; } = new(); } diff --git a/Bank/BankDatabaseImplement/Models/Request.cs b/Bank/BankDatabaseImplement/Models/Request.cs index 50689ad..0992bca 100644 --- a/Bank/BankDatabaseImplement/Models/Request.cs +++ b/Bank/BankDatabaseImplement/Models/Request.cs @@ -22,15 +22,15 @@ namespace BankDatabaseImplement.Models public RequestStatus Status { get; set; } [ForeignKey("RequestId")] public virtual List Cards { get; set; } = new(); - private Dictionary? _cardRequests { get; set; } = null; + private Dictionary? _cardRequests { get; set; } = null; [NotMapped] - public Dictionary CardRequests + public Dictionary CardRequests { get { if (_cardRequests == null) { - _cardRequests = Cards.ToDictionary(recPC => recPC.CardId, recPC => (recPC.Card as ICardModel, recPC.Sum)); + _cardRequests = Cards.ToDictionary(recPC => recPC.CardId, recPC => recPC.Card as ICardModel); } return _cardRequests; } @@ -46,9 +46,7 @@ namespace BankDatabaseImplement.Models Status = model.Status, Cards = model.CardRequests.Select(x => new CardRequest { - Card = context.Cards.First(y => y.Id == x.Key), - Sum = x.Value.Item2 - + Card = context.Cards.First(y => y.Id == x.Key) }).ToList() }; } @@ -76,12 +74,6 @@ namespace BankDatabaseImplement.Models { // удалили те, которых нет в модели context.CardRequests.RemoveRange(CardRequests.Where(rec => !model.CardRequests.ContainsKey(rec.CardId))); context.SaveChanges(); - foreach (var updateCard in CardRequests) - { - updateCard.Sum = model.CardRequests[updateCard.CardId].Item2; - model.CardRequests.Remove(updateCard.CardId); - } - context.SaveChanges(); } var Request = context.Requests.First(x => x.Id == Id); foreach (var request in model.CardRequests) @@ -89,8 +81,7 @@ namespace BankDatabaseImplement.Models context.CardRequests.Add(new CardRequest { Request = Request, - Card = context.Cards.First(x => x.Id == request.Key), - Sum = request.Value.Item2 + Card = context.Cards.First(x => x.Id == request.Key) }); context.SaveChanges(); }