public void Post(CareVisitTask careVisitTask) { using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Pets"].ConnectionString)) { connection.Open(); try { using (SqlCommand command = new SqlCommand("Update dbo.CareVisitTask Set IsComplete = @IsComplete, CompletedByPersonID = @CompletedByPersonID, DateCompleted = GetUTCDate() Where ID = @ID;", connection)) { command.Parameters.AddWithValue("ID", careVisitTask.ID); command.Parameters.AddWithValue("IsComplete", careVisitTask.IsComplete); command.Parameters.AddWithValue("CompletedByPersonID", careVisitTask.CompletedByPersonID); command.ExecuteNonQuery(); } } catch (Exception ex) { throw new Exception(ex.Message); } } }
internal static List <CareVisitTask> GetList(int careVisitID) { List <CareVisitTask> tasks = new List <CareVisitTask>(); CareVisitTask task; using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Pets"].ConnectionString)) { try { connection.Open(); using (SqlCommand command = new SqlCommand("Select * From dbo.vwCareVisitTask Where CareVisitID = @careVisitID Order By PetName;", connection)) { command.Parameters.AddWithValue("careVisitID", careVisitID); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { task = new CareVisitTask(); task.ID = ((int)reader["ID"]); task.Pet = new Pet((int)reader["PetID"], (string)reader["PetName"]); task.Description = ((string)reader["Description"]); task.IsComplete = ((bool)reader["IsComplete"]); task.CompletedByPersonID = reader["CompletedByPersonID"] == DBNull.Value ? (int?)null : (int?)reader["CompletedByPersonID"]; task.DateCompleted = reader["DateCompleted"] == DBNull.Value ? (DateTime?)null : (DateTime?)reader["DateCompleted"]; tasks.Add(task); } } } return(tasks); } catch (Exception ex) { throw new Exception(ex.Message); } } }