public async Task <IActionResult> Get([FromQuery] int pageSize = 10, [FromQuery] int pageIndex = 0) { var result = await _itemService.GetItemsAsync(); var totalItems = result.Count(); var itemsOnPage = result.OrderBy(c => c.Name) .Skip(pageSize * pageIndex) .Take(pageSize); var hateoasResults = new List <ItemHateoasResponse>(); foreach (var itemResponse in itemsOnPage) { var hateoasResult = new ItemHateoasResponse { Data = itemResponse }; await _linksService.AddLinksAsync(hateoasResult); hateoasResults.Add(hateoasResult); } var model = new PaginatedItemResponseModel <ItemHateoasResponse>( pageIndex, pageSize, totalItems, hateoasResults); return(Ok(model)); }
public async Task <IActionResult> GetById(Guid id) { var result = await _itemService.GetItemAsync(new GetItemRequest { Id = id }); var hateoasResult = new ItemHateoasResponse { Data = result }; await _linksService.AddLinksAsync(hateoasResult); return(Ok(hateoasResult)); }
public async Task <IActionResult> GetById(Guid id) { var result = await _mediator.Send(new GetItemCommand { Id = id }); var hateoasResult = new ItemHateoasResponse { Data = result }; await _linksService.AddLinksAsync(hateoasResult); return(Ok(hateoasResult)); }
public async Task <IActionResult> Put(Guid id, EditItemRequest request) { request.Id = id; var result = await _itemService.EditItemAsync(request, CancellationToken.None); var hateoasResult = new ItemHateoasResponse { Data = result }; await _linksService.AddLinksAsync(hateoasResult); return(Ok(hateoasResult)); }
public async Task <IActionResult> Put(Guid id, EditItemCommand request) { request.Id = id; var result = await _mediator.Send(request); var hateoasResult = new ItemHateoasResponse { Data = result }; await _linksService.AddLinksAsync(hateoasResult); return(Ok(hateoasResult)); }