private const string Config = "ConnectionString";
public bool Insert(Destination destination)
{
Database db = DatabaseFactory.CreateDatabase(Config);
DbCommand dbCommand = db.GetStoredProcCommand("uspSaveDestination");
db.AddInParameter(dbCommand, "DestinationID", DbType.Int64, destination.DestinationID);
db.AddInParameter(dbCommand, "DestinationName", DbType.String, destination.DestinationName);
db.AddInParameter(dbCommand, "Description", DbType.String, destination.Description);
return (db.ExecuteNonQuery(dbCommand) == 1);
}
public bool Update(Destination destination)
{
Database db = DatabaseFactory.CreateDatabase(Config);
DbCommand dbCommand = db.GetStoredProcCommand("uspSaveDestination");
db.AddInParameter(dbCommand, "DestinationID", DbType.Int64, destination.DestinationID);
db.AddInParameter(dbCommand, "DestinationName", DbType.String, destination.DestinationName);
db.AddInParameter(dbCommand, "Description", DbType.String, destination.Description);
return (db.ExecuteNonQuery(dbCommand) == 1);
}
public bool Delete(long DestinationID)
{
Database db = DatabaseFactory.CreateDatabase(Config);
DbCommand dbCommand = db.GetStoredProcCommand("uspDeleteDestination");
db.AddInParameter(dbCommand, "DestinationID", DbType.Int64, DestinationID);
return (db.ExecuteNonQuery(dbCommand) == 1);
}
public IList<Destination> GetAll()
{
Database db = DatabaseFactory.CreateDatabase(Config);
DbCommand dbCommand = db.GetStoredProcCommand("uspGetAllDestination");
List<Destination> list = new List<Destination>();
using (IDataReader dataReader = db.ExecuteReader(dbCommand))
{
while (dataReader.Read())
{
Destination obj = new Destination();
if (dataReader["DestinationID"] != DBNull.Value) { obj.DestinationID = (Int64)dataReader["DestinationID"]; }
if (dataReader["DestinationName"] != DBNull.Value) { obj.DestinationName = (String)dataReader["DestinationName"]; }
if (dataReader["Description"] != DBNull.Value) { obj.Description = (String)dataReader["Description"]; }
list.Add(obj);
}
}
return list;
}
public Destination GetByID(long DestinationID)
{
Database db = DatabaseFactory.CreateDatabase(Config);
DbCommand dbCommand = db.GetStoredProcCommand("uspGetDestinationByID");
db.AddInParameter(dbCommand, "DestinationID", DbType.Int64, DestinationID);
Destination obj = new Destination();
using (IDataReader dataReader = db.ExecuteReader(dbCommand))
{
while (dataReader.Read())
{
if (dataReader["DestinationID"] != DBNull.Value) { obj.DestinationID = (Int64)dataReader["DestinationID"]; }
if (dataReader["DestinationName"] != DBNull.Value) { obj.DestinationName = (String)dataReader["DestinationName"]; }
if (dataReader["Description"] != DBNull.Value) { obj.Description = (String)dataReader["Description"]; }
}
}
return obj;
}
No comments:
Post a Comment