protected void showEmployees()
        {
            for (int i = employeeTable.Rows.Count - 1; i > 0; i--)
            {
                employeeTable.Rows.RemoveAt(i);
            }
            using (StudentRecordEntities1 entityContext = new StudentRecordEntities1())
            {
                var employees = entityContext.Employees.ToList <Employee>();
                foreach (Employee employee in employees)
                {
                    TableRow  employeeRow = new TableRow();
                    TableCell nameCell    = new TableCell();
                    TableCell userCell    = new TableCell();
                    TableCell roleCell    = new TableCell();

                    nameCell.Text = employee.Name;
                    userCell.Text = employee.UserName;

                    string role = string.Empty;
                    foreach (Role r in employee.Roles)
                    {
                        role += r.Role1 + ", ";
                    }
                    roleCell.Text = role;

                    employeeRow.Cells.Add(nameCell);
                    employeeRow.Cells.Add(userCell);
                    employeeRow.Cells.Add(roleCell);

                    employeeTable.Rows.Add(employeeRow);
                }
            }
        }
Ejemplo n.º 2
0
        protected void ActionHandler(string action)
        {
            string courseId  = Request.Params["course"] as String;
            string studentId = Request.Params["id"] as String;

            using (StudentRecordEntities1 entityContext = new StudentRecordEntities1())
            {
                Course course = (from c in entityContext.Courses
                                 where c.Code == courseId
                                 select c).FirstOrDefault <Course>();

                if (action == "edit")
                {
                    AcademicRecord record = (from c in course.AcademicRecords
                                             where c.StudentId == studentId
                                             select c).FirstOrDefault <AcademicRecord>();

                    CourseList.SelectedValue = course.Code + " " + course.Title;
                    txtStudentName.Text      = record.Student.Name;
                    txtStudentNum.Text       = record.Student.Id;
                    txtStudentName.ReadOnly  = true;
                    txtStudentNum.ReadOnly   = true;
                    CourseList.Enabled       = false;
                }
                else if (action == "delete")
                {
                    AcademicRecord record = (from c in course.AcademicRecords
                                             where c.StudentId == studentId
                                             select c).FirstOrDefault <AcademicRecord>();
                    course.AcademicRecords.Remove(record);
                    entityContext.SaveChanges();
                    Response.Redirect("AddStudent.aspx");
                }
            }
        }
Ejemplo n.º 3
0
 protected void CourseInformation(string action, string id)
 {
     using (StudentRecordEntities1 entityContext = new StudentRecordEntities1())
     {
         Course course = (from c in entityContext.Courses
                          where c.Code == id
                          select c).FirstOrDefault <Course>();
         if (course != null)
         {
             if (action == "delete")
             {
                 for (int i = course.AcademicRecords.Count() - 1; i >= 0; i--)
                 {
                     var ar = course.AcademicRecords.ElementAt <AcademicRecord>(i);
                     course.AcademicRecords.Remove(ar);
                 }
                 entityContext.Courses.Remove(course);
                 entityContext.SaveChanges();
                 Response.Redirect("AddCourse.aspx");
             }
             else if (action == "edit")
             {
                 txtCourseNumber.Text     = course.Code;
                 txtCourseNumber.ReadOnly = true;
             }
         }
     }
 }
Ejemplo n.º 4
0
        protected void ShowCourseInfo()
        {
            for (int i = courseTable.Rows.Count - 1; i > 0; i--)
            {
                courseTable.Rows.RemoveAt(i);
            }
            using (StudentRecordEntities1 entityContext = new StudentRecordEntities1())
            {
                List <Course> courses = entityContext.Courses.ToList <Course>();
                if (courses != null)
                {
                    foreach (Course course in courses)
                    {
                        TableRow  CourseRow    = new TableRow();
                        TableCell CourseNumber = new TableCell();
                        TableCell CourseName   = new TableCell();
                        TableCell Cell         = new TableCell();

                        CourseNumber.Text = course.Code;
                        CourseName.Text   = course.Title;
                        Cell.Text         = "<a href='AddCourse.aspx?action=edit&id=" + course.Code + "'>Edit</a>"
                                            + " | <a class='deleteCourse' href='AddCourse.aspx?action=delete&id=" + course.Code + "'>Delete</a>";
                        CourseRow.Cells.Add(CourseNumber);
                        CourseRow.Cells.Add(CourseName);
                        CourseRow.Cells.Add(Cell);
                        courseTable.Rows.Add(CourseRow);
                    }
                }
            }
        }
