Пример #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 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");
      }
    }