在我的MVC 3項目中,我有一張發票和付款表。我有一個頁面,用戶可以確認付款是針對發票進行的。發票狀態必須根據已支付的金額或支付的累計金額更改爲「已付」或「部分已付」。累計金額是我遇到問題的地方。我的代碼只會工作,如果用戶第一次支付全額金額,則將其狀態更改爲「已確認」 - 不累計金額。將付款確認發票爲付費MVC 3
我是C#的新手,不太清楚如何做到這一點。數額來自單選按鈕,這工作正常。因此,這裏是我的控制器代碼:以上
public ActionResult Confirm(int id, long InvoiceAmount, string PaymentType)
{
Invoices invoices = db.Invoice.Find(id);
//now validate that if the logged in user is authorized to select and confirm this invoice or not.
var clientPayment = new ClientPayments();
if (InvoiceAmount + clientPayment.PaymentAmount != invoices.InvoiceAmount)
{
invoices.InvoiceStatus = "Partly Paid";
}
else
{
invoices.InvoiceStatus = "Confirmed";
}
db.Entry(invoices).State = EntityState.Modified;
clientPayment.InvoiceNumberID = id;
clientPayment.PaymentAmount = InvoiceAmount;
clientPayment.PaymentType = PaymentType;
clientPayment.PaymentDate = DateTime.Now;
// Set clientPayment properties
db.ClientPayments.Add(clientPayment);
db.SaveChanges();
INVOICEAMOUNT從單選按鈕選擇的付款金額(也許我應該改變它的東西更有意義),clientPayment.PaymentAmount應在列付款表和invoices.InvoiceAmount是發票表中的金額。
謝謝