Ejemplo n.º 5
0
    private void loadTable()
    {
        if (Session["sort"] != null && Session["sort"].ToString() == Request.Params["sort"])
        {
            if (Session["order"] != null && Session["order"].ToString() == "ascending")
            {
                this.order       = "descending";
                Session["order"] = this.order;
            }
            else
            {
                this.order       = "ascending";
                Session["order"] = this.order;
            }
        }
        else
        {
            this.order       = "ascending";
            Session["order"] = this.order;
        }

        Session["sort"] = Request.Params["sort"];

        using (var context = new StudentRecordEntities1())
        {
            List <Course> list = context.Courses.ToList();

            IComparer <Course> comparer;
            switch (Request.Params["sort"])
            {
            case "number":
                comparer = new SortByNumber(this.order);
                list.Sort(comparer);
                break;

            case "name":
                comparer = new SortByName(this.order);
                list.Sort(comparer);
                break;
            }

            foreach (Course course in list)
            {
                TableRow row = new TableRow();

                TableCell cell = new TableCell();
                cell.Text = course.Code;
                row.Cells.Add(cell);

                cell      = new TableCell();
                cell.Text = course.Title;
                row.Cells.Add(cell);

                tblCourses.Rows.Add(row);
            }
        }
    }
Ejemplo n.º 6
0
 protected List <Course> GetCourses()
 {
     using (StudentRecordEntities1 entityContext = new StudentRecordEntities1())
     {
         List <Course> courses = entityContext.Courses.ToList <Course>();
         if (courses != null)
         {
             return(courses);
         }
     }
     return(null);
 }
Ejemplo n.º 7
0
        protected void btn_SubmitCourse_Click(object sender, EventArgs e)
        {
            string courseCode = txtCourseNumber.Text.ToUpper().Trim();
            string action     = Request.Params["action"];

            using (StudentRecordEntities1 entity = new StudentRecordEntities1())
            {
                if (action == "edit")
                {
                    string id     = Request.Params["id"];
                    Course course = (from c in entity.Courses
                                     where c.Code == id
                                     select c).FirstOrDefault <Course>();
                    if (course != null)
                    {
                        course.Title = txtCourseName.Text;
                        entity.Entry(course).State = System.Data.Entity.EntityState.Modified;
                        entity.SaveChanges();
                        Response.Redirect("AddCourse.aspx");
                    }
                }
                else
                {
                    Course course = (from c in entity.Courses
                                     where c.Code == courseCode
                                     select c).FirstOrDefault <Course>();
                    if (course != null)
                    {
                        if (course.Code == courseCode)
                        {
                            err.Text    = "Course with that code already exists!";
                            err.Visible = true;
                        }
                    }
                    else
                    {
                        Course newCourse = new Course();
                        newCourse.Code  = courseCode;
                        newCourse.Title = txtCourseName.Text;

                        entity.Courses.Add(newCourse);
                        entity.SaveChanges();
                        err.Visible = false;
                        Response.Redirect("AddCourse.aspx");
                    }
                }
            }
        }
Ejemplo n.º 8
0
    public void btnSubmit_Click(object sender, EventArgs e)
    {
        Page.Validate();

        if (Session["selectedcourse"] != null)
        {
            if (Page.IsValid)
            {
                using (var context = new StudentRecordEntities1())
                {
                    Course course = context.Courses.Where(c => c.Code == drpCourseSelection.SelectedValue).FirstOrDefault();

                    if (course != null)
                    {
                        List <AcademicRecord> records = course.AcademicRecords.Where(r => r.StudentId == studentID.Text).ToList();
                        if (records.Count > 0)
                        {
                            studentExistsError.Text = "The system already has a record of this student for the selected course";
                            orderList();
                        }
                        else
                        {
                            Student s = context.Students.Where(st => st.Id == studentID.Text).FirstOrDefault();

                            if (s == null)
                            {
                                s      = new Student();
                                s.Id   = studentID.Text;
                                s.Name = studentName.Text;
                                context.Students.Add(s);
                            }

                            AcademicRecord a = new AcademicRecord();
                            a.CourseCode = course.Code;
                            a.Grade      = int.Parse(studentGrade.Text);
                            a.Student    = s;

                            course.AcademicRecords.Add(a);
                            context.SaveChanges();

                            Response.Redirect("AddStudent.aspx");
                        }
                    }
                }
            }
        }
    }
