public async Task <int> GetProducts(bool getAll = false, string dateTime = "") { int count; try { var httpRequestBuilder = new HttpRequestBuilder().WithMethod(HttpMethod.Get) .WithRequestUri($"{Program.AppSettings.ApiUrl}{Program.AppSettings.ProductDetailsEndPoint}") .AddHeader(Program.AppSettings.ApiKeyName, Program.AppSettings.ApiKey) .AddQueryParameter("maxResults", 30000); if (!getAll) { httpRequestBuilder.AddQueryParameter("changedSince", dateTime); } var httpRequestMessage = httpRequestBuilder.Build(); Logger.Log($"Fetching from {httpRequestMessage.RequestUri}"); var stopwatch = Stopwatch.StartNew(); var response = await m_client.SendAsync(httpRequestMessage); Logger.Log($"Request duration: {stopwatch.Elapsed}"); stopwatch.Stop(); response.EnsureSuccessStatusCode(); Logger.Log($"{response.StatusCode}: {response.ReasonPhrase}"); var content = await response.Content.ReadAsStringAsync(); var alcoholicEntities = JsonConvert.DeserializeObject <List <AlcoholicEntity> >(content); count = alcoholicEntities.Count; Logger.Log($"Retrieved count: {count}"); if (!getAll) { await UpdateProducts(alcoholicEntities); } else { await AddAllToDb(alcoholicEntities); } } catch (Exception e) { Logger.Log($"{e.Message}\n{e.StackTrace}\nInner Exception:\n{e?.InnerException?.Message}\n{e?.InnerException?.StackTrace}"); return(-1); } return(0); }