public async Task <IActionResult> PutModel(long id, EfModel model) { if (id != model.EfModelId) { return(BadRequest()); } _context.Entry(model).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ModelExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ElasticsearchProvider() { _elasticsearchMappingResolver = new ElasticsearchMappingResolver(); _elasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(Address), new ElasticsearchMappingAddress()); _elasticsearchContext = new ElasticsearchContext(ConnectionString, new ElasticsearchSerializerConfiguration(_elasticsearchMappingResolver, true, true)); _elasticsearchContext.TraceProvider = new ConsoleTraceProvider(); _entityFrameworkContext = new EfModel(); }
public void SaveToElasticsearchStateProvinceIfitDoesNotExist() { IElasticsearchMappingResolver elasticsearchMappingResolver = new ElasticsearchMappingResolver(); using (var elasticSearchContext = new ElasticsearchContext("http://localhost:9200/", new ElasticsearchSerializerConfiguration(elasticsearchMappingResolver, true, true))) { if (!elasticSearchContext.IndexTypeExists <StateProvince>()) { elasticSearchContext.TraceProvider = new ConsoleTraceProvider(); using (var databaseEfModel = new EfModel()) { int pointer = 0; const int interval = 20; bool firstRun = true; int length = databaseEfModel.StateProvince.Count(); while (pointer < length) { _stopwatch.Start(); var collection = databaseEfModel.StateProvince.OrderBy(t => t.StateProvinceID) .Skip(pointer) .Take(interval) .ToList <StateProvince>(); _stopwatch.Stop(); Console.WriteLine("Time taken for select {0} Address: {1}", interval, _stopwatch.Elapsed); _stopwatch.Reset(); _stopwatch.Start(); foreach (var item in collection) { var ee = item.CountryRegion.Name; elasticSearchContext.AddUpdateDocument(item, item.StateProvinceID); } if (firstRun) { elasticSearchContext.SaveChangesAndInitMappings(); firstRun = false; } else { elasticSearchContext.SaveChanges(); } _stopwatch.Stop(); Console.WriteLine("Time taken to insert {0} Address documents: {1}", interval, _stopwatch.Elapsed); _stopwatch.Reset(); pointer = pointer + interval; Console.WriteLine("Transferred: {0} items", pointer); } } } } }
public IActionResult PutModel(long id, EfModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (id != model.EfModelId) { return(BadRequest()); } var dbModel = _modelRepository.GetBy(source => source, predicate: m => m.EfModelId == id, disableTracking: false).FirstOrDefault(); dbModel.Email = model.Email; dbModel.AddressLine1 = model.AddressLine1; dbModel.AddressLine2 = model.AddressLine2; dbModel.BirthDate = model.BirthDate; dbModel.City = model.City; dbModel.Comments = model.Comments; dbModel.EyeColor = model.EyeColor; dbModel.Country = model.Country; dbModel.FirstName = model.FirstName; dbModel.HairColor = model.HairColor; dbModel.Height = model.Height; dbModel.LastName = model.LastName; dbModel.PhoneNo = model.PhoneNo; dbModel.Nationality = model.Nationality; dbModel.ShoeSize = model.ShoeSize; dbModel.Zip = model.Zip; _modelRepository.Update(dbModel); return(Ok()); }