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)