Еще пофиксил
This commit is contained in:
parent
26558beae3
commit
b5647466b4
@ -7,9 +7,9 @@
|
||||
</div>
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Карта:</div>
|
||||
<div class="col-4">Операция:</div>
|
||||
<div class="col-8">
|
||||
<select id="card" name="card" class="form-control" asp-items="@(new SelectList(@ViewBag.Operations, "Id", "Number"))"></select>
|
||||
<select id="operation" name="operation" class="form-control" asp-items="@(new SelectList(@ViewBag.Operations, "Id", "Id"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
|
@ -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, int)> CardRequests { get; set; } = new();
|
||||
public Dictionary<int, ICardModel> 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, int)> CardRequests { get; set; } = new();
|
||||
public Dictionary<int, ICardModel> 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, int)> CardRequests { get; }
|
||||
Dictionary<int, ICardModel> CardRequests { get; }
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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, int)>? _cardRequests { get; set; } = null;
|
||||
private Dictionary<int, ICardModel>? _cardRequests { get; set; } = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (ICardModel, int)> CardRequests
|
||||
public Dictionary<int, ICardModel> 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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user