public void DeleteCourse(int id, CourseUpdateViewModel model)
 {
     try
     {
         _service.DeleteCourse(id, model);
     }
     catch (AppObjectNotFoundException)
     {
         throw new HttpResponseException(HttpStatusCode.NotFound);
     }
 }
 /// <summary>
 /// Deletes course with specific id
 /// </summary>
 /// <param name="id"></param>
 /// <param name="model"></param>
 /// <returns></returns>
 public void DeleteCourse(int id, CourseUpdateViewModel model)
 {
     var course = (from x in _db.Courses
                   where x.ID == id
                   select x).SingleOrDefault();
     if (course == null)
     {
         throw new AppObjectNotFoundException();
     }
     _db.Courses.Remove(course);
     _db.SaveChanges();
 }
        public CourseDTO UpdateCourse(int id, CourseUpdateViewModel model)
        {
            //1.Validate
            //2.Update

            var courseEntity = (from x in _db.Courses
                                where x.ID == id
                                select x).SingleOrDefault();
            if(courseEntity == null)
            {
                throw new AppObjectNotFoundException();
            }

            courseEntity.StartDate = model.StartDate;
            courseEntity.EndDate = model.EndDate;

            _db.SaveChanges();

            var courseTemplate = (from x in _db.CourseTemplates
                                 where x.TemplateID == courseEntity.TemplateID
                                 select x).SingleOrDefault();
            if(courseTemplate == null)
            {
                throw new ApplicationException("Ooooops");
            }

            var count = (from x in _db.CourseStudents
                         where x.CourseID == courseEntity.ID
                         select x).Count();

            var result = new CourseDTO
            {
                ID = courseEntity.ID,
                Name = courseTemplate.Name,
                StartDate = courseEntity.StartDate,
                EndDate = courseEntity.EndDate,
                StudentCount = count

            };

            return result;
        }