Beispiel #1
0
        public async Task <ActionResult <GroupInfo> > UpdateGroup(int groupId, [FromBody] UpdateGroupParameters parameters)
        {
            var group = await groupsRepo.FindGroupByIdAsync(groupId).ConfigureAwait(false);

            var newName = parameters.Name ?? group.Name;
            var newIsManualCheckingEnabled = parameters.IsManualCheckingEnabled ?? group.IsManualCheckingEnabled;
            var newIsManualCheckingEnabledForOldSolutions = parameters.IsManualCheckingEnabledForOldSolutions ?? group.IsManualCheckingEnabledForOldSolutions;
            var newDefaultProhibitFurtherReview           = parameters.DefaultProhibitFurtherReview ?? group.DefaultProhibitFutherReview;
            var newCanUsersSeeGroupProgress = parameters.CanStudentsSeeGroupProgress ?? group.CanUsersSeeGroupProgress;
            await groupsRepo.ModifyGroupAsync(
                groupId,
                newName,
                newIsManualCheckingEnabled,
                newIsManualCheckingEnabledForOldSolutions,
                newDefaultProhibitFurtherReview,
                newCanUsersSeeGroupProgress
                ).ConfigureAwait(false);

            if (parameters.IsArchived.HasValue)
            {
                await groupsRepo.ArchiveGroupAsync(groupId, parameters.IsArchived.Value).ConfigureAwait(false);
            }

            if (parameters.IsInviteLinkEnabled.HasValue)
            {
                await groupsRepo.EnableInviteLinkAsync(groupId, parameters.IsInviteLinkEnabled.Value).ConfigureAwait(false);
            }

            return(BuildGroupInfo(await groupsRepo.FindGroupByIdAsync(groupId).ConfigureAwait(false)));
        }
Beispiel #2
0
        public async Task <ActionResult <GroupInfo> > UpdateGroup(int groupId, [FromBody] UpdateGroupParameters parameters)
        {
            var hasEditAccess = await groupAccessesRepo.HasUserEditAccessToGroupAsync(groupId, UserId).ConfigureAwait(false);

            if (!hasEditAccess)
            {
                return(StatusCode((int)HttpStatusCode.Forbidden, new ErrorResponse("You have no edit access to this group")));
            }

            var group = await groupsRepo.FindGroupByIdAsync(groupId).ConfigureAwait(false);

            var newName = parameters.Name ?? group.Name;
            var newIsManualCheckingEnabled = parameters.IsManualCheckingEnabled ?? group.IsManualCheckingEnabled;
            var newIsManualCheckingEnabledForOldSolutions = parameters.IsManualCheckingEnabledForOldSolutions ?? group.IsManualCheckingEnabledForOldSolutions;
            var newDefaultProhibitFurtherReview           = parameters.DefaultProhibitFurtherReview ?? group.DefaultProhibitFutherReview;
            var newCanUsersSeeGroupProgress = parameters.CanStudentsSeeGroupProgress ?? group.CanUsersSeeGroupProgress;
            await groupsRepo.ModifyGroupAsync(
                groupId,
                newName,
                newIsManualCheckingEnabled,
                newIsManualCheckingEnabledForOldSolutions,
                newDefaultProhibitFurtherReview,
                newCanUsersSeeGroupProgress
                ).ConfigureAwait(false);

            if (parameters.IsArchived.HasValue)
            {
                await groupsRepo.ArchiveGroupAsync(groupId, parameters.IsArchived.Value).ConfigureAwait(false);

                if (parameters.IsArchived.Value)
                {
                    var notification = new GroupIsArchivedNotification {
                        GroupId = groupId
                    };
                    await notificationsRepo.AddNotification(group.CourseId, notification, UserId);
                    await ArchiveAllOldGroups();
                }
            }

            if (parameters.IsInviteLinkEnabled.HasValue)
            {
                await groupsRepo.EnableInviteLinkAsync(groupId, parameters.IsInviteLinkEnabled.Value).ConfigureAwait(false);
            }

            return(BuildGroupInfo(await groupsRepo.FindGroupByIdAsync(groupId).ConfigureAwait(false)));
        }