Exemplo n.º 1
0
        public ActionResult NewPayment(Payment model)
        {
            try
            {
                Bill bill = dbContext.Bills.Find(model.BillId);

                if (bill == null)
                {
                    return HttpNotFound();
                }

                if (ModelState.IsValid)
                {
                    model.Amount = Util.Round(model.Amount);
                    bill.Status = (int)BillStatus.Working;
                    dbContext.Entry(bill).State = EntityState.Modified;

                    var paymentMethod = dbContext.PaymentMethods.Find(model.PaymentMethodId);

                    if (paymentMethod == null)
                    {
                        return HttpNotFound();
                    }

                    foreach (PaymentMethodCaptureField captureField in paymentMethod.PaymentMethodCaptureFields)
                    {
                        if (HttpContext.Request.Params["CaptureFields[" + captureField.Name + "]"] != null)
                        {
                            PaymentPaymentMethodCaptureField paymentPaymentMethodCaptureField = new PaymentPaymentMethodCaptureField();
                            paymentPaymentMethodCaptureField.PaymentMethodCaptureFieldId = captureField.PaymentMethodCaptureFieldId;
                            paymentPaymentMethodCaptureField.Value = HttpContext.Request.Params["CaptureFields[" + captureField.Name + "]"];

                            model.PaymentPaymentMethodCaptureFields.Add(paymentPaymentMethodCaptureField);
                        }
                    }

                    dbContext.Payments.Add(model);

                    dbContext.SaveChanges();

                    return RedirectToAction("NewPayment", new { billId = model.BillId });
                }
                else
                {
                    var paymentMethods = dbContext.PaymentMethods;

                    ViewBag.paymentMethods = paymentMethods;

                    return View(model);
                }
            }
            catch (Exception ex)
            {
                Util.HandleException(ex.GetBaseException());
                return RedirectToAction("Error", "Default", null);
            }
        }
Exemplo n.º 2
0
        public ActionResult NewPayment(int billId)
        {
            try
            {
                Bill bill = dbContext.Bills.Find(billId);

                if (bill == null)
                {
                    return HttpNotFound();
                }

                Payment payment = new Payment();

                payment.BillId = bill.BillId;

                var paymentMethods = dbContext.PaymentMethods;

                ViewBag.paymentMethods = paymentMethods;
                ViewBag.bill = bill;

                return View(payment);
            }
            catch (Exception ex)
            {
                Util.HandleException(ex.GetBaseException());
                return RedirectToAction("Error", "Default", null);
            }
        }