From 6c79ce111970c7b4f81b3987c27e025d2aeb37f7 Mon Sep 17 00:00:00 2001 From: Artyom_Yashin Date: Sun, 28 Apr 2024 22:41:22 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D0=B5=20=D1=81=D1=83=D0=BC=D0=BC=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/RequestBindingModel.cs | 2 +- .../BankContracts/ViewModels/RequestViewModel.cs | 2 +- Bank/BankDataModels/Models/IRequestModel.cs | 2 +- Bank/BankDatabaseImplement/Models/CardRequest.cs | 2 ++ Bank/BankDatabaseImplement/Models/Request.cs | 16 ++++++++++++---- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Bank/BankContracts/BindingModels/RequestBindingModel.cs b/Bank/BankContracts/BindingModels/RequestBindingModel.cs index 654fba9..387eeff 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 7fdf810..a8e20ec 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 070c34c..90b5372 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 119bb1b..c6c3d18 100644 --- a/Bank/BankDatabaseImplement/Models/CardRequest.cs +++ b/Bank/BankDatabaseImplement/Models/CardRequest.cs @@ -14,6 +14,8 @@ 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 fadc8e9..1e971ca 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); + _cardRequests = Cards.ToDictionary(recPC => recPC.CardId, recPC => (recPC.Card as ICardModel, recPC.Sum)); } return _cardRequests; } @@ -46,7 +46,9 @@ namespace BankDatabaseImplement.Models Status = model.Status, Cards = model.CardRequests.Select(x => new CardRequest { - Card = context.Cards.First(y => y.Id == x.Key) + Card = context.Cards.First(y => y.Id == x.Key), + Sum = x.Value.Item2 + }).ToList() }; } @@ -74,6 +76,12 @@ 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)