/// <summary> /// Add the routes to the database /// </summary> /// <parameter name="routeInfo"></parameter> /// <returns>Returns the number of rows affected by the insert</returns> public int AddRoute(Model.Entities.AirTravel.Route routeInfo) { try { return(ExecuteStoredProcedure("InsertRoute", new SqlParameter() { ParameterName = "@fromcityID", DbType = DbType.Int32, Value = routeInfo.FromCity.CityId }, new SqlParameter() { ParameterName = "@toCityID", DbType = DbType.Int32, Value = routeInfo.ToCity.CityId }, new SqlParameter() { ParameterName = "@dis", DbType = DbType.Decimal, Value = routeInfo.DistanceInKms }, new SqlParameter() { ParameterName = "@st", DbType = DbType.Boolean, Value = routeInfo.IsActive } )); } catch (Common.ConnectToDatabaseException) { throw new RouteDAOException("Unable to add route"); } catch (Exception) { throw new RouteDAOException("Unable to add route"); } }
/// <summary> /// Update the existing routes to the database /// </summary> /// <parameter name="routeInfo"></parameter> /// <returns>Returns the number of rows affected by the update</returns> public int UpdateRoute(Model.Entities.AirTravel.Route routeInfo) { try { return(ExecuteStoredProcedure("UpdateRoutes", new SqlParameter() { ParameterName = "@ID", DbType = DbType.Int64, Value = routeInfo.ID }, new SqlParameter() { ParameterName = "@DisInKms", DbType = DbType.Decimal, Value = routeInfo.DistanceInKms }, new SqlParameter() { ParameterName = "@Status", DbType = DbType.Boolean, Value = routeInfo.IsActive } )); } catch (Common.ConnectToDatabaseException) { throw new RouteDAOException("Unable to update route"); } catch (Exception) { throw new RouteDAOException("Unable to update route"); } }
/// <summary> /// Update the existing routes to the database /// </summary> /// <parameter name="RouteInfo"></parameter> /// <returns>Status of the update</returns> public bool UpdateRoute(Model.Entities.AirTravel.Route RouteInfo) { IDbConnection conn = null; bool isUpdated = false; try { conn = this.GetConnection(); //ADO.NET Bug //STYCBG15.2 - Unable to update the route //Connection has to be opened conn.Open(); IDbCommand cmd = conn.CreateCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "UpdateRoutes"; IDataParameter p1 = cmd.CreateParameter(); p1.ParameterName = "@ID"; //ADO.NET Bug //STYCBG15.2 - Unable to update the route //ID has to be assigned p1.Value = RouteInfo.ID; cmd.Parameters.Add(p1); IDataParameter p2 = cmd.CreateParameter(); p2.ParameterName = "@DisInKms"; p2.Value = RouteInfo.DistanceInKms; cmd.Parameters.Add(p2); IDataParameter p3 = cmd.CreateParameter(); p3.ParameterName = "@Status"; p3.Value = RouteInfo.IsActive; cmd.Parameters.Add(p3); cmd.ExecuteNonQuery(); isUpdated = true; } catch (Common.ConnectToDatabaseException) { throw new RouteDAOException("Unable to update route"); } catch (Exception) { throw new RouteDAOException("Unable to update route"); } finally { if (conn != null && conn.State != ConnectionState.Closed) { conn.Close(); } } return(isUpdated); }
/// <summary> /// Add the routes to the database /// </summary> /// <parameter name="RouteInfo"></parameter> /// <returns>int</returns> public int AddRoute(Model.Entities.AirTravel.Route RouteInfo) { IDbConnection conn = null; try { conn = this.GetConnection(); conn.Open(); IDbCommand cmd = conn.CreateCommand(); //string insertSQL = @"insert into Routes(FromCityId,ToCityId,DistanceInKms,Status) values(@fromcityID,@toCityID,@dis,@st);"; cmd.CommandText = "InsertRoute"; cmd.CommandType = CommandType.StoredProcedure; IDataParameter p1 = cmd.CreateParameter(); p1.ParameterName = "@fromcityID"; p1.Value = RouteInfo.FromCity.CityId; cmd.Parameters.Add(p1); IDataParameter p2 = cmd.CreateParameter(); p2.ParameterName = "@tocityID"; p2.Value = RouteInfo.ToCity.CityId; cmd.Parameters.Add(p2); IDataParameter p3 = cmd.CreateParameter(); p3.ParameterName = "@dis"; p3.Value = RouteInfo.DistanceInKms; cmd.Parameters.Add(p3); IDataParameter p4 = cmd.CreateParameter(); p4.ParameterName = "@st"; p4.Value = RouteInfo.IsActive; cmd.Parameters.Add(p4); return(cmd.ExecuteNonQuery()); } catch (Common.ConnectToDatabaseException) { throw new RouteDAOException("Unable to add route"); } catch (Exception) { throw new RouteDAOException("Unable to add route"); } finally { conn.Close(); } }
/// <summary> /// Add the routes to the database /// </summary> /// <parameter name="routeInfo"></parameter> /// <returns>Returns the number of rows affected by the insert</returns> public int AddRoute(Model.Entities.AirTravel.Route routeInfo) { try { db = GetDatabaseConnection(); return(db.ExecuteNonQuery("InsertRoute", routeInfo.FromCity.CityId, routeInfo.ToCity.CityId, routeInfo.DistanceInKms, routeInfo.IsActive)); } catch (Common.ConnectToDatabaseException) { throw new RouteDAOException("Unable to add route"); } catch (Exception) { throw new RouteDAOException("Unable to add route"); } }
/// <summary> /// Update the existing routes to the database /// </summary> /// <parameter name="routeInfo"></parameter> /// <returns>Returns the number of rows affected by the update</returns> public int UpdateRoute(Model.Entities.AirTravel.Route routeInfo) { try { db = GetDatabaseConnection(); return(db.ExecuteNonQuery("UpdateRoutes", routeInfo.ID, routeInfo.DistanceInKms, routeInfo.IsActive)); } catch (Common.ConnectToDatabaseException) { throw new RouteDAOException("Unable to update route"); } catch (Exception) { throw new RouteDAOException("Unable to update route"); } }