Example #1
0
        public async Task <IActionResult> RemoveUserFromCourseAsync(WorkspaceCourseUserEditModel model)
        {
            try
            {
                var userId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name)?.Value;
                if (userId == null)
                {
                    throw new AppException("UC1001");
                }

                var workspaceId = User.Claims.FirstOrDefault(c => c.Type == "WorkspaceId")?.Value;
                if (string.IsNullOrWhiteSpace(workspaceId))
                {
                    throw new AppException("UC1001");
                }

                var courseUser = await _courseService.GetCourseUserByWorkspaceIdAsync(model.UserId, model.CourseId, int.Parse(workspaceId));

                var courseUserResult = await _courseService.RemoveUserFromCourseAsync(courseUser);

                return(Ok(new
                {
                    id = model.UserId,
                    registered = courseUserResult
                }));
            }
            catch (Exception ex)
            {
                return(BadRequest(new { ex.Message }));
            }
        }
Example #2
0
        public async Task <IActionResult> AddUserToCourseAsync(WorkspaceCourseUserEditModel model)
        {
            try
            {
                var userId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name)?.Value;
                if (userId == null)
                {
                    throw new AppException("UC1001");
                }

                var workspaceId = User.Claims.FirstOrDefault(c => c.Type == "WorkspaceId")?.Value;
                if (string.IsNullOrWhiteSpace(workspaceId))
                {
                    throw new AppException("UC1001");
                }

                var courseUserResult = await _courseService.AddUserToCourseAsync(new CourseUser { UserId = model.UserId, CourseId = model.CourseId, RoleCode = model.RoleCode });

                return(Ok(new
                {
                    userid = model.UserId,
                    registered = courseUserResult
                }));
            }
            catch (Exception ex)
            {
                return(BadRequest(new { ex.Message }));
            }
        }