public bool DeleteAssoc(StudentCourseAssocModel assocModel)
        {
            var deleted = false;

            try
            {
                // Step 1 - Initialize the connection and set the sproc
                var conn    = new SqlConnection(connStr);
                var command = new SqlCommand(StoredProcedures.StudentCourseAssoc_Delete, conn);
                command.CommandType = CommandType.StoredProcedure;
                conn.Open();

                // Step 2 - Set the Parameters
                command.Parameters.AddWithValue("@IdCourse", assocModel.IdCourse);
                command.Parameters.AddWithValue("@IdStudent", assocModel.IdStudent);

                // Step 3 - Execute the sproc and set deleted to true
                var sqlReader = command.ExecuteReader();
                deleted = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                deleted = false;
            }

            return(deleted);
        }
        public IStudentCourseAssocModel InsertAssoc(StudentCourseAssocModel assocModel)
        {
            var addedAssoc = new StudentCourseAssocModel();

            try
            {
                // Step 1 - Initialize the connection and set the sproc
                var conn    = new SqlConnection(connStr);
                var command = new SqlCommand(StoredProcedures.StudentCourseAssoc_Insert, conn);
                command.CommandType = CommandType.StoredProcedure;
                conn.Open();

                // Step 2 - Set the Parameters
                command.Parameters.AddWithValue("@IdCourse", assocModel.IdCourse);
                command.Parameters.AddWithValue("@IdStudent", assocModel.IdStudent);

                // Step 3 - Execute the sproc and store the new Association in an object
                var sqlReader = command.ExecuteReader();
                while (sqlReader.Read())
                {
                    addedAssoc.IdCourse  = sqlReader.GetInt32(0);
                    addedAssoc.IdStudent = sqlReader.GetInt32(1);
                }
                sqlReader.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return(addedAssoc);
        }
        public List<StudentCourseAssocModel> ListAssocs(StudentCourseAssocModel assocModel)
        {
            var assocs = new List<StudentCourseAssocModel>();

            try
            {
                // Get list of all associations
                assocs = StudentCourseAssocRepository.ListAssocs(assocModel).ConvertAll(c => (StudentCourseAssocModel)c);
            }
            catch (Exception e)
            {
                Console.Write(e.Message);
            }

            return assocs;
        }
        public bool DeleteAssoc(StudentCourseAssocModel assocModel)
        {
            var deleted = false;

            try
            {
                // Null check the parameters, then get the association
                if (assocModel.IdCourse > 0 && assocModel.IdStudent > 0)
                {
                    deleted = StudentCourseAssocRepository.DeleteAssoc(assocModel);
                }
            }
            catch (Exception e)
            {
                Console.Write(e.Message);
            }

            return deleted;
        }
        public StudentCourseAssocModel GetAssoc(StudentCourseAssocModel assocModel)
        {
            var assoc = new StudentCourseAssocModel();

            try
            {
                // Null check the parameters, then get the association
                if (assocModel.IdCourse > 0 && assocModel.IdStudent > 0)
                {
                    assoc = StudentCourseAssocRepository.GetAssoc(assocModel) as StudentCourseAssocModel;
                }
            }
            catch (Exception e)
            {
                Console.Write(e.Message);
            }

            return assoc;
        }
        public StudentCourseAssocModel InsertAssoc(StudentCourseAssocModel assocModel)
        {
            var addedAssoc = new StudentCourseAssocModel();

            try
            {
                // Null check the model, then insert the association
                if (assocModel.IdCourse > 0 && assocModel.IdStudent > 0)
                {
                    addedAssoc = StudentCourseAssocRepository.InsertAssoc(assocModel) as StudentCourseAssocModel;
                }
            }
            catch(Exception e)
            {
                Console.Write(e.Message);
            }

            return addedAssoc;
        }
        public List <IStudentCourseAssocModel> ListAssocs(StudentCourseAssocModel assocModel)
        {
            var associations = new List <IStudentCourseAssocModel>();

            try
            {
                // Step 1 - Initialize the connection and set the sproc
                var conn    = new SqlConnection(connStr);
                var command = new SqlCommand(StoredProcedures.StudentCourseAssoc_List, conn);
                command.CommandType = CommandType.StoredProcedure;
                conn.Open();

                // Step 2 - Set the Parameters

                // Null int for parameter assignment
                int?nullInt = null;

                command.Parameters.AddWithValue("@IdCourse", assocModel.IdCourse == 0 ? nullInt : assocModel.IdCourse);
                command.Parameters.AddWithValue("@IdStudent", assocModel.IdStudent == 0 ? nullInt : assocModel.IdStudent);

                // Step 3 - Execute the sproc and store the Courses in an object
                var sqlReader = command.ExecuteReader();
                while (sqlReader.Read())
                {
                    // Add each association to the list
                    associations.Add(new StudentCourseAssocModel
                    {
                        IdCourse  = sqlReader.GetInt32(0),
                        IdStudent = sqlReader.GetInt32(1)
                    });
                }
                sqlReader.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return(associations);
        }