예제 #1
0
 //Todo Add try catch
 public bool Commit()
 {
     _logger.LogInformation($"Commit - Save all changes");
     _db.SaveChanges();
     return(true);
     //return db.SaveChanges() > 0;
 }
예제 #2
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();
            }
        }
예제 #3
0
 public int Commit()
 {
     return(db.SaveChanges());
 }