Ejemplo n.º 1
0
        public async Task SeedAsync()
        {
            _ctx.Database.EnsureCreated();

            StoreUser user = await _userManager.FindByEmailAsync("*****@*****.**");

            if (user == null)
            {
                user = new StoreUser
                {
                    FirstName = "Sebastian",
                    LastName  = "Ferrari",
                    Email     = "*****@*****.**",
                    UserName  = "******"
                };

                var result = await _userManager.CreateAsync(user, "Password1!");

                if (result != IdentityResult.Success)
                {
                    throw new InvalidOperationException("Could not create a new user in seeder");
                }
            }

            if (!_ctx.Licenses.Any())
            {
                // Need to create sample data
                var filepath = Path.Combine(_hosting.ContentRootPath, "Data/lic.json");
                var json     = File.ReadAllText(filepath);
                var licenses = JsonConvert.DeserializeObject <IEnumerable <CustomerDriverLicense> >(json);
                _ctx.Licenses.AddRange(licenses);
                _ctx.SaveChanges();
            }
        }
Ejemplo n.º 2
0
 public bool SaveAll()
 {
     return(_ctx.SaveChanges() > 0);
 }