public ActionResult BankDetailsDelete(int id)
        {
            PartnerBankDetail bankDetailsInDb = _context.PartnerBankDetails.Where(x => x.bank_id == id).FirstOrDefault();

            if (bankDetailsInDb == null)
            {
                ModelState.AddModelError("", "Not found.");
                return(View("BankDetailForm", bankDetailsInDb));
            }

            _context.PartnerBankDetails.Remove(bankDetailsInDb);
            _context.SaveChanges();

            return(RedirectToAction("BankDetailsIndex",
                                    new { partner_id = int.Parse(Session["PartnerId"].ToString()) }));
        }
        public ActionResult BankDetailsSave(PartnerBankDetailFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("BankDetailForm", viewModel));
            }

            if (viewModel.bank_id == 0)
            {
                PartnerBankDetail bankDetail = new PartnerBankDetail
                {
                    account_no       = viewModel.account_no,
                    bank_holder_name = viewModel.bank_holder_name,
                    bank_name        = viewModel.bank_name,
                    ifsc_code        = viewModel.ifsc_code,
                    branch_name      = viewModel.branch_name,
                    partner_id       = int.Parse(Session["PartnerId"].ToString())
                };

                _context.PartnerBankDetails.Add(bankDetail);
                _context.SaveChanges();
            }
            else
            {
                PartnerBankDetail bankDetailsInDb = _context.PartnerBankDetails.Where(x => x.bank_id == viewModel.bank_id).FirstOrDefault();

                if (bankDetailsInDb == null)
                {
                    ModelState.AddModelError("", "Bad request.");
                    return(View("BankDetailForm", viewModel));
                }

                bankDetailsInDb.account_no       = viewModel.account_no;
                bankDetailsInDb.bank_holder_name = viewModel.bank_holder_name;
                bankDetailsInDb.bank_name        = viewModel.bank_name;
                bankDetailsInDb.ifsc_code        = viewModel.ifsc_code;
                bankDetailsInDb.branch_name      = viewModel.branch_name;

                _context.Entry(bankDetailsInDb).State = System.Data.Entity.EntityState.Modified;
                _context.SaveChanges();
            }

            return(RedirectToAction("BankDetailsIndex",
                                    new { partner_id = int.Parse(Session["PartnerId"].ToString()) }));
        }
        public ActionResult BankDetailsEdit(int id)
        {
            PartnerBankDetail bankDetailsInDb = _context.PartnerBankDetails.Where(x => x.bank_id == id).FirstOrDefault();

            if (bankDetailsInDb == null)
            {
                ModelState.AddModelError("", "Not found.");
                return(View("BankDetailForm", bankDetailsInDb));
            }

            PartnerBankDetailFormViewModel viewModel = new PartnerBankDetailFormViewModel
            {
                bank_id          = bankDetailsInDb.bank_id,
                account_no       = bankDetailsInDb.account_no,
                bank_holder_name = bankDetailsInDb.bank_holder_name,
                bank_name        = bankDetailsInDb.bank_name,
                ifsc_code        = bankDetailsInDb.ifsc_code,
                branch_name      = bankDetailsInDb.branch_name,
                partner_id       = int.Parse(Session["PartnerId"].ToString()),
                Title            = "Bank Details Edit"
            };

            return(View("BankDetailForm", viewModel));
        }