我有發票表和我的數據庫ClientPayments表。我有確認付款已經發生的代碼,並將其註冊到選定的發票(用戶在視圖中選擇發票)。一旦總付款金額等於發票金額,我試圖將發票的狀態更改爲「已確認」。對於一次發票可以有多次付款,並且如果付款金額小於發票金額,則狀態更改爲「部分付款」。這是從下面的控制我的代碼:加起來的金額從數據庫MVC 3
public ActionResult Confirm(int id, long InvoiceAmount, string PaymentType, float? InvoiceCustomAmount)
{
var invoice = db.Invoice.Find(id);
//now validate that if the logged in user is authorized to select and confirm this invoice or not.
ClientPayments clientPayment = db.ClientPayments.FirstOrDefault(cp => cp.InvoiceNumberID == id);
clientPayment = new ClientPayments();
clientPayment.InvoiceNumberID = id;
var TotalPayments = (clientPayment.PaymentAmount + InvoiceAmount);
if (InvoiceAmount == 115)
{
clientPayment.PaymentAmount = (long)InvoiceCustomAmount;
}
else
{
clientPayment.PaymentAmount = InvoiceAmount;
}
clientPayment.PaymentType = PaymentType;
clientPayment.PaymentDate = DateTime.Now;
db.ClientPayments.Add(clientPayment);
if (TotalPayments != invoice.InvoiceAmount)
{
invoice.InvoiceStatus = "Partly Paid";
}
else
{
invoice.InvoiceStatus = "Confirmed";
}
// You don´t need this, since "invoice" was retrieved earlier in the method the database context
// knows that changes have been made to this object when you call "SaveChanges".
// db.Entry(invoices).State = EntityState.Modified;
db.SaveChanges();
return View();
}
我遇到的問題是,TotalPayments不給我的總付款金額 - 它不添加了那些已經被添加到數據庫中的條目。
感謝
ClientPayment「全額支付」計劃** S **是一個單一的支付對平衡這個金額是多少?你不是說有超過一筆付款,你是檢索一個單一的記錄。 – Bas
我想將ClientPayments表中所有付款的所有金額相加,那麼如何檢索所有記錄? – Amy