【问题标题】:Add Up Payments to Confirm Invoice as Paid MVC 3添加付款以确认发票为已付款 MVC 3
【发布时间】:2011-09-07 01:54:59
【问题描述】:

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

谢谢

【问题讨论】:

    标签: c# asp.net-mvc-3


    【解决方案1】:

    您没有累积付款。你的代码说

    clientPayment.PaymentAmount = InvoiceAmount

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

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

    顺便说一句,题外话,使用(小写)驼峰式大小写作为参数名称是一种广泛使用的约定,例如long invoiceAmount,...

    【讨论】:

      猜你喜欢
      • 2021-03-24
      • 2015-01-19
      • 2023-03-13
      • 1970-01-01
      • 2011-12-24
      • 1970-01-01
      • 2021-11-02
      • 2011-02-22
      • 1970-01-01
      相关资源
      最近更新 更多