Exemplo n.º 1
0
 public CourseGroup MapCourseGroupDTO(CourseGroupDTO courseGroup)
 {
     return(new CourseGroup {
         CourseId = courseGroup.CourseId,
         GroupId = courseGroup.GroupId
     });
 }
Exemplo n.º 2
0
        public async Task <ActionResult <CourseGroupDTO> > PostCourseGroup(Guid courseId, CourseGroupDTO group)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (courseId != group.CourseId)
            {
                ModelState.AddModelError(string.Empty, "The courseId request parameter did not match the courseId property in the data.");
                return(BadRequest(ModelState));
            }

            var cGroup = courseMapper.MapCourseGroupDTO(group);

            var existingGroup = await _context.CourseGroups.FindAsync(cGroup.CourseId, cGroup.GroupId);

            if (existingGroup != null)
            {
                ModelState.AddModelError(string.Empty, "The group you are trying to add already exists.");
                return(BadRequest(ModelState));
            }

            var course = await _context.Courses
                         .Include(c => c.Professor)
                         .Include(c => c.CourseInfo)
                         .FirstOrDefaultAsync(c => c.Id == cGroup.CourseId);

            var authorization = await authorizationService.AuthorizeAsync(User, course, AuthorizationConstants.CanUpdateCoursePolicy);

            if (!authorization.Succeeded)
            {
                return(Forbid());
            }

            _context.CourseGroups.Add(cGroup);
            await _context.SaveChangesAsync();

            cGroup = await _context.CourseGroups
                     .Include(cg => cg.Group)
                     .FirstOrDefaultAsync(cg => cg.CourseId == cGroup.CourseId && cg.GroupId == cGroup.GroupId);

            await cache.ClearCourseCacheAsync(courseId, course.CourseInfo.Slug);

            return(CreatedAtAction("GetCourse", new { id = cGroup.CourseId }, courseMapper.MapCourseGroup(cGroup)));
        }
 private async Task OpenCourses(CourseGroupDTO courseGroup)
 {
     await _navigation.Navigate <CoursesViewModel, CourseGroupDTO>(courseGroup);
 }