// GET: CustomerPayment public ActionResult Payment(int customerId = -1) { CustomerPayment customerPayment = dbContext.CustomerPayments. Where(x => x.CustomerId == customerId && x.IsActive == true).FirstOrDefault(); if (customerPayment == null) { CustomerPaymentVM customerPaymentVM = new CustomerPaymentVM(); customerPaymentVM.CustomerId = customerId; return(View(customerPaymentVM)); } else { CustomerPaymentVM customerPaymentVM = new CustomerPaymentVM(); customerPaymentVM.BalanceAmount = customerPayment.BalanceAmount; customerPaymentVM.CourseName = customerPayment.CourseName; customerPaymentVM.CustomerName = customerPayment.CustomerName; customerPaymentVM.DueDate = customerPayment.DueDate; customerPaymentVM.InvoiceValue = customerPayment.InvoiceValue; customerPaymentVM.OrderId = customerPayment.OrderId; customerPaymentVM.OtherRecievables = customerPayment.OtherRecievables; customerPaymentVM.PaidAmount = customerPayment.PaidAmount; customerPaymentVM.RecieptDate = customerPayment.RecieptDate; return(View(customerPaymentVM)); } }
public ActionResult Payment(CustomerPaymentVM customerPaymentVM) { if (customerPaymentVM.CustomerId == -1) { CustomerPayment customerPayment = new CustomerPayment(); customerPayment.BalanceAmount = customerPaymentVM.BalanceAmount; customerPayment.CourseName = customerPaymentVM.CourseName; customerPayment.CustomerName = customerPaymentVM.CustomerName; customerPayment.DueDate = customerPaymentVM.DueDate; customerPayment.InvoiceValue = customerPaymentVM.InvoiceValue; customerPayment.OrderId = customerPaymentVM.OrderId; customerPayment.OtherRecievables = customerPaymentVM.OtherRecievables; customerPayment.PaidAmount = customerPaymentVM.PaidAmount; customerPayment.RecieptDate = customerPaymentVM.RecieptDate; customerPayment.IsActive = true; if (customerPaymentVM.ReferenceDocument.ContentLength > 0) { customerPayment.ReferenceDocument = customerPaymentVM.ReferenceDocument.FileName; string fileName = customerPaymentVM.ReferenceDocument.FileName; string path = Path.Combine(Server.MapPath("~/FileUploads"), fileName); customerPaymentVM.ReferenceDocument.SaveAs(path); } dbContext.CustomerPayments.Add(customerPayment); dbContext.SaveChanges(); } else { CustomerPayment customerPayment = dbContext.CustomerPayments. Where(x => x.CustomerId == customerPaymentVM.CustomerId).FirstOrDefault(); customerPayment.BalanceAmount = customerPaymentVM.BalanceAmount; customerPayment.CourseName = customerPaymentVM.CourseName; customerPayment.CustomerName = customerPaymentVM.CustomerName; customerPayment.DueDate = customerPaymentVM.DueDate; customerPayment.InvoiceValue = customerPaymentVM.InvoiceValue; customerPayment.OrderId = customerPaymentVM.OrderId; customerPayment.OtherRecievables = customerPaymentVM.OtherRecievables; customerPayment.PaidAmount = customerPaymentVM.PaidAmount; customerPayment.RecieptDate = customerPaymentVM.RecieptDate; customerPayment.ReferenceDocument = customerPaymentVM.ReferenceDocument.FileName; dbContext.SaveChanges(); } return(RedirectToAction("CustomerPaymentList")); }