コード例 #1
0
ファイル: Create.cs プロジェクト: Orjanen/Db_Kvarteret
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var course = new Domain.Course
                {
                    Id          = request.Id,
                    navn        = request.navn,
                    beskrivelse = request.beskrivelse,
                };

                _context.Courses.Add(course);

                var user = await _context.Users.SingleOrDefaultAsync(x => x.UserName ==
                                                                     _userAccessor.GetCurrentUsername());

                /*var admin = new UserCourse
                 * {
                 *  AppUser = user,
                 *  Course = course,
                 *  CourseAdmin = true,
                 *  DateJoined = DateTime.Now
                 * };
                 *
                 * _context.UserCourses.Add(admin);*/

                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }

                throw new Exception("Problem saving changes");
            }
コード例 #2
0
        public static void GenerateData()
        {
            //Set up some test data
            using (ISession session = _factory.OpenSession())
            {
                //Save venues
                Venue venue = new Venue { Name="Main Venue"};
                session.Save(venue);

                //Save courses
                Course course1 = new Course {CourseNumber = 1, Venue = venue};
                Course course2 = new Course { CourseNumber = 2, Venue = venue };
                session.Save(course1);
                session.Save(course2);

                //Save students
                Student student1 = new Student {Name="Student 1"};
                student1.Courses.Add(course1);
                student1.Courses.Add(course2);
                session.Save(student1);

                Student student2 = new Student { Name = "Student 2" };
                student2.Courses.Add(course1);
                session.Save(student2);

                session.Flush();
            }
        }
コード例 #3
0
 /// <summary>
 ///     Add a Course to this department
 /// </summary>
 /// <param name="course">The Course to be added</param>
 public void addCourse(Course course)
 {
     courseList.addAtTail(course);
 }
コード例 #4
0
 /// <summary>
 ///     Check if a Course is in this Deptartment
 /// </summary>
 /// <param name="course">The Course to search for</param>
 /// <returns>True or False</returns>
 public bool isInDept(Course course)
 {
     return courseList.searchList(course);
 }
コード例 #5
0
        public ActionResult CreateCourse(UserInformation user, Course course)
        {
            if (user != null)
            {
                if (user.IsStudent)
                {
                    return View("Students limitations");
                }
                else
                {
                    try
                    {
                        if (ModelState.IsValid)
                        {
                            _repository.SaveCourse(course);
                            return View("CreationSucceed");
                        }
                        else
                        {
                            SelectList categories = new SelectList(_repository.CourseCategories, "ID", "Name");
                            SelectList courseTypes = new SelectList(_repository.CourseTypes, "ID", "TypeName");
                            ViewBag.Categories = categories;
                            ViewBag.CourseTypes = courseTypes;
                            return View("CreateCourse", course);
                        }
                    }
                    catch (Exception e)
                    {
                        return View("Error");
                    }

                }
            }
            else return View("UnauthorizedAccess");
        }
コード例 #6
0
        /// <summary>
        ///     Load LinkedList of Course 
        /// </summary>
        private void loadCourseList()
        {
            Course tempCourse ;

            string sqlStatment = "SELECT * FROM Course"; 
            try
            {
                OpenConection();
                cmd = new OleDbCommand(sqlStatment, conn);
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    if (reader["Deleted"].ToString().Equals("False"))
                    {
                        tempCourse = new Course(reader["ID"].ToString(), 
                            reader["Code"].ToString(),
                            reader["CourseName"].ToString(), 
                            Convert.ToInt32(reader["NumOfStudents"]),
                            reader["DeptID"].ToString()
                            );
                        courseList.addAtTail(tempCourse);
                    }
                    
                }
                CloseConnection();
            }
            catch 
            {
                // MessageBox.Show("Failed to get data from source");
            }
        }
コード例 #7
0
 /// <summary>
 /// update a course in the database
 /// </summary>
 /// <param name="course">the updated course</param>
 public void updateCourse(Course course)
 {
     string sql;
     sql = "UPDATE Course";
     sql += "Code=" + course.courseCode + ",";
     sql += "Course_Name='" + course.name + "', ";
     sql += "NumOfStudents=" + course.numOfStudents + ", ";
     sql += "DeptId='" + course.deptID + "', ";
     sql += "WHERE ID LIKE " + course.ID;
     excuteNonQuery(sql);
 }
コード例 #8
0
        /// <summary>
        ///     Loads a LinkedList of Module from a Course
        /// </summary>
        /// <param name="course">The Course the Modules are in</param>
        /// <returns>A LinkedList of Modules</returns>
        public LinkedList LoadModuleList(Course course)
        {
            LinkedList moduleList = new LinkedList();
            Module tempModule;
            string sqlStatment = "SELECT * FROM Course WHERE CourseCode LIKE "+ course.getCourseCode();
            try
            {
                OpenConection();
                cmd = new OleDbCommand(sqlStatment, conn);
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {

                    if (reader["Deleted"].ToString().Equals("False"))
                    {
                        tempModule = new Module();
                        tempModule.setId(reader["ID"].ToString());
                        tempModule.setName(reader["Module_Name"].ToString());
                        tempModule.setPractical(Convert.ToBoolean(reader["Pratcial"]));
                        tempModule.setHoursPerWeek(Convert.ToInt32(reader["HoursPerWeek"]));
                        tempModule.setRoomtype(reader["RoomType"].ToString());
                        tempModule.setMaxConsecHours(Convert.ToInt32(reader["MaxConsecHours"]));
                        tempModule.setDoubleSlots(Convert.ToBoolean(reader["DoubleSlots"]));
                        moduleList.addAtTail(tempModule);
                    }
                }
                CloseConnection();
            }
            catch
            {

            }
            return moduleList;
        }
