public PapaDogNote GetById(int id) { using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "GetPapaDogNoteById"; cmd.Parameters.AddWithValue("@PapaDogNoteId", id); conn.Open(); using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { PapaDogNote current = new PapaDogNote(); current.PapaDogNoteId = (int)dr["PapaDogNoteId"]; current.PapaDogId = (int)dr["PapaDogId"]; current.Note = dr["Note"].ToString(); current.NoteTitle = dr["NoteTitle"].ToString(); current.DateCreated = (DateTime)dr["DateCreated"]; return(current); } } } return(null); }
public IEnumerable <PapaDogNote> GetRecent() { using (SqlConnection conn = new SqlConnection()) { List <PapaDogNote> notes = new List <PapaDogNote>(); conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "GetRecentPapaDogNotes"; conn.Open(); using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { PapaDogNote current = new PapaDogNote(); current.PapaDogNoteId = (int)dr["PapaDogNoteId"]; current.PapaDogId = (int)dr["PapaDogId"]; current.Note = dr["Note"].ToString(); current.NoteTitle = dr["NoteTitle"].ToString(); current.DateCreated = (DateTime)dr["DateCreated"]; notes.Add(current); } } return(notes); } }
public int Update(PapaDogNote note) { using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "UpdatePapaDogNote"; cmd.Parameters.AddWithValue("@PapaDogNoteId", note.PapaDogNoteId); cmd.Parameters.AddWithValue("@Note", note.Note); cmd.Parameters.AddWithValue("@NoteTitle", note.NoteTitle); conn.Open(); cmd.ExecuteNonQuery(); } return(note.PapaDogNoteId); }
public int Create(PapaDogNote note) { using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "CreatePapaDogNote"; cmd.Parameters.AddWithValue("@Note", note.Note); cmd.Parameters.AddWithValue("@NoteTitle", note.NoteTitle); cmd.Parameters.AddWithValue("@PapaDogId", note.PapaDogId); cmd.Parameters.Add(new SqlParameter("@Id", SqlDbType.Int)); cmd.Parameters["@Id"].Direction = ParameterDirection.Output; conn.Open(); cmd.ExecuteScalar(); return(System.Convert.ToInt32(cmd.Parameters["@Id"].Value)); } }