public async Task <IActionResult> GetUserClient(int id)
        {
            if (_memoryCache.TryGetValue(string.Format(GET_USER_CLIENT_CACHE, id), out GetUserViewModel client))
            {
                return(Ok(client));
            }

            var query  = new SearchClientQuery(id);
            var result = await _mediator.Send(query);

            if (result == null)
            {
                return(NotFound());
            }

            var memoryCacheOptions = new MemoryCacheEntryOptions
            {
                //Daqui a 1h, irei invalidar a cache
                AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(3600),

                //Tempo decorrido sem requisições => Passa 20 minutos seguidos sem nenhuma requisição
                SlidingExpiration = TimeSpan.FromSeconds(1200)
            };

            _memoryCache.Set(string.Format(GET_USER_CLIENT_CACHE, id), result, memoryCacheOptions);

            return(Ok(result));
        }
        public async Task <QueryExecutionResult <Page <ClientEntity> > > HandleAsync(SearchClientQuery query)
        {
            var clients = await _repository.PageAsync(new ClientLikeSpecification(query.ClientNo), query.PageSize, query.PageNo);

            var queryExecutionResult = new QueryExecutionResult <Page <ClientEntity> >(clients);

            return(queryExecutionResult);
        }
        public async Task <IActionResult> Index(SearchClientQuery query)
        {
            _builder.Link(Url.AppLink(RelTypes.Breadcrumb, "Clients", nameof(Index), nameof(ClientController)))
            .Link(Url.AppLink(RelTypes.Nav, "Employees", nameof(EmployeeController.Index), nameof(EmployeeController)))
            .Link(Url.AppLink(RelTypes.Nav, "Clients", nameof(ClientController.Index), nameof(ClientController)))
            .Link(Url.AppLink(RelTypes.Action, "+ new client", nameof(ClientController.Add), nameof(ClientController)))
            .Link(Url.AppLink(RelTypes.Self, "Clients", nameof(Index), nameof(ClientController)));

            var commandExecutionResult = await _clientService.HandleAsync(query);

            if (commandExecutionResult.HasError == false)
            {
                if (commandExecutionResult.Result.PageNo > commandExecutionResult.Result.FirstPageNo)
                {
                    _builder.Link(Url.AppLink(RelTypes.First, "First", nameof(Index), nameof(ClientController), new SearchClientQuery(query.ClientNo, commandExecutionResult.Result.FirstPageNo)))
                    .Link(Url.AppLink(RelTypes.Prev, "Previous", nameof(Index), nameof(ClientController), new SearchClientQuery(query.ClientNo, commandExecutionResult.Result.PageNo - 1)));
                }

                if (commandExecutionResult.Result.PageNo < commandExecutionResult.Result.LastPageNo)
                {
                    _builder.Link(Url.AppLink(RelTypes.Next, "Next", nameof(Index), nameof(ClientController), new SearchClientQuery(query.ClientNo, commandExecutionResult.Result.PageNo + 1)))
                    .Link(Url.AppLink(RelTypes.Last, "Last", nameof(Index), nameof(ClientController), new SearchClientQuery(query.ClientNo, commandExecutionResult.Result.LastPageNo)));
                }

                foreach (var client in commandExecutionResult.Result)
                {
                    _builder.Embedded(RelTypes.Row)
                    .Property(nameof(client.Name), "Name", client.Name)
                    .Property(nameof(client.ClientNo), "Client No", client.ClientNo)
                    .Property(nameof(client.Created), "Created", client.Created)
                    .Link(Url.AppLink(RelTypes.Self, "Name", nameof(Edit), nameof(ClientController), new UpdateClientQuery(client.ClientId)));
                }
            }

            var vm = _builder.Build()
                     .ToGridVm();

            return(View("GridView", vm));
        }