【发布时间】: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