// GET: BankAndBranches/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BankAndBranch bankAndBranch = db.BankAndBranches.Find(id);

            if (bankAndBranch == null)
            {
                return(HttpNotFound());
            }
            return(View(bankAndBranch));
        }
        public ActionResult Create([Bind(Include = "Id,BankName,BranchName")] BankAndBranch bankAndBranch)
        {
            if (ModelState.IsValid)
            {
                using (var context = new ApplicationDbContext())
                {
                    using (var dbContextTransaction = context.Database.BeginTransaction())
                    {
                        try
                        {
                            context.BankAndBranches.Add(bankAndBranch);
                            // context.SaveChanges();
                            // Saving Longing Credential
                            LoginInfoModel logingInfoModel = new LoginInfoModel();
                            PopulateLoginInfoCredencial populateLoginInfoCredencial = new PopulateLoginInfoCredencial(logingInfoModel);
                            logingInfoModel = populateLoginInfoCredencial.getLoginInfoCredencial();
                            if (!populateLoginInfoCredencial.ValidateIPv4(logingInfoModel.LoginIp))
                            {
                                return(RedirectToAction("Login", "Account"));
                            }
                            logingInfoModel.UsedModel    = "BankAndBranches";
                            logingInfoModel.TypeOfAction = TypeOfAction.Insert;
                            logingInfoModel.SysDate      = DateTime.Now;
                            logingInfoModel.Data         = Newtonsoft.Json.JsonConvert.SerializeObject(bankAndBranch);
                            context.LoginInfoModels.Add(logingInfoModel);
                            context.SaveChanges();
                            // Saving Longing Credential
                            dbContextTransaction.Commit();
                            return(RedirectToAction("Index"));
                        }
                        catch (Exception ex)
                        {
                            dbContextTransaction.Rollback();
                        }
                    }
                }
            }

            return(View(bankAndBranch));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            using (var context = new ApplicationDbContext())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        BankAndBranch bankAndBranch = context.BankAndBranches.Find(id);


                        // Saving Longing Credential
                        LoginInfoModel logingInfoModel = new LoginInfoModel();
                        PopulateLoginInfoCredencial populateLoginInfoCredencial = new PopulateLoginInfoCredencial(logingInfoModel);
                        logingInfoModel = populateLoginInfoCredencial.getLoginInfoCredencial();
                        if (!populateLoginInfoCredencial.ValidateIPv4(logingInfoModel.LoginIp))
                        {
                            return(RedirectToAction("Login", "Account"));
                        }
                        logingInfoModel.UsedModel    = "BankAndBranches";
                        logingInfoModel.TypeOfAction = TypeOfAction.Delete;
                        logingInfoModel.Data         = Newtonsoft.Json.JsonConvert.SerializeObject(bankAndBranch);
                        logingInfoModel.SysDate      = DateTime.Now;
                        context.LoginInfoModels.Add(logingInfoModel);
                        context.BankAndBranches.Remove(bankAndBranch);
                        // Saving Longing Credential
                        context.SaveChanges();
                        dbContextTransaction.Commit();
                        return(RedirectToAction("Index"));
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                    }
                }
            }

            return(RedirectToAction("Index"));
        }