public IInstructorCourseAssocModel InsertAssoc(InstructorCourseAssocModel assocModel)
        {
            var addedAssoc = new InstructorCourseAssocModel();

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

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

                // 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.IdInstructor = sqlReader.GetInt32(1);
                }
                sqlReader.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

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

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

            return(assocs);
        }
        public InstructorCourseAssocModel GetAssoc(int courseId)
        {
            var assoc = new InstructorCourseAssocModel();

            try
            {
                // Null check the parameters, then get the association
                if (courseId > 0)
                {
                    assoc = InstructorCourseAssocRepository.GetAssoc(courseId) as InstructorCourseAssocModel;
                }
            }
            catch (Exception e)
            {
                Console.Write(e.Message);
            }

            return(assoc);
        }
        public InstructorCourseAssocModel UpdateAssoc(InstructorCourseAssocModel assocModel)
        {
            var updatedAssoc = new InstructorCourseAssocModel();

            try
            {
                // Null check the model, then update the association
                if (assocModel != null)
                {
                    updatedAssoc = InstructorCourseAssocRepository.UpdateAssoc(assocModel) as InstructorCourseAssocModel;
                }
            }
            catch (Exception e)
            {
                Console.Write(e.Message);
            }

            return(updatedAssoc);
        }
        public InstructorCourseAssocModel InsertAssoc(InstructorCourseAssocModel assocModel)
        {
            var addedAssoc = new InstructorCourseAssocModel();

            try
            {
                // Null check the model, then insert the association
                if (assocModel != null)
                {
                    addedAssoc = InstructorCourseAssocRepository.InsertAssoc(assocModel) as InstructorCourseAssocModel;
                }
            }
            catch (Exception e)
            {
                Console.Write(e.Message);
            }

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

            try
            {
                // Step 1 - Initialize the connection and set the sproc
                var conn    = new SqlConnection(connStr);
                var command = new SqlCommand(StoredProcedures.InstructorCourseAssoc_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("@IdInstructor", assocModel.IdInstructor == 0 ? nullInt : assocModel.IdInstructor);

                // 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 InstructorCourseAssocModel
                    {
                        IdCourse     = sqlReader.GetInt32(0),
                        IdInstructor = sqlReader.GetInt32(1)
                    });
                }
                sqlReader.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return(associations);
        }