public async Task SeedAsync() { _context.Database.EnsureCreated(); var user = await _userManager.FindByEmailAsync("*****@*****.**"); if (user == null) { user = new StoreUser { FirstName = "test", LastName = "test", Email = "*****@*****.**", UserName = "******" }; var result = await _userManager.CreateAsync(user, "P@ssw0rd!"); if (result != IdentityResult.Success) { throw new Exception("Could not create the user"); } } if (!_context.Products.Any()) { var filePath = Path.Combine(_hostingEnvironment.ContentRootPath, "Data/art.json"); var json = File.ReadAllText(filePath); var products = JsonConvert.DeserializeObject <IEnumerable <Product> >(json); _context.Products.AddRange(products); var order = _context.Orders.FirstOrDefault(o => o.Id == 1); if (order != null) { order.User = user; order.Items = new List <OrderItem>() { new OrderItem { Product = products.First(), Quantity = 5, UnitPrice = products.First().Price } }; } _context.SaveChanges(); } }
public bool SaveAll() { return(_ctx.SaveChanges() > 0); }