我正在编写一种方法来为每个成员保存发票,发票和成员是具有不同存储库的不同实体。我怎样才能利用这两种情境?我应该处理成员存储库吗?
public RedirectToRouteResult CalculateAllInvoices()
{
var amount = _memberRepository.GetAll().Count();
for (int i = 1; i<amount; i++)
{
Member m = _memberRepository.GetSingle(i);
CalculateInvoice(m);
}
return RedirectToAction("Overview");
}
private void CalculateInvoice(Member member)
{
double invoicePrice = 0.0;
ICollection<Sport> sports = member.Sports;
foreach(Sport s in sports){
invoicePrice =+ s.Price;
}
Invoice i = new Invoice { SendDate = DateTime.Now, Status = false, Member = member, Price = invoicePrice };
_memberRepository.Dispose();
_InvoiceRepository.Add(i);
_InvoiceRepository.Save();
}