コード例 #1
0
        public List <EnrolledStudent> GetEnrollmentsFor(DateTime from, DateTime to)
        {
            List <EnrolledStudent> returnMe = new List <EnrolledStudent>();

            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                using (SqlCommand sqlCommand = new SqlCommand())
                {
                    sqlCommand.Connection  = connection;
                    sqlCommand.CommandType = CommandType.Text;
                    sqlCommand.CommandText = sql + " WHERE ((StudentStatus.dOutDate = @NULLDATE) OR (StudentStatus.dOutDate>@STARTTIME)) AND (StudentStatus.dInDate<=@ENDTIME)";
                    sqlCommand.Parameters.AddWithValue("NULLDATE", new DateTime(1900, 1, 1, 0, 0, 0));
                    sqlCommand.Parameters.AddWithValue("STARTTIME", from);
                    sqlCommand.Parameters.AddWithValue("ENDTIME", to);
                    sqlCommand.Connection.Open();
                    SqlDataReader dataReader = sqlCommand.ExecuteReader();
                    if (dataReader.HasRows)
                    {
                        while (dataReader.Read())
                        {
                            EnrolledStudent s = dataReaderToEnrolledStudent(dataReader);
                            if (s != null)
                            {
                                returnMe.Add(s);
                            }
                        }
                    }
                    sqlCommand.Connection.Close();
                }
            }

            return(returnMe);
        }
コード例 #2
0
        public async Task EnrollStudentToCourseAsync(int studentId, int courseId)
        {
            var user = await this.context.Users.Include(us => us.EnrolledStudents).FirstOrDefaultAsync(us => us.Id == studentId);

            var course = await this.context.Courses.FirstOrDefaultAsync(co => co.CourseId == courseId);

            if (course == null)
            {
                throw new CourseDoesntExistsException("Unfortunately we are not offering such a course at the moment");
            }
            else if (user.EnrolledStudents.Any(es => es.CourseId == course.CourseId))
            {
                throw new EntityAlreadyExistsException($"You are already enrolled for the course {course.Name}.");
            }
            else
            {
                var enrolled = new EnrolledStudent
                {
                    StudentId = user.Id,
                    CourseId  = course.CourseId
                };
                user.EnrolledStudents.Add(enrolled);
                await context.SaveChangesAsync();
            }
        }
コード例 #3
0
        public void EnrollStudent(string username, string coursename)
        {
            Validations.ValidateLength(Validations.MIN_USERNAME, Validations.MAX_USERNAME, username, $"The username can't be less than {Validations.MIN_USERNAME} and greater than {Validations.MAX_USERNAME}");
            Validations.ValidateLength(Validations.MIN_COURSENAME, Validations.MAX_COURSENAME, coursename, $"The course name can't be less than {Validations.MIN_COURSENAME} and greater than {Validations.MAX_COURSENAME}");
            Validations.VerifyUserName(username);

            var user   = this.data.Users.All().Include(us => us.EnrolledStudents).FirstOrDefault(us => us.UserName == username);
            var course = this.data.Courses.All().FirstOrDefault(co => co.Name == coursename);

            if (course == null)
            {
                throw new CourseDoesntExistsException("Unfortunately we are not offering such a course at the moment");
            }
            else if (user.EnrolledStudents.Any(es => es.CourseId == course.CourseId))
            {
                throw new CourseAlreadyEnrolledException($"You are already enrolled for the course {course.Name}.");
            }
            else
            {
                var enrolled = new EnrolledStudent
                {
                    StudentId = user.Id,
                    CourseId  = course.CourseId
                };
                user.EnrolledStudents.Add(enrolled);
                this.data.SaveChanges();
            }
        }
コード例 #4
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            String          StudentID    = tbxStudentID.Text.ToString();
            String          CourseCode   = lbCourseAdded.Items.ToString();
            EnrolledStudent newEnrolment = new EnrolledStudent(StudentID, CourseCode, "Processing");

            newEnrolment.SaveData();
        }