コード例 #9
0
        /// <summary>
        ///     Load LinkedList of Course for a Department
        /// </summary>
        /// <param name="dept">The Department the Courses are in</param>
        /// <returns>A LinkedList of Course</returns>
        public LinkedList loadCourseList(Department dept)
        {
            LinkedList courses = new LinkedList();
            Course tempCourse ;

            string sqlStatment = "SELECT ID, Code, CourseName, NumOfStudents FROM Course WHERE DeptId Like  " +  dept.getID();
            try
            {
                OpenConection();
                cmd = new OleDbCommand(sqlStatment, conn);
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    if (reader["Deleted"].ToString().Equals("False"))
                    {
                        tempCourse = new Course();
                        tempCourse.setID(reader["ID"].ToString());
                        tempCourse.setCourseCode(reader["Code"].ToString());
                        tempCourse.setName(reader["CourseName"].ToString());
                        tempCourse.setNumOfStudents(Convert.ToInt32(reader["NumOfStudents"]));
                        tempCourse.setModuleList(LoadModuleList(tempCourse));
                        courses.addAtTail(tempCourse);
                    }

                }
                CloseConnection();
            }
            catch
            {
                // MessageBox.Show("Failed to get data from source");
            }

            return courses ;
        }
コード例 #10
0
        protected void AddCourseButtonClick(object sender, EventArgs e)
        {
            string name = courseName.Text;
            string startTime = courseStartTimeDropDownList.Items[courseStartTimeDropDownList.SelectedIndex].Text;
            string endTime = courseEndTimeDropDownList.Items[courseEndTimeDropDownList.SelectedIndex].Text;
            string weekTime = courseWeekTimeDropDownList.Items[courseWeekTimeDropDownList.SelectedIndex].Text;
            string maxStudentNum = CourseMaxStudentNum.Text;
            //取得课程一天上的节课string dayTime = "1节2节";
            //IList<string> courseDayTimeCheckBoxList = new List<string>();
            string courseDayTimeList="";
            foreach (ListItem it in courseDayTimeCheckBoxList.Items)
            {
                if (it.Selected)
                {
                    courseDayTimeList=courseDayTimeList+it.Text+" ";
                }
            }

            string location = courseLocationTextBox.Text;
            //string info = "nixisdkjksdfjkdsdkjsdkdffjdskfj";
            bool openCloseFlag = true;
            string selectableRequired =seltctableRequiredDropDownList.Items[seltctableRequiredDropDownList.SelectedIndex].Text;
            bool selectable=false;
            bool required=true;
            if (selectableRequired == "必修")
            {
                selectable = false;
                required = true;
            }
            else if (selectableRequired =="专业选修") {
                selectable = true;
                required = false;
            }
            int teacherID=-1;
            if (null != Session["userID"])
            {
                teacherID =Convert.ToInt32( Session["userID"].ToString());
            }
            string studyYear = courseStudyYearDropDownList.Items[courseStudyYearDropDownList.SelectedIndex].Text;
            string term = courseTermDropDownList.Items[courseTermDropDownList.SelectedIndex].Text;
            //取得课程面向的专业
            IList<string> courseFaceClassName=new List<string>();
            foreach(ListItem it in classCourseListCheckBoxList.Items)
            {
                if(it.Selected){
                    courseFaceClassName.Add(it.Text);
                }
            }
            //取得课程面向的年级string[] courseFaceGrade = { "2009", "2010" };
            IList<string> courseFaceGrade = new List<string>();
            foreach (ListItem it in gradeListCheckBoxList.Items)
            {
                if (it.Selected)
                {
                    courseFaceGrade.Add(it.Text);
                }
            }
            Course newCourse = new Course
            {
                courseName = name,
                courseStartTime = startTime,
                courseEndTime = endTime,
                courseLocation = location,
                courseDayTime=courseDayTimeList,
                courseOpenCloseFlag = openCloseFlag,
                courseTeacherID = teacherID,
                courseWeekTime = weekTime,
                courseRequired = required,
                courseSelectable = selectable,
                courseStudyYear = studyYear,
                courseTerm = term,
                courseMaxStudentNum=maxStudentNum
            };
            TeacherController teacherController=null;
            if (Session["teacherController"] != null)
            {
                teacherController = (TeacherController)Session["teacherController"];
            }
            int courseID = teacherController.AddCourse(newCourse);
            if (courseID != 0)
            {
                for (int i = 0; i < courseFaceClassName.Count; i++)
                {
                    for (int j = 0; j < courseFaceGrade.Count; j++)
                    {
                        ClassGradeCourse classGradeCourse = new ClassGradeCourse
                        {
                            ID = new ClassGradeCourseID
                            {
                                classGradeCourseClassName = courseFaceClassName[i],
                                classGradeCourseGrade = courseFaceGrade[j],
                                classGradeCourseCourseId = courseID
                            }

                        };
                        bool success = teacherController.AddClassGradeCourse(classGradeCourse);

                    }

                }
            }
        }