public async Task Seed() { _ctx.Database.EnsureCreated(); StoreUser user = await _userManager.FindByEmailAsync("*****@*****.**"); if (user == null) { user = new StoreUser() { FirstName = "Patryk", LastName = "Walkowiak", Email = "*****@*****.**", UserName = "******" }; var result = await _userManager.CreateAsync(user, "Haslo.123"); if (result != IdentityResult.Success) { throw new InvalidOperationException("Could not create new user in seeder!"); } } if (!_ctx.Questions.Any()) { //Przykladowa zawartosc var path = Path.Combine(_hosting.ContentRootPath, "Data/quest.json"); var json = File.ReadAllText(path); var questions = JsonConvert.DeserializeObject <IEnumerable <Question> >(json); _ctx.Questions.AddRange(questions); _ctx.SaveChanges(); } }
public bool SaveAll() { return(ctx.SaveChanges() > 0); }