public ICollection<ToDoListItem> ListTasks() { List<ToDoListItem> tasks = new List<ToDoListItem>(); using (SqlConnection cnn = new SqlConnection(ConnectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = cnn; cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = "Tasks_GetAll"; cmd.Connection.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { ToDoListItem task = new ToDoListItem() { ID = reader.GetGuid(0), Description = reader.GetString(1), Created = reader.GetDateTime(2), IsComplete = reader.GetBoolean(3) }; tasks.Add(task); } reader.Close(); } } return tasks; }
public ICollection <ToDoListItem> ListTasks() { List <ToDoListItem> tasks = new List <ToDoListItem>(); using (SqlConnection cnn = new SqlConnection(ConnectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = cnn; cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = "Tasks_GetAll"; cmd.Connection.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { ToDoListItem task = new ToDoListItem() { ID = reader.GetGuid(0), Description = reader.GetString(1), Created = reader.GetDateTime(2), IsComplete = reader.GetBoolean(3) }; tasks.Add(task); } reader.Close(); } } return(tasks); }
public void AddTask(string description) { ToDoListItem newTask = new ToDoListItem() { ID = Guid.NewGuid(), Description = description, Created = DateTime.Now, IsComplete = false }; Tasks.Add(newTask); }