Search code examples
c#listasp.net-web-apimicroservices

Iterate through Response<List><KVInfoModel>>>$"{_applicationUris.GranularKVInfo}/{_KVlId}/kv");


I am trying to iterate through a variable which is set through a response and filter it. I want to filter based on contact type. Is this possible? any suggestions are welcome.

//Response class

    public class Response<T> : Response
        {
            public Response();

            public T Content { get; set; }
        }

private async Task<string> GetKVValueAsync()
        {
     var KVContactInformation = await _restServiceClient.GetAsync<Response<List<KVInfoModel>>>($"{_applicationUris.GranularKVInfo}/{_KVlId}/kv");

                List<KVInfoModel> TestList = new List<KVInfoModel>();

                TestList = KVContactInformation.Where(Xyz => xyz.contactType == "Sample");

                return TestList();
}

Solution

  • You can use

    var KVContactInformation = await _restServiceClient.GetAsync<Response<List<KVInfoModel>>>($"{_applicationUris.GranularKVInfo}/{_KVlId}/kv"); 
    List<KVInfoModel> testList = KVContactInformation.Content.Where(Xyz => xyz.contactType == "Sample");
    return testList;