public async Task <IActionResult> Search([FromBody] SearchNotificationsQuery parameter, CancellationToken token) { parameter.Claims = User.GetClaims(); var result = await _mediator.Send(parameter, token); return(new OkObjectResult(result)); }
public async Task <SearchResult <NotificationDetailsResult> > Handle(SearchNotificationsQuery request, CancellationToken cancellationToken) { if (request.Claims == null || !request.Claims.Any()) { _logger.LogError("User is not authenticated"); throw new NotAuthenticatedException(Global.UserNotAuthenticated); } var userClaims = new UserClaims { UserIdentifier = _authorizationHelper.GetNameIdentifier(request.Claims), Roles = _authorizationHelper.GetRoles(request.Claims), LogicalGroups = (await _logicalPeopleGroupStore.GetLogicalGroups(request.Claims, cancellationToken)).Select(_ => _.Name).ToList() }; var result = await _notificationInstanceQueryRepository.Find(new FindNotificationInstanceParameter { Count = request.Count, Order = request.Order, OrderBy = request.OrderBy, StartIndex = request.StartIndex, User = userClaims }, cancellationToken); var content = new List <NotificationDetailsResult>(); foreach (var record in result.Content) { var callbackTxt = new Func <ICollection <PresentationElementInstance>, Localization.Translation>((t) => { if (t == null || !t.Any()) { return(null); } try { return(_translationHelper.Translate(t)); } catch (BadOperationExceptions) { return(null); } }); var name = callbackTxt(record.Names); var subject = callbackTxt(record.Subjects); content.Add(NotificationDetailsResult.ToDto(record, name, subject)); } return(new SearchResult <NotificationDetailsResult> { StartIndex = result.StartIndex, TotalLength = result.TotalLength, Count = result.Count, Content = content }); }