public ActionResult EmployeeBankDetailsNew()
        {
            EmployeeBankDetailFormViewModel viewModel = new EmployeeBankDetailFormViewModel
            {
                Title = "New Bank Detail"
            };

            return(View("EmployeeBankDetailForm", viewModel));
        }
        public ActionResult EmployeeBankDetailsSave(EmployeeBankDetailFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("EmployeeBankDetailForm", viewModel));
            }

            if (viewModel.bank_id == 0)
            {
                EmployeeBankDetail bankDetail = new EmployeeBankDetail
                {
                    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,
                    employee_id      = int.Parse(Session["EmployeeId"].ToString())
                };

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

                if (bankDetailsInDb == null)
                {
                    ModelState.AddModelError("", "Bad request.");
                    return(View("EmployeeBankDetailForm", 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("EmployeeBankDetailsIndex",
                                    new { employee_id = int.Parse(Session["EmployeeId"].ToString()) }));
        }
        public ActionResult EmployeeBankDetailsEdit(int id)
        {
            EmployeeBankDetail bankDetailsInDb = _context.EmployeeBankDetails.Where(x => x.bank_id == id).FirstOrDefault();

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

            EmployeeBankDetailFormViewModel viewModel = new EmployeeBankDetailFormViewModel
            {
                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,
                employee_id      = int.Parse(Session["EmployeeId"].ToString()),
                Title            = "Edit Bank Details"
            };

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