public IActionResult CreateCourseEdition([FromBody] CourseEditionViewModel editionViewModel)
        {
            if (editionViewModel == null || editionViewModel.CourseId < 0)
            {
                return(BadRequest());
            }
            if (editionViewModel.EndDate < editionViewModel.StartDate)
            {
                ModelState.AddModelError("StartDate", "Start date must be prior to end date.");
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            editionWork.Begin();
            var course = editionWork.Courses.FindByID(editionViewModel.CourseId);

            if (course == null)
            {
                return(NotFound());
            }
            var edition = new CourseEdition()
            {
                CourseId  = editionViewModel.CourseId,
                StartDate = editionViewModel.StartDate,
                EndDate   = editionViewModel.EndDate,
                Cost      = editionViewModel.Cost
            };

            editionWork.CourseEditions.Add(edition);
            editionWork.Save();
            editionWork.End();
            return(CreatedAtRoute("GetCourseEdition",
                                  new { edition.Id }, edition.ToViewModel()));
        }
        public void Remove(long editionId)
        {
            var toRemove = new CourseEdition {
                Id = editionId
            };

            ctx.CourseEditions.Remove(toRemove);
        }
コード例 #3
0
        private void CreateEnrollmentsForBestStudentsTest()
        {
            // best 2  students for course 0: student 1 with a 410, student 3 with an average of (230 + 200)/2
            // best 2  students for edition 0: student 1 with 410 , student 2 with 210
            // best 2  students for course 1 : student 0 with 500 , second student 2 with 420
            // best 2  students overall : student  2 with 415 , student 1 with 410

            var students = new Student[4];

            for (int i = 0; i < students.Length; i++)
            {
                students[i] = new Student {
                    Name = TEST_NAME + i, BirthDate = DateTime.Today.AddYears(-20)
                };
            }
            for (int i = 0; i < courses.Length; i++)
            {
                courses[i] = new Course {
                    Title = TEST_TITLE + i, DurationInHours = 40, Level = CourseLevel.Introductory
                };
            }
            for (int i = 0; i < courseEditions.Length; i++)
            {
                courseEditions[i] = new CourseEdition {
                    Course = i < (courseEditions.Length - 1) ? courses[0] : courses[1], StartDate = DateTime.Today, EndDate = DateTime.Today.AddDays(1), Cost = 1000
                };
            }
            var enrollments = new Enrollment[8];

            enrollments[0] = new Enrollment {
                Score = 200, Student = students[0], CourseEdition = courseEditions[0], EnrollmentDate = DateTime.Today
            };
            enrollments[1] = new Enrollment {
                Score = 410, Student = students[1], CourseEdition = courseEditions[0], EnrollmentDate = DateTime.Today
            };
            enrollments[2] = new Enrollment {
                Score = 210, Student = students[2], CourseEdition = courseEditions[0], EnrollmentDate = DateTime.Today
            };
            enrollments[3] = new Enrollment {
                Score = 200, Student = students[3], CourseEdition = courseEditions[0], EnrollmentDate = DateTime.Today
            };
            enrollments[4] = new Enrollment {
                Score = 230, Student = students[3], CourseEdition = courseEditions[1], EnrollmentDate = DateTime.Today
            };
            enrollments[5] = new Enrollment {
                Score = 500, Student = students[0], CourseEdition = courseEditions[2], EnrollmentDate = DateTime.Today
            };
            enrollments[6] = new Enrollment {
                Score = 420, Student = students[2], CourseEdition = courseEditions[2], EnrollmentDate = DateTime.Today
            };
            enrollments[7] = new Enrollment {
                Score = 50, Student = students[3], CourseEdition = courseEditions[2], EnrollmentDate = DateTime.Today
            };

            ctx.Enrollments.AddRange(enrollments);
            ctx.SaveChanges();
        }
コード例 #4
0
 public static CourseEditionViewModel ToViewModel(this CourseEdition edition)
 {
     return(new CourseEditionViewModel()
     {
         Id = edition.Id,
         CourseId = edition.CourseId,
         StartDate = edition.StartDate,
         EndDate = edition.EndDate,
         Cost = edition.Cost
     });
 }
        public void RemoveFromCourseEdition(CourseEdition edition, Student student)
        {
            Enrollment enro = new Enrollment(edition.Id, student.Id);

            ctx.Enrollments.Remove(enro);
        }
        public void EnrollInCourseEdition(CourseEdition edition, Student student)
        {
            Enrollment enro = new Enrollment(edition.Id, student.Id);

            ctx.Enrollments.Add(enro);
        }
 public void Add(CourseEdition edition)
 {
     ctx.CourseEditions.Add(edition);
 }