public async Task <IActionResult> Execute(JObject jObj, string subject) { if (jObj == null) { throw new ArgumentNullException(nameof(jObj)); } var href = "/" + Constants.RouteNames.Shops + "/" + Constants.RouteNames.Search; var request = _requestBuilder.GetSearchShops(jObj); request.Subjects = new[] { subject }; var searchResult = await _repository.Search(request); if (searchResult.Content == null || !searchResult.Content.Any()) { return(new NotFoundResult()); } _halResponseBuilder.AddLinks(l => l.AddSelf(href)); foreach (var shop in searchResult.Content) { _shopEnricher.Enrich(_halResponseBuilder, shop); } 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())); }
public async Task <IActionResult> Execute() { var shops = await _repository.Get(); _halResponseBuilder.AddLinks(l => l.AddSelf("/" + Constants.RouteNames.Shops)); foreach (var shop in shops) { _shopEnricher.Enrich(_halResponseBuilder, shop); } return(new OkObjectResult(_halResponseBuilder.Build())); }
public async Task <IActionResult> Execute(string id) { if (string.IsNullOrWhiteSpace(id)) { throw new ArgumentNullException(nameof(id)); } var shop = await _repository.Get(id); if (shop == null) { return(new NotFoundResult()); } _halResponseBuilder.AddLinks(l => l.AddSelf("/" + Constants.RouteNames.Shops + "/" + id)); _shopEnricher.Enrich(_halResponseBuilder, shop); return(new OkObjectResult(_halResponseBuilder.Build())); }
public async Task <IActionResult> Execute(string subject) { if (string.IsNullOrWhiteSpace(subject)) { throw new ArgumentNullException(nameof(subject)); } var shops = await _repository.Search(new SearchShopsParameter { Subjects = new[] { subject } }); _halResponseBuilder.AddLinks(l => l.AddSelf("/" + Constants.RouteNames.Shops + "/" + Constants.RouteNames.Me)); foreach (var shop in shops.Content) { _shopEnricher.Enrich(_halResponseBuilder, shop); } return(new OkObjectResult(_halResponseBuilder.Build())); }