public ActionResult transfer(int id) { CreateCustomerAccounts2porDbData objDB = new CreateCustomerAccounts2porDbData(); DataSet ds = objDB.AccountSearch(id, "ByAccountID"); transfer_amount PD = new transfer_amount(); PD.source_account_id = Convert.ToInt32(ds.Tables[0].Rows[0]["AccountID"].ToString()); return(View(PD)); }
/// <summary> /// Sql operation to transfer certain amount from existing source account to target account. /// </summary> /// <param name="balancelist"></param> /// <param name="ta"></param> /// <returns></returns> public int transfer_amount(List <int> balancelist, transfer_amount ta) { try { DateTime date = DateTime.Now; int firstaccountupdate = balancelist.ElementAt(2); int secondaccountupdate = balancelist.ElementAt(3); string str = "data source=.;" + "database=Binoy;" + "Integrated Security=true"; SqlConnection con = new SqlConnection(str); con.Open(); SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "sp_updatebalance_s2por"; cmd.Connection = con; cmd.Parameters.AddWithValue("@amount1", firstaccountupdate); cmd.Parameters.AddWithValue("@amount2", secondaccountupdate); cmd.Parameters.AddWithValue("@id1", ta.source_account_id); cmd.Parameters.AddWithValue("@id2", ta.target_account_id); cmd.Parameters.AddWithValue("@date", date); cmd.Parameters.AddWithValue("@balance", ta.Transfer_amount); cmd.Parameters.AddWithValue("@count", 0); int rowaffect = cmd.ExecuteNonQuery(); con.Close(); if (rowaffect > 0) { return(1); } else { return(2); } } catch (Exception p) { return(0); } }
public ActionResult transfer(transfer_amount tu) { if (ModelState.IsValid) // Check the model state for any validation errors { List <int> balist = new List <int>(); CreateCustomerAccounts2porDbData cu = new CreateCustomerAccounts2porDbData(); if (tu.source_account_id != tu.target_account_id) { int bal1 = cu.viewbalance(tu.source_account_id); int bal2 = cu.viewbalance(tu.target_account_id); if (bal1 < 0 || bal2 < 0) { return(RedirectToAction("Exeption")); } balist.Add(bal1); balist.Add(bal2); if (tu.Transfer_amount > 0) { if (bal1 >= tu.Transfer_amount) { int a = bal1; int b = bal2; int c = tu.Transfer_amount; a = a - c; b = b + c; balist.Add(a); balist.Add(b); int m = cu.transfer_amount(balist, tu); int firstaccountupdate = balist.ElementAt(2); int secondaccountupdate = balist.ElementAt(3); if (m != 0) { if (m == 1) { ViewBag.acc1 = tu.source_account_id; ViewBag.acc2 = tu.target_account_id; ViewBag.balbefupdateacc1 = bal1; ViewBag.balbefupdateacc2 = bal2; ViewBag.balaftupdateacc1 = firstaccountupdate; ViewBag.balaftupdateacc2 = secondaccountupdate; ViewBag.amount = tu.Transfer_amount; if (Request.HttpMethod == "POST") { TempData["AlertMessage"] = "Amount INR " + tu.Transfer_amount + " has been transferred succesfully."; } return(View("aftertransfer")); } else if (m == 2) { TempData["AlertMessage"] = "Please enter existing target account ID."; } } else if (m == 0) { return(RedirectToAction("Exception")); } } else { if (Request.HttpMethod == "POST") { string sp = "Amount should be less than or equal to " + bal1 + " Rs."; TempData["AlertMessage"] = sp; } return(View()); } } else { TempData["AlertMessage"] = "Please enter some valid amount to transfer."; } return(View()); } else { TempData["AlertMessage"] = "Target account ID can not be same as source account ID."; } return(View()); } else { return(View()); } }