public NumberBLL FindNumber(int id) { var r = that.DataContext.Numbers.SP_ReadSpecificNumber(id); if (r == null) { return(null); } DataAccessLayer.NumberDAL wrongtype = that.DataContext.Numbers.SP_ReadSpecificNumber(id); // could do something like mapper.BLLFromDAL(wrongType); // instead I am using Construtor mapping return(new NumberBLL(wrongtype)); }
//get all items in the Numbers table #region access functions for the numbers table public List <NumberDAL> GetAllNumbers() { //Ensure connected opens the connection to the database if it is not already opended EnsureConnected(); //create an empty list to return List <NumberDAL> rv = new List <NumberDAL>(); //create a sql command object using the existing and open connection. we know it is open //because of ensureconnection(); SqlCommand localcommand = MyConnection.CreateCommand(); //configure the command object. we are sending literal sql to execute, so use text as the type // and select * from numbers since we want all numbers localcommand.CommandType = System.Data.CommandType.Text; localcommand.CommandText = "Select * from Numbers"; //start the query SqlDataReader reader = localcommand.ExecuteReader(); //reader.read positions us to the first record returned by the sql query //and it returns false when there are no more records, and true when the record is postioned int IDPosition = 0; int NamePosition = 0; int DSPosition = 0; int FSPosition = 0; bool first = true; while (reader.Read()) { if (first) { first = false; IDPosition = reader.GetOrdinal("ID"); NamePosition = reader.GetOrdinal("Name"); DSPosition = reader.GetOrdinal("Doublestuff"); FSPosition = reader.GetOrdinal("Floatstuff"); } NumberDAL r = new NumberDAL(); r.ID = reader.GetInt32(IDPosition);// this involves boxing, unboxing and garbage generation r.Name = (string)reader[NamePosition]; //r.Doublstuff = (double)reader[DSPosition]; r.Doublstuff = reader.GetDouble(DSPosition); r.Floatstuff = reader.GetFloat(FSPosition); //r.Floatstuff = (float)reader[FSPosition]; rv.Add(r); } reader.Close(); return(rv); }
//update an existing nmber from the numbers table by using new values public void UpdateNumber(NumberDAL newValues) { UpdateNumber(newValues.ID, newValues.Name, newValues.Doublstuff, newValues.Floatstuff); }
//create a new number in the numbers table public int CreateNumber(NumberDAL newValues) { return(CreateNumber(newValues.Name, newValues.Doublstuff, newValues.Floatstuff)); }
public void DeleteNumberID(NumberDAL recordToDelete) { DeleteNumberByID(recordToDelete.ID); }