public async Task <IActionResult> Execute(JObject jObj, string subject)
        {
            if (jObj == null)
            {
                throw new ArgumentNullException(nameof(jObj));
            }

            var href         = "/" + Constants.RouteNames.Messages + "/" + Constants.RouteNames.Search;
            var request      = _requestBuilder.GetSearchMessages(jObj);
            var searchResult = await _repository.Search(request);

            _halResponseBuilder.AddLinks(l => l.AddSelf(href));
            if (searchResult.Content == null || !searchResult.Content.Any())
            {
                return(new OkObjectResult(_halResponseBuilder.Build()));
            }

            foreach (var message in searchResult.Content)
            {
                _messageEnricher.Enrich(_halResponseBuilder, message);
            }

            double r       = (double)searchResult.TotalResults / (double)request.Count;
            var    nbPages = Math.Ceiling(r);

            nbPages = nbPages == 0 ? 1 : nbPages;
            for (var page = 1; page <= nbPages; page++)
            {
                _halResponseBuilder.AddLinks(l => l.AddOtherItem("navigation", new Dtos.Link(href, page.ToString())));
            }

            return(new OkObjectResult(_halResponseBuilder.Build()));
        }
예제 #2
0
        public async Task <IActionResult> Execute(string id, string subject)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                throw new ArgumentNullException(nameof(id));
            }

            if (string.IsNullOrWhiteSpace(subject))
            {
                throw new ArgumentNullException(nameof(subject));
            }

            var message = await _messageRepository.Get(id);

            if (message == null)
            {
                return(new NotFoundResult());
            }

            _halResponseBuilder.AddLinks(l => l.AddSelf("/" + Constants.RouteNames.Messages + "/" + id));
            _messageEnricher.Enrich(_halResponseBuilder, message);
            return(new OkObjectResult(_halResponseBuilder.Build()));
        }