public async Task <IActionResult> RemoveStudent(int groupId, string studentId) { 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 user = await usersRepo.FindUserByIdAsync(studentId).ConfigureAwait(false); if (user == null) { return(NotFound(new ErrorResponse($"Can't find user with id {studentId}"))); } var groupMember = await groupMembersRepo.RemoveUserFromGroupAsync(groupId, studentId).ConfigureAwait(false); if (groupMember == null) { return(NotFound(new ErrorResponse($"User {studentId} is not a student of group {groupId}"))); } await notificationsRepo.AddNotification( group.CourseId, new GroupMembersHaveBeenRemovedNotification(groupId, new List <string> { studentId }, usersRepo), UserId ).ConfigureAwait(false); return(Ok(new SuccessResponseWithMessage($"Student {studentId} is removed from group {groupId}"))); }
public async Task Handle(NotificationMessage message, RecipientContactInfo recipient) { if (message.Subject != null && message.Body != null) { _repo.AddNotification(new Notification(message.NotificationEvent, recipient.UserId, message.Subject, message.Body)); await _unitOfWork.SaveAsync(default);
// Оповещает о создании комментария к ревью, а не самого ревью (т.е. замечения к коду) private async Task NotifyAboutCodeReviewComment(ExerciseCodeReviewComment comment) { var courseId = comment.Review.ExerciseCheckingId.HasValue ? comment.Review.ExerciseChecking.CourseId : comment.Review.Submission.CourseId; await notificationsRepo.AddNotification(courseId, new ReceivedCommentToCodeReviewNotification { CommentId = comment.Id, }, comment.AuthorId); }
protected async Task NotifyAboutNewCommentAsync(Comment comment) { var courseId = comment.CourseId; if (!comment.IsTopLevel) { var parentComment = await commentsRepo.FindCommentByIdAsync(comment.ParentCommentId).ConfigureAwait(false); if (parentComment != null) { var replyNotification = new RepliedToYourCommentNotification { Comment = comment, ParentComment = parentComment, }; await notificationsRepo.AddNotification(courseId, replyNotification, comment.AuthorId).ConfigureAwait(false); } } /* Create NewCommentFromStudentFormYourGroupNotification later than RepliedToYourCommentNotification, because the last one is blocker for the first one. * We don't send NewCommentNotification if there is a RepliedToYouCommentNotification */ var commentFromYourGroupStudentNotification = new NewCommentFromYourGroupStudentNotification { Comment = comment }; await notificationsRepo.AddNotification(courseId, commentFromYourGroupStudentNotification, comment.AuthorId); /* Create NewComment[ForInstructors]Notification later than RepliedToYourCommentNotification and NewCommentFromYourGroupStudentNotification, because the last one is blocker for the first one. * We don't send NewCommentNotification if there is a RepliedToYouCommentNotification or NewCommentFromYourGroupStudentNotification */ var notification = comment.IsForInstructorsOnly ? (Notification) new NewCommentForInstructorsOnlyNotification { Comment = comment } : new NewCommentNotification { Comment = comment }; await notificationsRepo.AddNotification(courseId, notification, comment.AuthorId).ConfigureAwait(false); }
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))); }
public async Task <ActionResult <CreateGroupResponse> > CreateGroup([FromQuery] CourseAuthorizationParameters courseAuthorizationParameters, CreateGroupParameters parameters) { var ownerId = User.GetUserId(); var group = await groupsRepo.CreateGroupAsync(courseAuthorizationParameters.CourseId, parameters.Name, ownerId).ConfigureAwait(false); await notificationsRepo.AddNotification( group.CourseId, new CreatedGroupNotification(group.Id), UserId ).ConfigureAwait(false); var url = Url.Action(new UrlActionContext { Action = nameof(GroupController.Group), Controller = "Group", Values = new { groupId = group.Id } }); return(Created(url, new CreateGroupResponse { Id = group.Id, ApiUrl = url, })); }