Пример #1
0
        public IHttpActionResult CreateCourse(CourseViewModel newCourse)
        {
            NewCourseDTO dto = new NewCourseDTO();

            dto.Semester   = newCourse.Semester;
            dto.TemplateID = newCourse.TemplateID;
            dto.StartDate  = newCourse.StartDate;
            dto.EndDate    = newCourse.EndDate;

            try
            {
                var createdCourse = _context.CreateCourse(dto);

                var location = Url.Link("GetCourse", new { id = createdCourse.ID });
                return(Created(location, createdCourse));
            }
            catch (Exception ex)
            {
                if (ex is KeyNotFoundException)
                {
                    return(NotFound());
                }
                return(InternalServerError());
            }
        }
        /// <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);
        }
Пример #3
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));
        }
Пример #4
0
        public IHttpActionResult CreateCourse(CourseViewModel newCourse)
        {
            NewCourseDTO dto = new NewCourseDTO();
            dto.Semester = newCourse.Semester;
            dto.TemplateID = newCourse.TemplateID;
            dto.StartDate = newCourse.StartDate;
            dto.EndDate = newCourse.EndDate;

            try
            {
                var createdCourse = _context.CreateCourse(dto);

                var location = Url.Link("GetCourse", new { id = createdCourse.ID });
                return Created(location, createdCourse);
            }
            catch(Exception ex)
            {
                if (ex is KeyNotFoundException)
                    return NotFound();
                return InternalServerError();
            }
        }