public ActionResult CreatePaySched(PaymentSchedule paymentschedule, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    paymentschedule.ReceiptImage = new byte[file.ContentLength];
                    paymentschedule.ReceiptImageType = file.ContentType;
                    BinaryReader reader = new BinaryReader(file.InputStream);
                    paymentschedule.ReceiptImage = reader.ReadBytes(file.ContentLength);
                }
                paymentschedule.ScheduleID = Guid.NewGuid();
                var mycontroller = new PaymentScheduleController();
                mycontroller.ControllerContext = ControllerContext;
                decimal result = mycontroller.GetBalance(paymentschedule.UserID);
                paymentschedule.RemainingAmount = result - paymentschedule.ScheduleAmount.Value;
                db.PaymentSchedule.Add(paymentschedule);
                db.SaveChanges();
                return RedirectToAction("SearchCust");
            }

            return View(paymentschedule);
        }
        public ActionResult Edit(PaymentSchedule paymentschedule, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                if (file != null)
                {

                    paymentschedule.ReceiptImage = new byte[file.ContentLength];
                    paymentschedule.ReceiptImageType = file.ContentType;
                    BinaryReader reader = new BinaryReader(file.InputStream);
                    paymentschedule.ReceiptImage = reader.ReadBytes(file.ContentLength);
                }
                db.Entry(paymentschedule).State = EntityState.Modified;
                try
                {
                    db.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    var sb = new System.Text.StringBuilder();

                    foreach (var failure in ex.EntityValidationErrors)
                    {
                        sb.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType());
                        foreach (var error in failure.ValidationErrors)
                        {
                            sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage);
                            sb.AppendLine();
                        }
                    }

                    throw new DbEntityValidationException(
                        "Entity Validation Failed - errors follow:\n" +
                        sb.ToString(), ex
                        ); // Add the original exception as the innerException
                }
                return RedirectToAction("SearchCust");
            }
            return View(paymentschedule);
        }