Example #1
0
        public static AssignmentPerStudentPerCourse AddAssignmentPerCourse()
        {
            AssignmentPerStudentPerCourse apc = new AssignmentPerStudentPerCourse();

            FrontEnd.PrintAssignments();
            apc.AssignemntId = InputsMethods.SelectAssignmentId();
            FrontEnd.PrintCourses();
            apc.CourseId = InputsMethods.SelectCourseId();
            FrontEnd.PrintStudents();
            apc.StudentId = InputsMethods.SelectStudentId();
            return(apc);
        }
Example #2
0
        public static void InsertAssignmentPerStudentPerCourse(AssignmentPerStudentPerCourse apc)
        {
            var connectionString = Properties.Settings.Default.connectionString;

            using (SqlConnection con = new SqlConnection(connectionString))
            {
                string     query = @"INSERT INTO Assignment_Per_Course VALUES(@CourseId, @AssignmentId)INSERT INTO Student_Per_Course VALUES(@StudentId,@CourseId)";
                SqlCommand cmd   = new SqlCommand(query, con);
                //Pass values to Parameters
                cmd.Parameters.AddWithValue("@CourseId", apc.CourseId);
                cmd.Parameters.AddWithValue("@AssignmentId", apc.AssignemntId);
                cmd.Parameters.AddWithValue("@StudentId", apc.StudentId);


                try
                {
                    con.Open();
                    cmd.ExecuteNonQuery();
                    Console.WriteLine("Records Inserted Successfully");
                    Menu.RunMenu();
                }
                catch (SqlException e) when(e.Number == 2627)  //Exception this relationship already exists
                {
                    Console.WriteLine("\n Wrong\n The combination already exists try again");
                    Inserts.InsertAssignmentPerStudentPerCourse(Inserts.AddAssignmentPerCourse());
                }
                catch (SqlException e) when(e.Number == 547)  //Exception the id doesn't exist
                {
                    Console.WriteLine("\n Wrong\n The Id does not exist try again");
                    Inserts.InsertStudentPerCourse(Inserts.AddStudentPerCourse());
                }
                catch (SqlException e)
                {
                    Console.WriteLine("Error Generated. Details: " + e.ToString());
                }
                finally
                {
                    con.Close();
                    Console.ReadKey();
                }
            }
        }