public ActionResult CreateUpdateLoanReturn(ReturnLoanModel returnLoanModel)
        {
            if (!ModelState.IsValid)
            {
                return(ShowErrorMessage(GetModelErrors(ModelState)));
            }

            var returnLoan = new ReturnLoan();

            if (returnLoanModel.Id > 0)
            {
                returnLoan = FarmManagementEntities.ReturnLoans.Single(x => x.Id == returnLoanModel.Id);
            }

            returnLoan.LoanId            = returnLoanModel.LoanId;
            returnLoan.InstallmentAmount = returnLoanModel.InstallmentAmount;
            returnLoan.AccountId         = returnLoanModel.AccountId;
            returnLoan.UserId            = returnLoanModel.UserId;
            returnLoan.PaidDate          = returnLoanModel.PaidDate;

            if (returnLoanModel.Id == 0)
            {
                returnLoan.InsertDate = DateTime.Now;
                FarmManagementEntities.ReturnLoans.Add(returnLoan);
            }

            FarmManagementEntities.SaveChanges();

            var message = string.Format(Constant.SuccessMessage, returnLoanModel.Id > 0 ? "updated" : "added");

            return(ShowSuccessMessage(message));
        }
        public ActionResult CreateUpdateLoanReturn(Int32 id)
        {
            var returnLoanModel = new ReturnLoanModel();

            returnLoanModel.PaidDate = DateTime.Now;

            if (id > 0)
            {
                var returnLoan = FarmManagementEntities.ReturnLoans.Single(x => x.Id == id);
                returnLoanModel = returnLoan.ToType <ReturnLoan, ReturnLoanModel>();
            }

            return(PartialView("LoanReturnPartial", returnLoanModel));
        }