Пример #1
0
        public void UpdateGrade(List <string> grade, string courseName)
        {
            cours course = new cours();

            try
            {
                using (var context = new BAProjectEntities())
                {
                    course = context.courses.FirstOrDefault(x => x.name.Equals(courseName));

                    foreach (var gradeDatabase in course.grades_database)
                    {
                        gradeDatabase.grade = grade.First();
                        grade.Remove(grade.First());
                    }
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                if (ex is EntityException || ex is NullReferenceException)
                {
                    MessageBox.Show("Couldn't connect to the database. Please try again later.");
                }
                else
                {
                    throw;
                }
            }
            Response.Redirect("~/ReportCard/LecturerView/" + course.course_id);
        }
Пример #2
0
 public bool CheckLogin(string _username, string _password)
 {
     try
     {
         //var result = new SignInStatus();
         using (var context = new BAProjectEntities())
         {
             var existingUser = context.users.FirstOrDefault(x => x.username.Contains(_username));
             if (existingUser != null)
             {
                 if (existingUser.password.Equals(_password))
                 {
                     return(true);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         if (ex is EntityException || ex is NullReferenceException)
         {
             MessageBox.Show("Couldn't connect to the database. Please try again later.");
         }
         else
         {
             throw;
         }
     }
     return(false);
 }
Пример #3
0
        public ActionResult courseInfo()
        {
            List <user> listOfProfessors = new List <user>();

            using (var context = new BAProjectEntities())
            {
                listOfProfessors = context.users.Where(x => x.type_of_user.Equals(1)).ToList();
            }
            return(View(listOfProfessors));
        }
Пример #4
0
        //profile for Lecturers
        public ActionResult LecturerProfile(string id)
        {
            user lecturer = new user();

            using (var context = new BAProjectEntities())
            {
                lecturer = context.users.FirstOrDefault(x => x.users_id.ToString().Equals(id));
            }

            return(View(lecturer));
        }
Пример #5
0
        public user GetUser()
        {
            user   user   = new user();
            string cookie = HttpContext.Request.Cookies["user"].Value;

            using (var context = new BAProjectEntities())
            {
                user = context.users.FirstOrDefault(x => x.username.Equals(cookie));
            }
            return(user);
        }
Пример #6
0
        public user GetProfessorById(string id)
        {
            user lecturer;

            using (var context = new BAProjectEntities())
            {
                lecturer = context.courses.FirstOrDefault(l => l.course_id.ToString().Equals(id)).user;
            }

            return(lecturer);
        }
Пример #7
0
        public List <cours> GetListOfCourses()
        {
            listOfCourses = new List <cours>();
            using (var context = new BAProjectEntities())
            {
                foreach (cours course in context.courses)
                {
                    listOfCourses.Add(course);
                }
            }

            return(listOfCourses);
        }
Пример #8
0
        public void Index()
        {
            user   user   = new user();
            string cookie = HttpContext.Request.Cookies["user"].Value;

            using (var context = new BAProjectEntities())
            {
                user = context.users.FirstOrDefault(x => x.username.Equals(cookie));
            }
            if (user.type_of_user == 2)
            {
                Response.Redirect("~/ReportCard/StudentView/" + user.users_id);
            }
        }
Пример #9
0
        //view for the lecturer
        public ActionResult LecturerView(string id)
        {
            Dictionary <string, string> usernamesAndGrades = new Dictionary <string, string>();

            using (var context = new BAProjectEntities())
            {
                cours course = context.courses.FirstOrDefault(x => x.course_id.ToString() == id);
                ViewBag.courseName = course.name;

                foreach (var grade in course.grades_database)
                {
                    usernamesAndGrades.Add(grade.user.full_name, grade.grade);
                }
            }
            return(View(usernamesAndGrades));
        }
Пример #10
0
        public void UpdateData(string desc, string addressline1, string addressline2, string postcode, string phone, string email, string city, string name, string office)
        {
            user user = GetUser();

            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(desc) || string.IsNullOrEmpty(city) || string.IsNullOrEmpty(addressline1) || string.IsNullOrEmpty(postcode) || string.IsNullOrEmpty(phone))
            {
                MessageBox.Show("Not all information has been filled in. Please try again.");
            }
            else
            {
                try
                {
                    using (var context = new BAProjectEntities())
                    {
                        user databaseUser = context.users.FirstOrDefault(u => u.username.Equals(user.username));

                        databaseUser.full_name          = name;
                        databaseUser.description        = desc;
                        databaseUser.email              = email;
                        databaseUser.address_city       = city;
                        databaseUser.address_firstline  = addressline1;
                        databaseUser.address_secondline = addressline2;
                        databaseUser.postcode           = postcode;
                        databaseUser.phone_number       = phone;
                        databaseUser.office             = office;

                        context.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    if (ex is EntityException || ex is NullReferenceException)
                    {
                        MessageBox.Show("Couldn't connect to the database. Please try again later.");
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            Response.Redirect("~/Profile/Index");
        }
Пример #11
0
        //view for student report card
        public ActionResult StudentView(int id)
        {
            Dictionary <string, string> grades = new Dictionary <string, string>();

            using (var context = new BAProjectEntities())
            {
                List <grades_database> gradeDB         = context.grades_database.ToList();
                List <grades_database> gradeForStudent = gradeDB.FindAll(x => x.student_id.Equals(id)).ToList();
                foreach (var item in gradeForStudent)
                {
                    if (item.history == false)
                    {
                        grades.Add(item.cours.name, item.grade);
                    }
                }
            }

            return(View(grades));
        }
Пример #12
0
        public void AddNewCourse(string name, string outline, string startdate, string enddate, int lecturer)
        {
            bool messageBox = true;

            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(outline) || string.IsNullOrEmpty(startdate) || string.IsNullOrEmpty(enddate))
            {
                MessageBox.Show("Not all details have been filled out. Please try again.");
            }
            else
            {
                try
                {
                    string   username = Request.Cookies["user"].Value;
                    bool     approved = false;
                    DateTime start    = Convert.ToDateTime(startdate);
                    DateTime end      = Convert.ToDateTime(enddate);

                    if (start < end)
                    {
                        using (var context = new BAProjectEntities())
                        {
                            user user = context.users.FirstOrDefault(x => x.username.Equals(username));
                            int  type = user.type_of_user;

                            if (type == 3)
                            {
                                approved = true;
                            }

                            cours course = new cours()
                            {
                                name        = name,
                                outline     = outline,
                                start_date  = start,
                                finish_date = end,
                                available   = true,
                                approved    = approved,
                                lecturer    = lecturer
                            };
                            context.courses.Add(course);
                            context.SaveChanges();

                            if (approved)
                            {
                                MessageBox.Show(name + " has been added as a course.");
                            }
                            else
                            {
                                messageBox = false;
                                Response.Redirect("~/CourseCatalogue/confirmationPage");
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("The start date is after the end date. Please try again.");
                    }
                }
                catch (Exception ex)
                {
                    if (ex is EntityException || ex is NullReferenceException)
                    {
                        MessageBox.Show("Couldn't connect to the database. Please try again later.");
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            if (messageBox)
            {
                Response.Redirect("~/CourseCatalogue/courseInfo");
            }
        }