public int CreateDepot(Depot d) { int ret = 0; using (connect = new MySqlConnection(_connectionString)) { connect.Open(); using (MySqlTransaction transaction = connect.BeginTransaction()) { try { string query = "NewRole"; var cmd = new MySqlCommand(query, connect) { CommandType = CommandType.StoredProcedure }; cmd.Parameters.AddWithValue("DepotName", d.DepotName); cmd.Parameters.AddWithValue("FloorSpace", d.FloorSpace); cmd.Parameters.AddWithValue("NumOfVehicles", d.NumVehicles); cmd.Parameters.AddWithValue("AddressID", d.Address); cmd.Parameters.AddWithValue("DepotManager", d.ManagerID); ret = int.Parse(cmd.ExecuteScalar().ToString()); transaction.Commit(); connect.Close(); } catch (InvalidOperationException ioException) { transaction.Rollback(); connect.Close(); } } } return ret; }
// Controller for modification of a depot public ActionResult EditDepot() { // Null handling if (Session["loggedInState"] == null) { return Redirect("/403.html"); } // Checks if logged in bool state = (bool)Session["loggedInState"]; if (state == true) { // Creates a role placeholder var depot = new Depot(); // Setup role edit depot.ID = int.Parse(Request.Form["id"]); depot.ManagerID = int.Parse(Request.Form["managerID"]); depot.DepotName = Request.Form["depotName"]; depot.FloorSpace = int.Parse(Request.Form["floorSpace"]); depot.NumVehicles = int.Parse(Request.Form["numVehicles"]); // Establishes role model var depotModel = new DepotModel(); // Conduct edit depotModel.EditDepot(depot); // Passes back to the view return View(); } else { // If not logged in return Redirect("/login.html"); } }
public void EditDepot(Depot d) { using (connect = new MySqlConnection(_connectionString)) { connect.Open(); using (MySqlTransaction transaction = connect.BeginTransaction()) { try { string query = "EditRole"; var cmd = new MySqlCommand(query, connect) { CommandType = CommandType.StoredProcedure }; cmd.Parameters.AddWithValue("DepotID", d.ID); cmd.Parameters.AddWithValue("DepotName", d.DepotName); cmd.Parameters.AddWithValue("FloorSpace", d.FloorSpace); cmd.Parameters.AddWithValue("NumOfVehicles", d.NumVehicles); cmd.Parameters.AddWithValue("AddressID", d.Address); cmd.Parameters.AddWithValue("DepotManager", d.ManagerID); cmd.ExecuteNonQuery(); transaction.Commit(); connect.Close(); } catch (InvalidOperationException ioException) { transaction.Rollback(); connect.Close(); } } } }
public Depot SearchDepot(Depot d) { return SearchDepot(d.ID); }
public Depot SearchDepot(int ID) { var depot = new Depot(); using (connect = new MySqlConnection(_connectionString)) { try { string query = "GetDepot"; var cmd = new MySqlCommand(query, connect) { CommandType = CommandType.StoredProcedure }; cmd.Parameters.AddWithValue("DepotID", ID); connect.Open(); var reader = cmd.ExecuteReader(); while (reader.Read()) { try { depot.ID = (int)reader["Depot_ID"]; } catch (Exception) { } depot.DepotName = reader["Depot_Name"].ToString(); depot.FloorSpace = (double)reader["Floor_space"]; depot.NumVehicles = (int)reader["NumVehicles"]; try { depot.AddressID = (int)reader["Address_ID"]; } catch (Exception) { } depot.ManagerID = (int)reader["Depot_Manager"]; } connect.Close(); } catch (InvalidOperationException ioException) { connect.Close(); } return depot; } }
public List<Depot> ListDepots() { var depotList = new List<Depot>(); using (connect = new MySqlConnection(_connectionString)) { try { string query = "ListDepot"; var cmd = new MySqlCommand(query, connect) { CommandType = CommandType.StoredProcedure }; connect.Open(); var reader = cmd.ExecuteReader(); while (reader.Read()) { var depot = new Depot(); depot.ID = (int) reader["Depot_ID"]; depot.DepotName = reader["Depot_Name"].ToString(); depot.FloorSpace = (double)reader["Floor_space"]; depot.NumVehicles = (int)reader["NumVehicles"]; depot.AddressID = (int)reader["Address_ID"]; depot.ManagerID = (int) reader["Depot_Manager"]; depotList.Add(depot); } connect.Close(); } catch (InvalidOperationException ioException) { connect.Close(); } return depotList; } }
// GET: Depot public ActionResult Index() { // Ensures logged in if (Session["loggedInState"] == null) { return Redirect("/403.html"); } // Checks if logged in bool state = (bool)Session["loggedInState"]; if (state == true) { // Establishes depot model DepotModel depotModel = new DepotModel(); // Holds the new depot Depot newDepot = new Depot(); // Stored details for the depot newDepot.AddressID = int.Parse(Request.Form[0]); newDepot.ManagerID = int.Parse(Request.Form[1]); newDepot.DepotName = Request.Form[2]; newDepot.FloorSpace = Double.Parse(Request.Form[3]); newDepot.NumVehicles = int.Parse(Request.Form[4]); // Adds the object to the database depotModel.CreateDepot(newDepot); // Return created department to view return View(newDepot); } else { // If not logged in return Redirect("/login.html"); } }