/// <summary> /// Add a payment to the Billing invoice. /// </summary> /// <returns>Json object used to update the billing cshtml view through javascript.</returns> public JsonResult AddPayment() { try { PaymentRepository paymentRepo = new PaymentRepository(); Payment payment = new Payment(); payment.IsActive = true; payment.CashAmount = decimal.Parse(Request.Form["Amount"]); payment.Invoice = new InvoiceRepository().Get(int.Parse(Request.Form["InvoiceId"])); BillingViewModel billing = new BillingViewModel(payment.Invoice.Id); payment.PaymentDate = DateTime.Now; if (payment.CashAmount > billing.Total - billing.PaymentTotal) { return Json(new { error = true, message = "Please do not pay more than is owed." }); } paymentRepo.Add(payment); return Json(new { error = false, Date = payment.PaymentDate.ToString(), Amount = payment.CashAmount.ToString("c"), Balance = String.Format("{0:c}", billing.Total - billing.PaymentTotal - payment.CashAmount), Payments = String.Format("{0:c}", billing.PaymentTotal + payment.CashAmount) }); } catch(Exception e) { return Json(new { error = true, message = e.Message }); } }
/// <summary> /// Adds an Payment to the Repository. /// </summary> /// <param name="entity">The Payment to add to the Repository.</param> public void Add(Payment entity) { //is this correct? I copied the ProductRepository. Session.Save(entity); }
/// <summary> /// Removes a Payment from the Repository. /// </summary> /// <param name="entity">The Payment to remove from the Repository.</param> public void Remove(Payment entity) { //is this correct? I copied the ProductRepository again. Session.Delete(entity); }