// FOR DEMO PURPOSES ONLY:
        public async Task <int> CreateCourse(ServiceModels.Admin.BindingModels.CourseEditingBindingModel model)
        {
            var course = this.Mapper.Map <Course>(model);

            await this.DbContext.Courses.AddAsync(course);

            await this.DbContext.SaveChangesAsync();

            return(course.Id);
        }
        public async Task <IActionResult> CreateCourse([FromBody] ServiceModels.Admin.BindingModels.CourseEditingBindingModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(BadRequest(this.ModelState));
            }

            int courseId = await this.coursesService.CreateCourse(model);

            return(CreatedAtAction("Details", new { id = courseId }));
        }
        public async Task <CourseDetailsViewModel> UpdateCourse(ServiceModels.Admin.BindingModels.CourseEditingBindingModel model)
        {
            var course = this.DbContext.Courses
                         .Include(c => c.Instances)
                         .SingleOrDefault(c => c.Id == model.Id);

            if (course == null)
            {
                return(null);
            }

            course.Name = model.Name;
            course.Slug = model.Slug;
            await this.DbContext.SaveChangesAsync();

            var courseModel = this.Mapper.Map <CourseDetailsViewModel>(course);

            return(courseModel);
        }
        public async Task <ActionResult <CourseDetailsViewModel> > EditCourse(
            int id, [FromBody] ServiceModels.Admin.BindingModels.CourseEditingBindingModel model)
        {
            if (!this.ModelState.IsValid) // chech the B.Model attributes!
            {
                return(BadRequest(this.ModelState));
            }

            if (id != model.Id)
            {
                return(BadRequest(new { Message = "The ID to edit does not match." }));
            }

            var course = await this.coursesService.UpdateCourse(model);

            if (course == null)
            {
                return(NotFound(new { Message = "The course ID does not exist." }));
            }

            return(course);
        }