Ejemplo n.º 9
0
    protected void Page_Load(object sender, EventArgs e)
    {
        LinkButton btnHome = (LinkButton)Master.FindControl("btnHome");

        btnHome.Click += (object s, EventArgs ev) =>
        {
            Response.Redirect("Default.aspx");
        };

        BulletedList topMenu = (BulletedList)Master.FindControl("topMenu");

        topMenu.Click += (object s, BulletedListEventArgs ev) =>
        {
            switch (ev.Index)
            {
            case 0:
                Response.Redirect("AddCourse.aspx");
                break;
            }
        };
        topMenu.Items.Remove("Add Students");

        if (topMenu.Items.Count < 1)
        {
            topMenu.Items.Add("Add Course");
        }

        using (var context = new StudentRecordEntities1()) {
            var courses = context.Courses.ToList <Course>();

            if (drpCourseSelection.Items.Count < courses.Count)
            {
                for (int i = 0; i < courses.Count; i++)
                {
                    drpCourseSelection.Items.Add(new ListItem(courses[i].Title, courses[i].Code));
                }
            }
        }

        if (Session["selectedcourse"] != null && drpCourseSelection.SelectedValue == "-1")
        {
            drpCourseSelection.SelectedValue = Session["selectedcourse"].ToString();
            orderList();
        }
    }
Ejemplo n.º 10
0
        protected void ShowStudentRecords()
        {
            var courses = GetCourses();

            for (int i = studentTable.Rows.Count - 1; i > 0; i--)
            {
                studentTable.Rows.RemoveAt(i);
            }
            foreach (Course course in courses)
            {
                string format = course.Code + " " + course.Title;
                if (CourseList.SelectedValue == format)
                {
                    using (StudentRecordEntities1 entityContext = new StudentRecordEntities1())
                    {
                        AcademicRecord records = (from c in entityContext.AcademicRecords
                                                  where c.CourseCode == course.Code
                                                  select c).FirstOrDefault <AcademicRecord>();
                        if (records != null)
                        {
                            foreach (AcademicRecord record in records.Course.AcademicRecords)
                            {
                                TableRow  studentRow = new TableRow();
                                TableCell idCell     = new TableCell();
                                TableCell nameCell   = new TableCell();
                                TableCell gradeCell  = new TableCell();
                                TableCell cell       = new TableCell();

                                idCell.Text    = record.Student.Id;
                                nameCell.Text  = record.Student.Name;
                                gradeCell.Text = record.Grade.ToString();
                                cell.Text      = "<a href='AddStudent.aspx?action=edit&id=" + record.Student.Id + "&course=" + course.Code + "'/>Change Grade</a>"
                                                 + " | <a class='deleteCourse' href='AddStudent.aspx?action=delete&id=" + record.Student.Id + "&course=" + course.Code + "'/>Delete</a>";

                                studentRow.Cells.Add(idCell);
                                studentRow.Cells.Add(nameCell);
                                studentRow.Cells.Add(gradeCell);
                                studentRow.Cells.Add(cell);
                                studentTable.Rows.Add(studentRow);
                            }
                        }
                    }
                }
            }
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string name     = txtEmployeeName.Text;
            string userName = txtUserName.Text.ToLower();
            string password = txtPassword.Text;

            using (StudentRecordEntities1 entityContext = new StudentRecordEntities1())
            {
                Employee employee = (from em in entityContext.Employees
                                     where em.UserName == userName
                                     select em).FirstOrDefault <Employee>();

                if (employee == null)
                {
                    Employee em = new Employee();
                    em.UserName = userName;
                    em.Name     = name;
                    em.Password = password;

                    List <ListItem> selected = new List <ListItem>();
                    foreach (ListItem item in checkList.Items)
                    {
                        if (item.Selected)
                        {
                            Role r = (from rm in entityContext.Roles
                                      where rm.Role1.ToLower() == item.Value.ToLower()
                                      select rm).FirstOrDefault <Role>();
                            if (r != null)
                            {
                                r.Employees.Add(em);
                            }
                        }
                    }
                    entityContext.SaveChanges();

                    Response.Redirect("AddEmployee.aspx");
                }
                else
                {
                    errMsg.Text = "Our system has indicated that username is already in use, please choose another";
                }
            }
        }
Ejemplo n.º 12
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        Course course = new Course();

        course.Code  = courseNumber.Text;
        course.Title = courseName.Text;

        using (var context = new StudentRecordEntities1())
        {
            if (context.Courses.Where(c => c.Code == courseNumber.Text).Count() > 0)
            {
                labelCourseNumberError.Text = "Course with this code already exists.";
                return;
            }
            else
            {
                context.Courses.Add(course);
                context.SaveChanges();
                Response.Redirect("AddCourse.aspx");
            }
        }
    }
