//Todo Add try catch public bool Commit() { _logger.LogInformation($"Commit - Save all changes"); _db.SaveChanges(); return(true); //return db.SaveChanges() > 0; }
public async Task SeedAsync() { _islandDbContext.Database.EnsureCreated(); StoreUser user = await _userManager.FindByEmailAsync("*****@*****.**"); if (user == null) { user = new StoreUser { FirstName = "Koen", LastName = " Hos", Email = "*****@*****.**", UserName = "******" }; var result = await _userManager.CreateAsync(user, "P@ssw0rd!"); if (result != IdentityResult.Success) { throw new InvalidOperationException("Could not create new user in seeder"); } } if (!_islandDbContext.Elements.Any()) { //seed var file = Path.Combine(_hostingEnvironment.ContentRootPath, "../Aruba.Data/Elements.json"); var json = File.ReadAllText("../Aruba.Data/Elements.json"); var elements = JsonConvert.DeserializeObject <IEnumerable <Element> >(json); foreach (Element element in elements) { element.User = user; } _islandDbContext.Elements.AddRange(elements); _islandDbContext.SaveChanges(); } }
public int Commit() { return(db.SaveChanges()); }