C# 累计付款以确认发票为已付款MVC 3

C# 累计付款以确认发票为已付款MVC 3,c#,asp.net-mvc-3,C#,Asp.net Mvc 3,在我的MVC3项目中,我有一个发票和付款表。我有一个页面,用户可以确认已根据发票付款。发票状态必须更改为“已付”或“部分已付”,具体取决于已付金额或累计已付金额。累积的金额是我遇到问题的地方。我的代码只会在用户第一次支付全部金额时起作用并将状态更改为“已确认”-它不会累计金额 我是C#的新手,不太清楚如何做到这一点。这些金额来自单选按钮,可以正常工作。下面是我的控制器中的代码: public ActionResult Confirm(int id, long InvoiceAmount, str

在我的MVC3项目中,我有一个发票和付款表。我有一个页面,用户可以确认已根据发票付款。发票状态必须更改为“已付”或“部分已付”,具体取决于已付金额或累计已付金额。累积的金额是我遇到问题的地方。我的代码只会在用户第一次支付全部金额时起作用并将状态更改为“已确认”-它不会累计金额

我是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应该是付款表中的列,InvoicesAmount是发票表中的金额


谢谢

您没有累计付款。你的密码是

clientPayment.PaymentAmount=InvoiceAmount

因此,每次付款都会更新为单个操作中支付的金额。应该是

clientPayment.PaymentAmount+=invoiceAmount
(注意小+符号)

顺便说一句,在主题之外,广泛使用的惯例是对参数名称使用(小写)驼峰大小写,如
long invoiceAmount,