/// <summary>
        /// Creates a new course of a template type
        /// </summary>
        /// <param name="newCourse">Info about the new course</param>
        public CourseDetailDTO CreateCourse(NewCourseDTO info)
        {
            var template = _db.CourseTemplate.SingleOrDefault(t => info.TemplateID == t.TemplateID);
            if(template == null)
            {
                throw new KeyNotFoundException();
            }

            Entities.Course  newCourse = new Entities.Course();
            newCourse.Semester = info.Semester;
            newCourse.TemplateID = info.TemplateID;
            newCourse.StartDate = info.StartDate;
            newCourse.EndDate = info.EndDate;

            _db.Courses.Add(newCourse);
            _db.SaveChanges();

            return GetCourseById(newCourse.ID);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new course of a template type
        /// </summary>
        /// <param name="newCourse">Info about the new course</param>
        public CourseDetailDTO CreateCourse(NewCourseDTO info)
        {
            var template = _db.CourseTemplate.SingleOrDefault(t => info.TemplateID == t.TemplateID);

            if (template == null)
            {
                throw new KeyNotFoundException();
            }


            Entities.Course newCourse = new Entities.Course();
            newCourse.Semester   = info.Semester;
            newCourse.TemplateID = info.TemplateID;
            newCourse.StartDate  = info.StartDate;
            newCourse.EndDate    = info.EndDate;

            _db.Courses.Add(newCourse);
            _db.SaveChanges();

            return(GetCourseById(newCourse.ID));
        }