Esempio n. 1
0
        public async Task Import(HousePrice record)
        {
            await _mongoContext.ExecuteActionAsync <HousePrice>("Transactions", async (collection) =>
            {
                record.Postcode  = record.Postcode.Replace(" ", String.Empty);
                var locationData = _postcodeLookup.GetByPostcode(record.Postcode);
                record.Location  = locationData?.Latitude != null && locationData?.Longitude != null
                    ? new Location(locationData?.Latitude, locationData?.Longitude)
                    : null;

                try
                {
                    await collection.InsertOneAsync(record);
                }
                catch (MongoException ex)
                {
                    Log.Warning(ex.Message);
                    throw;
                }
            });
        }
Esempio n. 2
0
        public static async Task AddTransferDateIndex(IMongoContext _mongoContext)
        {
            var housePriceBuilder = Builders <HousePrice> .IndexKeys;
            var indexModel        = new CreateIndexModel <HousePrice>(housePriceBuilder.Ascending(x => x.TransferDate),
                                                                      new CreateIndexOptions()
            {
                Name = "TransferDateIndex"
            });

            await _mongoContext.ExecuteActionAsync <HousePrice>("Transactions",
                                                                async (collection) =>
            {
                Log.Information("Checking TransferDateIndex");
                if (!await IndexExists(_mongoContext, "TransferDateIndex"))
                {
                    Log.Information("Creating TransferDateIndex");
                    await collection.Indexes.CreateOneAsync(indexModel).ConfigureAwait(false);
                }
            });
        }