コード例 #5
0
        public ActionResult DeleteStudent(int id)
        {
            EnrolledStudent enrolledStudent = db.EnrolledStudents.Find(id);

            db.EnrolledStudents.Remove(enrolledStudent);
            db.SaveChanges();

            var enroment = db.Enrolments.Where(u => u.Id == enrolledStudent.TutorialId).FirstOrDefault();

            enroment.SrudentCount = db.EnrolledStudents.Where(u => u.TutorialId == enroment.Id).Count();
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #6
0
        public ActionResult EnrolledStudents(CourseViewModel m)
        {
            try
            {
                DB41Entities     db = new DB41Entities();
                StudentViewModel s  = new StudentViewModel();
                EnrolledStudent  n  = new EnrolledStudent();
                var Id = db.Courses
                         .Where(x => x.Title == m.Title)
                         .Select(x => x.CourseID)
                         .FirstOrDefault();
                n.CourseID   = Id;
                n.StartDate  = m.Start_date;
                n.Duration   = m.Course_duration;
                n.Department = m.Department;
                n.Fee        = m.Fee;
                var Ide = db.Instructors
                          .Where(x => x.Name == m.Instructor)
                          .Select(x => x.InstructorID)
                          .FirstOrDefault();

                n.InstructorID = Ide;
                string userid = User.Identity.GetUserId();
                int    g      = Convert.ToInt32(userid);
                var    person = db.Students.Where(y => y.StudentID == g).First();
                n.StudentName = person.Name;
                n.CNIC        = person.CNIC;
                n.Address     = s.Address;
                n.Email       = s.Email;
                n.StudentID   = person.StudentID;
                db.EnrolledStudents.Add(n);
                db.SaveChanges();



                return(View("Index"));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
コード例 #7
0
        public ActionResult Enroll(int tutorialId)
        {
            //var currenttudent = db.EnrolledStudents.Where(u => u.StuName == User.Identity.Name);
            //if(currenttudent.Any())
            //{
            //    var preTutorialId = currenttudent.FirstOrDefault().TutorialId;
            //    var preTutorial = db.Enrolments.Find(preTutorialId);


            //    db.EnrolledStudents.Remove(currenttudent.FirstOrDefault());
            //    db.SaveChanges();
            //    preTutorial.SrudentCount = db.EnrolledStudents.Where(u => u.Id == preTutorialId).Count();
            //    db.SaveChanges();
            //}

            string status = string.Empty;

            EnrolledStudent enrollStudent = new EnrolledStudent();
            var             enrolment     = db.Enrolments.Find(tutorialId);

            enrollStudent.TutorialId   = tutorialId;
            enrollStudent.StuName      = User.Identity.Name;
            enrollStudent.DateEnrolled = DateTime.Now;
            //enrolment.SrudentCount = enrolment.SrudentCount + 1;

            var savedStudent = db.EnrolledStudents.Where(u => u.StuName == User.Identity.Name).FirstOrDefault();

            if (savedStudent != null && savedStudent.Id > 0)
            {
                if (savedStudent.TutorialId == tutorialId)
                {
                    status = "You already enrolled";
                    return(RedirectToAction("Index", new { @status = status }));
                }

                db.EnrolledStudents.Remove(savedStudent);

                db.SaveChanges();

                //PreEnrolments.SrudentCount = enrolments.
                //var PreEnrolments = db.Enrolments.Find(PreTutorialId);

                //PreEnrolments.SrudentCount = PreEnrolments.SrudentCount - 1;

                var preTutorial = db.Enrolments.Where(e => e.Id == savedStudent.TutorialId).FirstOrDefault();

                var preCount = db.EnrolledStudents.Where(p => p.TutorialId == preTutorial.Id).Count();

                preTutorial.SrudentCount = preCount;

                db.Entry(preTutorial).State = EntityState.Modified;

                db.SaveChanges();
            }



            db.EnrolledStudents.Add(enrollStudent);
            db.SaveChanges();

            var count = db.EnrolledStudents.Where(p => p.TutorialId == tutorialId).Count();

            var enrolledStudentsCount = db.EnrolledStudents.Where(p => p.TutorialId == tutorialId).Count();

            enrolment = db.Enrolments.Find(tutorialId);
            enrolment.SrudentCount = count;
            db.SaveChanges();



            PreTutorialId = tutorialId;

            status = "Congratulations! You enrolled successfully!";

            return(RedirectToAction("Index", new { @status = status }));
        }
コード例 #8
0
        public ActionResult Course(String CourseId)
        {
            CourseDetail CourseDes = new CourseDetail();
            DataTable    dtc       = DataAccess.daobj("select Top(1) * from Courses where Course_Id = " + CourseId + " and Teacher_Id = '" + ((User)Session["CurrentUser"]).Id.ToString() + "'");
            DataTable    dte       = DataAccess.daobj("select * from Exam  where Course_Id = " + CourseId);
            DataTable    dts       = DataAccess.daobj("select * from Enrollement as En Join Student as St on  En.Student_Id = St.id where Course_Id = " + CourseId + " and St.Blocked = 0");

            if (dtc.Rows.Count > 0)
            {
                CourseDes.Course = new Course
                {
                    Course_Id       = Int32.Parse(dtc.Rows[0]["Course_Id"].ToString()),
                    Name            = dtc.Rows[0]["Course_name"].ToString(),
                    Date            = dtc.Rows[0]["Date_Created"].ToString(),
                    Status          = dtc.Rows[0]["Status"].ToString(),
                    Enroll_id       = dtc.Rows[0]["Enroll_Id"].ToString(),
                    Enroll_Password = dtc.Rows[0]["Enroll_Password"].ToString()
                };

                if (dte.Rows.Count > 0)
                {
                    Exam[] Exams = new Exam[dte.Rows.Count];
                    for (int i = 0; i < dte.Rows.Count; i++)
                    {
                        Exams[i] = new Exam
                        {
                            Exam_Id     = Int32.Parse(dte.Rows[i]["Exam_Id"].ToString()),
                            Exam_Name   = dte.Rows[i]["Exam_Name"].ToString(),
                            Exam_Date   = DateTime.Parse(dte.Rows[i]["Exam_Date"].ToString()),
                            Start_Time  = DateTime.Parse(dte.Rows[i]["Start_Time"].ToString()),
                            End_Time    = DateTime.Parse(dte.Rows[i]["End_Time"].ToString()),
                            Total_Marks = Int32.Parse(dte.Rows[i]["Total_Marks"].ToString()),
                            Duration    = DateTime.Parse(dte.Rows[i]["End_Time"].ToString()).Subtract(DateTime.Parse(dte.Rows[i]["Start_Time"].ToString()))
                        };
                    }
                    CourseDes.Course.exam = Exams;
                }

                if (dts.Rows.Count > 0)
                {
                    EnrolledStudent[] Students = new EnrolledStudent[dts.Rows.Count];
                    for (int i = 0; i < dts.Rows.Count; i++)
                    {
                        Students[i] = new EnrolledStudent
                        {
                            Id               = dts.Rows[i]["Student_Id"].ToString(),
                            Fullname         = dts.Rows[i]["full_name"].ToString(),
                            Username         = dts.Rows[i]["username"].ToString(),
                            Gender           = dts.Rows[i]["Gender"].ToString(),
                            Emailaddress     = dts.Rows[i]["Email"].ToString(),
                            ImageLocation    = dts.Rows[i]["image"].ToString(),
                            Status           = dts.Rows[i]["Status"].ToString(),
                            Enrollement_Date = DateTime.Parse(dts.Rows[i]["Enrollement_Date"].ToString()),
                            Course_Id        = Int32.Parse(CourseId)
                        };
                    }
                    CourseDes.Students = Students;
                }
                TempData["Cid"] = CourseId;
            }
            else
            {
                return(RedirectToAction("Dashboard", "Teacher"));
            }
            return(View(CourseDes));
        }