コード例 #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
ファイル: ProfileController.cs プロジェクト: Psela/BAProject
        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");
        }
コード例 #3
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");
            }
        }