public JsonResult Index(CourseOfferingViewModel viewModel)
        {
            try
            {
                // Populate
                viewModel = new CourseOfferingViewModelFactory(viewModel, _courseService).GetViewModel();

                // Validate
                if (!ModelState.IsValid)
                    return Json(new {status = "error", message = "Validation Errors"});

                // Bind
                var courseOffering = new CourseOffering
                {
                    CourseId = viewModel.SelectedCourse,
                    Semester = viewModel.Semester.GetValueOrDefault(),
                    Year = viewModel.SelectedYear
                };

                // Save
                _courseService.AddCourseOffering(courseOffering);

                // Respond
                return Json(new {status = "success", message = "Course Offering Added"});
            }
            catch (CourseOfferingExistsException)
            {
                return Json(new {status = "error", message = "Course Offering already exists"});
            }
        }
        public JsonResult Add(CourseOfferingViewModel viewModel)
        {
            // Populate VM
            viewModel = PopulateViewModel(viewModel);

            // Validate model state
            if (!ModelState.IsValid)
                return Json(new { error = true, message = "There were errors in the submission"});

            // Attempt to add the offering
            try
            {
                var offering = new CourseOffering()
                {
                    Course_CourseID = viewModel.SelectedCourseId,
                    Semester = viewModel.Semester.ToString(),
                    Year = viewModel.SelectedYear
                };

                _courseService.AddCourseOffering(offering);

            }
            catch (CourseOfferingExistsException)
            {
                // If the offering already exists, display error
                return Json(new { error = true, message = "Course offering already exists" });
            }

            return Json(new { error = false, message = "Course offering successfully created!" });
        }
 public bool CourseOfferingExists(CourseOffering offering)
 {
     var match = _dbContext.CourseOfferings.Any(
         o =>
             o.Course_CourseID == offering.Course_CourseID &&
             o.Year == offering.Year &&
             o.Semester == offering.Semester);
     return match;
 }
Esempio n. 4
0
        /// <summary>
        ///     Adds the course offering.
        /// </summary>
        /// <param name="courseOffering">The course offering.</param>
        public void AddCourseOffering(CourseOffering courseOffering)
        {
            using (_courseOfferingRepository)
            {
                if (_courseOfferingRepository.HasCourseOffering(courseOffering))
                    throw new CourseOfferingExistsException();

                _courseOfferingRepository.InsertCourseOffering(courseOffering);
            }
        }
        public void InsertStudentIntoCourseOffering(Student student, CourseOffering courseOffering)
        {
            // Get the current student from the offering
            var currentStudent = _dbContext.Students.FirstOrDefault(s => s.StudentNum == student.StudentNum);

            // Add / Register student
            courseOffering.Students.Add(currentStudent ?? student);

            // Persist to the DB
            Save();
        }
 public void InsertCourseOffering(CourseOffering courseOffering)
 {
     using (var dbTransaction = _db.Database.BeginTransaction())
     {
         try
         {
             _db.CourseOfferings.Add(courseOffering);
             _db.SaveChanges();
             dbTransaction.Commit();
         }
         catch (Exception)
         {
             dbTransaction.Rollback();
         }
     }
 }
 public void InsertCourseOffering(CourseOffering courseOffering)
 {
     _dbContext.CourseOfferings.Add(courseOffering);
 }
 /// <summary>
 ///     Check if a Course Offering exists
 /// </summary>
 /// <param name="courseOffering">The course offering.</param>
 /// <returns></returns>
 public bool HasCourseOffering(CourseOffering courseOffering) => _db.CourseOfferings.Any(
     offering =>
         offering.Semester == courseOffering.Semester && offering.Year == courseOffering.Year &&
         offering.CourseId == courseOffering.CourseId);
Esempio n. 9
0
 public int CompareTo(CourseOffering other) => other == null ? 1 : Year.CompareTo(other.Year);
Esempio n. 10
0
 public bool StudentExists(CourseOffering offering, string number)
 {
     return offering.Students.FirstOrDefault(s => s.StudentNum == number) != null;
 }
Esempio n. 11
0
 public List<Student> GetStudents(CourseOffering offering)
 {
     return offering.Students.ToList();
 }