Exemple #1
0
        public async Task <IActionResult> PutCourse(int id, Course course)
        {
            if (id != course.Id)
            {
                return(BadRequest());
            }

            _context.Entry(course).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CourseExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToAction("GetCourse", new { id = course.Id }));
        }
Exemple #2
0
        public async Task <ActionResult <IEnumerable <Course> > > GetCourses(int userId)
        {
            var user = await _context.Users.FindAsync(userId);

            if (user == null)
            {
                return(NotFound());
            }

            return(_context.Entry(user)
                   .Collection(u => u.Enrollments)
                   .Query()
                   .Include(en => en.Course)
                   .ThenInclude(c => c.Enrollments)
                   .Select(en => en.Course)
                   .ToList());
        }