Ejemplo n.º 13
0
    public void orderList()
    {
        if (Session["selectedcourse"] != null && !string.IsNullOrEmpty(Session["selectedcourse"].ToString()))
        {
            using (var context = new StudentRecordEntities1())
            {
                string s      = Session["selectedcourse"].ToString();
                Course course = context.Courses.Where(c => c.Code.Equals(s)).FirstOrDefault();

                if (course == null)
                {
                    selectCourseError.Text = "Please select a course";
                    return;
                }

                TableRow header = tblStudents.Rows[0];
                tblStudents.Rows.Clear();
                tblStudents.Rows.Add(header);

                List <AcademicRecord> list = course.AcademicRecords.ToList();

                if (Session["sort"] != null && (string)Session["sort"] == Request.Params["sort"])
                {
                    if (Session["order"] != null && Session["order"].ToString() == "ascending")
                    {
                        this.order       = "descending";
                        Session["order"] = this.order;
                    }
                    else
                    {
                        this.order       = "ascending";
                        Session["order"] = this.order;
                    }
                }
                else
                {
                    this.order       = "ascending";
                    Session["order"] = this.order;
                }

                Session["sort"] = Request.Params["sort"];

                IComparer <AcademicRecord> comparer;
                switch (Request.Params["sort"])
                {
                case "id":
                    comparer = new SortById(this.order);
                    list.Sort(comparer);
                    break;

                case "name":
                    comparer = new SortByName(this.order);
                    list.Sort(comparer);
                    break;

                case "grade":
                    comparer = new SortByGrade(this.order);
                    list.Sort(comparer);
                    break;
                }

                foreach (AcademicRecord student in list)
                {
                    TableRow row = new TableRow();

                    TableCell cell = new TableCell();
                    cell.Text = student.Student.Id;
                    row.Cells.Add(cell);

                    cell      = new TableCell();
                    cell.Text = student.Student.Name;
                    row.Cells.Add(cell);

                    cell      = new TableCell();
                    cell.Text = student.Grade + "";
                    row.Cells.Add(cell);

                    tblStudents.Rows.Add(row);
                }
            }
        }
    }
Ejemplo n.º 14
0
        protected void btn_AddToCourse_Click(object sender, EventArgs e)
        {
            string action = Request.Params["action"];

            ActionHandler(action);

            String studentName = txtStudentName.Text.Trim();
            String studentID   = txtStudentNum.Text.Trim();

            String[] courseString = CourseList.SelectedValue.Split();
            string   courseCode   = courseString[0];

            using (StudentRecordEntities1 entityContext = new StudentRecordEntities1())
            {
                // TODO: Add edit actions
                if (action == "edit")
                {
                    string studentId  = Request.Params["id"] as String;
                    string courseId   = Request.Params["course"] as String;
                    Course editCourse = (from c in entityContext.Courses
                                         where c.Code == courseId
                                         select c).FirstOrDefault <Course>();

                    if (editCourse != null)
                    {
                        AcademicRecord record = (from c in editCourse.AcademicRecords
                                                 where c.StudentId == studentId
                                                 select c).FirstOrDefault <AcademicRecord>();

                        record.Grade = int.Parse(txtStudentGrade.Text);
                        entityContext.Entry(record).State = System.Data.Entity.EntityState.Modified;
                        entityContext.SaveChanges();
                        Response.Redirect("AddStudent.aspx");
                    }
                }
                else
                {
                    Course course = (from c in entityContext.Courses
                                     where c.Code == courseCode.Trim()
                                     select c).FirstOrDefault <Course>();

                    string format = course.Code + " " + course.Title;
                    if (CourseList.SelectedValue == format)
                    {
                        int studentGrade = int.Parse(txtStudentGrade.Text.Trim());

                        Student student = (from c in entityContext.Students
                                           where c.Id == studentID
                                           select c).FirstOrDefault <Student>();

                        if (student != null)
                        {
                            AcademicRecord record = (from c in student.AcademicRecords
                                                     where c.CourseCode == course.Code
                                                     select c).FirstOrDefault <AcademicRecord>();

                            if (course.AcademicRecords.Contains(record))
                            {
                                errMsg.Text    = "The system already has a record of this student for the selected course";
                                errMsg.Visible = true;
                            }
                            else
                            {
                                AcademicRecord newRecord = new AcademicRecord();
                                newRecord.Grade   = studentGrade;
                                newRecord.Student = student;
                                newRecord.Course  = course;
                                course.AcademicRecords.Add(newRecord);
                                entityContext.SaveChanges();
                                Response.Redirect("AddStudent.aspx");
                            }
                        }
                        else
                        {
                            Student newStudent = new Student();
                            newStudent.Name = studentName;
                            newStudent.Id   = studentID;
                            AcademicRecord newRecord = new AcademicRecord();
                            newRecord.Grade   = studentGrade;
                            newRecord.Student = newStudent;
                            newRecord.Course  = course;
                            course.AcademicRecords.Add(newRecord);
                            entityContext.SaveChanges();
                            Response.Redirect("AddStudent.aspx");
                        }
                    }
                }
            }
        }