public async Task <ArchiveReportResponse> Handle(ArchiveReportRequest request, CancellationToken cancellationToken) { var report = await reportValidationHub.ValidateAndReturnReport(request.ReportId, ReportPermission.ArchiveReport) ?? throw new NoPermissionsException(ErrorMessages.NotAllowedMessage); if (await reportManager.ArchiveReport(report)) { var membersGroup = ReportManagerUtils.GenerateReportMembersGroup(report, httpContextReader.CurrentUserId); var notifications = await notifier.PushToGroup( $"Report {report.Subject} has been archived", membersGroup); foreach (var memberId in membersGroup) { await hubManager.Invoke(SignalrActions.NOTIFICATION_RECEIVED, memberId, mapper.Map <IEnumerable <NotificationDto> >(notifications)); } return((ArchiveReportResponse) new ArchiveReportResponse().LogInformation( $"Report #{report.Id} has been archived")); } throw new CrudException("Archiving report failed"); }
public async Task <AddReportCommentResponse> Handle(AddReportCommentRequest request, CancellationToken cancellationToken) { var report = await reportValidationHub.ValidateAndReturnReport(request.ReportId, ReportPermission.AddComment) ?? throw new NoPermissionsException(ErrorMessages.NotAllowedMessage); var addedReportComment = await reportCommentService.AddComment(request with { IsPrivate = report.Private }) ?? throw new CrudException("Adding report comment failed"); if (ReportStatusTypeSmartEnum.FromValue(report.Status) .ShouldBeOpened(report, addedReportComment.UserId)) { await reportManager.ChangeStatus(ReportStatusType.Opened, report); } var membersGroup = ReportManagerUtils.GenerateReportMembersGroup(report, addedReportComment.UserId); var notifications = await notifier.PushToGroup( $"Someone responded to your report: {report.Subject}", membersGroup); foreach (var memberId in membersGroup) { await hubManager.Invoke(SignalrActions.NOTIFICATION_RECEIVED, memberId, mapper.Map <IEnumerable <NotificationDto> >(notifications)); } return((AddReportCommentResponse) new AddReportCommentResponse { ReportComment = mapper.Map <ReportCommentDto>(addedReportComment) } .LogInformation( $"Member #{addedReportComment.UserId} of report #{report.Id} added comment #{addedReportComment.Id}")); }