Exemple #1
0
        public async Task <ActionResult <CopyGroupResponse> > Copy(int groupId, [FromQuery] CopyGroupParameters parameters)
        {
            var group = await groupsRepo.FindGroupByIdAsync(groupId).ConfigureAwait(false);

            if (!await courseManager.HasCourseAsync(parameters.DestinationCourseId))
            {
                return(NotFound(new ErrorResponse($"Course {parameters.DestinationCourseId} not found")));
            }
            if (!await CanCreateGroupInCourseAsync(UserId, parameters.DestinationCourseId).ConfigureAwait(false))
            {
                return(Forbid());
            }

            var newOwnerId = parameters.ChangeOwner ? UserId : null;
            var newGroup   = await groupsCreatorAndCopier.CopyGroupAsync(group, parameters.DestinationCourseId, newOwnerId).ConfigureAwait(false);

            var members = await groupMembersRepo.GetGroupMembersAsync(newGroup.Id);

            foreach (var member in members)
            {
                await slideCheckingsRepo.ResetManualCheckingLimitsForUser(parameters.DestinationCourseId, member.UserId);
            }

            var url = Url.Action(new UrlActionContext {
                Action = nameof(Group), Controller = "Group", Values = new { groupId = group.Id }
            });

            return(Created(url, new CopyGroupResponse
            {
                Id = newGroup.Id,
                ApiUrl = url
            }));
        }
Exemple #2
0
        public async Task <IActionResult> Join(Guid inviteHash)
        {
            var group = await groupsRepo.FindGroupByInviteHashAsync(inviteHash).ConfigureAwait(false);

            var groupMember = await groupMembersRepo.AddUserToGroupAsync(group.Id, UserId).ConfigureAwait(false);

            if (groupMember == null)
            {
                return(StatusCode((int)HttpStatusCode.Conflict, new ErrorResponse($"User {UserId} is already a student of group {group.Id}")));
            }

            await slideCheckingsRepo.ResetManualCheckingLimitsForUser(group.CourseId, UserId);

            return(Ok(new SuccessResponseWithMessage($"Student {UserId} is added to group {group.Id}")));
        }