2011-09-06 85 views
0

在我的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是发票表中的金额。

谢谢

回答

0

您没有累积付款。您的代码表示

clientPayment.PaymentAmount = InvoiceAmount

所以,每一付款被更新,以在单一行动支付的金额的时间。它应该是

clientPayment.PaymentAmount += invoiceAmount(看小+号)

BTW,题外话,这是一种广泛使用的约定用于参数名称(更低)骆驼的情况下,像long invoiceAmount, ...