Добавил поле суммы
This commit is contained in:
parent
c3baf8cfb9
commit
6c79ce1119
@ -13,6 +13,6 @@ namespace BankContracts.BindingModels
|
||||
public int Sum { get; set; }
|
||||
public DateTime RequestTime { get; set; }
|
||||
public RequestStatus Status { get; set; }
|
||||
public Dictionary<int, ICardModel> CardRequests { get; set; } = new();
|
||||
public Dictionary<int, (ICardModel, int)> CardRequests { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,6 @@ namespace BankContracts.ViewModels
|
||||
public DateTime RequestTime { get; set; }
|
||||
[DisplayName("Статус заявки")]
|
||||
public RequestStatus Status { get; set; }
|
||||
public Dictionary<int, ICardModel> CardRequests { get; set; } = new();
|
||||
public Dictionary<int, (ICardModel, int)> CardRequests { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,6 @@ namespace BankDataModels.Models
|
||||
int Sum { get; set; }
|
||||
DateTime RequestTime { get; set; }
|
||||
RequestStatus Status { get; set; }
|
||||
Dictionary<int, ICardModel> CardRequests { get; }
|
||||
Dictionary<int, (ICardModel, int)> CardRequests { get; }
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -22,15 +22,15 @@ namespace BankDatabaseImplement.Models
|
||||
public RequestStatus Status { get; set; }
|
||||
[ForeignKey("RequestId")]
|
||||
public virtual List<CardRequest> Cards { get; set; } = new();
|
||||
private Dictionary<int, ICardModel>? _cardRequests { get; set; } = null;
|
||||
private Dictionary<int, (ICardModel, int)>? _cardRequests { get; set; } = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, ICardModel> CardRequests
|
||||
public Dictionary<int, (ICardModel, int)> 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)
|
||||
|
Loading…
Reference in New Issue
Block a user