Exemple #1
0
        private async Task Import(string requestUri, bool hasGarden)
        {
            client.DefaultRequestHeaders.Accept.Clear();

            int CurrentPage = 1;
            int TotalPage   = int.MaxValue;

            while (CurrentPage < TotalPage)
            {
                var stringTask = client.GetStringAsync(requestUri + CurrentPage.ToString());
                var msg        = await stringTask;

                Response resp = JsonConvert.DeserializeObject <Response>(msg);

                if (resp != null && resp.Objects != null)
                {
                    foreach (House house in resp.Objects)
                    {
                        Makelaar makelaar = new Makelaar
                        {
                            MakelaarId           = house.MakelaarId,
                            MakelaarName         = house.MakelaarNaam,
                            HouseCount           = hasGarden ? 0 : 1,
                            HouseWithGardenCount = hasGarden ? 1 : 0
                        };

                        await makelaarRepository.InsertOrUpdateMakelaar(makelaar);
                    }
                }

                TotalPage   = resp.Paging.AantalPaginas;
                CurrentPage = resp.Paging.HuidigePagina + 1;
                Task.Delay(600).Wait(); // approximately 100 requests per minute are allowed
            }
        }
 private async Task AddMakelaar(Makelaar item)
 {
     try
     {
         await context.Makelaars.InsertOneAsync(item);
     }
     catch (Exception ex)
     {
         // log or manage the exception
         throw ex;
     }
 }
 private async Task UpdateMakelaar(Makelaar item)
 {
     try
     {
         // ReplaceOneAsync
         await context.Makelaars.FindOneAndReplaceAsync(x => x.MakelaarId == item.MakelaarId, item);
     }
     catch (Exception ex)
     {
         // log or manage the exception
         throw ex;
     }
 }
 private Makelaar GetMakelaar(Makelaar item)
 {
     try
     {
         List <Makelaar> l = context.Makelaars.Find(x => x.MakelaarId == item.MakelaarId).ToListAsync().Result;
         if (l.Count > 0)
         {
             return(l.First());
         }
     }
     catch (Exception ex)
     {
         logger.LogWarn("Makelaar Repository seems to be empty.");
     }
     return(null);
 }
        public async Task InsertOrUpdateMakelaar(Makelaar item)
        {
            Makelaar temp = GetMakelaar(item);

            if (temp == null)
            {
                await AddMakelaar(item);

                return;
            }

            item.HouseCount           += temp.HouseCount;
            item.HouseWithGardenCount += temp.HouseWithGardenCount;
            item.InternalId            = temp.InternalId;

            await UpdateMakelaar(item);
        }