public ActionResult UpdateLocation(long LocationID) { LocationVM updateVM = new LocationVM(); ILocationInfoDO location = _LocationAccess.ViewLocationByID(LocationID); updateVM.Location = LocationMap.MapDOtoPO(location); return(View(updateVM)); }
public static LocationPO MapDOtoPO(ILocationInfoDO iFrom) { LocationPO newlocation = new LocationPO(); newlocation.LocationID = iFrom.LocationID; newlocation.LocationName = iFrom.LocationName; newlocation.Address = iFrom.Address; newlocation.Phone = iFrom.Phone; newlocation.MaxCapacity = iFrom.MaxCapacity; return(newlocation); }
public ActionResult AddLocation(LocationVM viewModel) { ActionResult oResponse = null; if (Session["UserName"] != null && (int)Session["UserLevel"] == 1) { if (ModelState.IsValid) { try { ILocationInfoDO locationform = LocationMap.MapPOtoDO(viewModel.Location); _LocationAccess.InsertLocation(locationform); } catch (Exception e) { if (e.Message.Contains("duplicate")) { viewModel.ErrorMessage = String.Format("There is already a {0} in the database.", viewModel.Location.LocationName); } else { viewModel.ErrorMessage = "We apologize but we were unable to handle your request at this time."; } } finally { //nothing to do here } if (viewModel.ErrorMessage == null) { oResponse = RedirectToAction("ViewLocations", "Location"); } else { oResponse = View(viewModel); } } else { oResponse = View(viewModel); } } else { oResponse = RedirectToAction("Login", "User"); } return(oResponse); }
public void InsertLocation(ILocationInfoDO location) { try { //create connection using (SqlConnection connectionToSQL = new SqlConnection(connectionString)) { //create a command for adding location using (SqlCommand command = new SqlCommand("ADD_LOCATION", connectionToSQL)) { try { command.CommandType = CommandType.StoredProcedure; command.CommandTimeout = 35; //SQL needs @params, pass these values as @values command.Parameters.AddWithValue("@LocationName", location.LocationName); command.Parameters.AddWithValue("@Address", location.Address); command.Parameters.AddWithValue("@Phone", location.Phone); command.Parameters.AddWithValue("@MaxCapacity", location.MaxCapacity); connectionToSQL.Open(); command.ExecuteNonQuery(); } catch (Exception e) { //write data error to file, pass to presentation layer ErrorLogging.LogError(e); throw (e); } finally { // using statement should close connection, this is just a double check connectionToSQL.Close(); connectionToSQL.Dispose(); } } } } catch (Exception e) { ErrorLogging.LogError(e); throw (e); } finally { //no connection to dispose, do nothing } }
public ActionResult UpdateLocation(LocationVM changelocation) { ActionResult oResult = null; if (ModelState.IsValid) { try { ILocationInfoDO updateLoc = LocationMap.MapPOtoDO(changelocation.Location); _LocationAccess.UpdateLocation(updateLoc); } catch (Exception e) { //what to do with exception what to write if (e.Message.Contains("duplicate")) { changelocation.ErrorMessage = "Unable to process request, duplicate record already exists"; } else { changelocation.ErrorMessage = "We apologize but we were unable to handle your request at this time."; } } finally { } if (changelocation.ErrorMessage == null) { oResult = RedirectToAction("ViewLocations", "Location"); } else { oResult = RedirectToAction("UpdateLocation", "Location"); } } else { oResult = View(changelocation); } return(oResult); }
public void UpdateLocation(ILocationInfoDO location) { try { //create connection using (SqlConnection connectionToSQL = new SqlConnection(connectionString)) //create a command using (SqlCommand command = new SqlCommand("UPDATE_LOCATION", connectionToSQL)) { try { command.CommandType = CommandType.StoredProcedure; command.CommandTimeout = 35; command.Parameters.AddWithValue("@LocationID", location.LocationID); command.Parameters.AddWithValue("@LocationName", location.LocationName); command.Parameters.AddWithValue("@Address", location.Address); command.Parameters.AddWithValue("@Phone", location.Phone); command.Parameters.AddWithValue("@MaxCapacity", location.MaxCapacity); connectionToSQL.Open(); command.ExecuteNonQuery(); } catch (Exception e) { ErrorLogging.LogError(e); throw e; } finally { } } } catch (Exception e) { throw e; } finally { //good to go } }