public void AddOrder(Order model) { foreach (var item in model.Items) { item.Product = context.Products.Find(item.Product.Id); } context.Add(model); }
public void AddEntity(object model) { try { _context.Add(model); } catch (Exception ex) { _logger.LogError($"Failed to save new entity {ex}"); } }
public async Task SeedAsync() { Context.Database.EnsureCreated(); UserShop user = await this.userManager.FindByEmailAsync("*****@*****.**"); if (user == null) { user = new UserShop { FirstName = "Ahmad", LastName = "Haseeb", Email = "*****@*****.**", UserName = "******" }; var result = await this.userManager.CreateAsync(user, "P@ssw0rd!"); if (result != IdentityResult.Success) { throw new InvalidOperationException("Could not create new user In Seeder"); } } if (!Context.Products.Any()) { string filepath = Path.Combine(hosting.ContentRootPath, "Data/art.json"); string json = File.ReadAllText(filepath); var products = JsonConvert.DeserializeObject <IEnumerable <Product> >(json); Context.AddRange(products); Order order = new Order() { User = user, OrderDate = DateTime.UtcNow, OrderNumber = "12345", Items = new List <OrderItem>() { new OrderItem() { Product = products.First(), Quantity = 5, UnitPrice = products.First().Price } } }; Context.Add(order); } Context.SaveChanges(); }
public void AddEntity(object order) { _context.Add(order); }
public void AddEntity(object model) { dutchContext.Add(model); }
public void AddEntity(object player) { _ctx.Add(player); }
public void AddEntity(Order model) { _context.Add(model); }
public void AddEntity(object model) { _ctx.Add(model); //The context can work out which type the object is and save it appropriately. }
public void AddEntity(object entity) { _ctx.Add(entity); }
public void AddEntity(object model) { // Pushes into context, but does not commit/save. _ctx.Add(model); }
public async Task SeedAsync() { //if (_hosting.IsDevelopment()) //{ // _ctx.Database.EnsureDeleted(); //kill the database?? Here we goooooooo! //} _ctx.Database.EnsureCreated(); //Check that the database actually exists StoreUser user = await _manager.FindByEmailAsync("*****@*****.**"); if (user == null) { user = new StoreUser() { FirstName = "Jason", LastName = "Thomson", Email = "*****@*****.**", UserName = "******" }; var result = await _manager.CreateAsync(user, "P@ssw0rd!"); if (result != IdentityResult.Success) { throw new InvalidOperationException("Unable to create user in seeder."); } } if (!_ctx.Products.Any()) //Make sure there are in fact existing products { //Create sample data var filepath = Path.Combine(_hosting.ContentRootPath, "Data/art.json"); var json = File.ReadAllText(filepath); var products = JsonConvert.DeserializeObject <IEnumerable <Product> >(json); _ctx.Products.AddRange(products); // add orders var order = _ctx.Orders.Where(o => o.Id == 1).FirstOrDefault(); if (order != null) { order.User = user; order.Items = new List <OrderItem>() { new OrderItem() { Product = products.First(), Quantity = 5, UnitPrice = products.First().Price } }; } else { _ctx.Add(new Order() { OrderDate = DateTime.UtcNow, OrderNumber = "TestJace", Items = new List <OrderItem>() { new OrderItem() { Product = products.First(), Quantity = 5, UnitPrice = products.First().Price } } }); } _ctx.SaveChanges(); } }
public void AddEntity(Object model) { _context.Add(model); }
public void AddModel(object data) { context.Add(data); }
public void AddEntity(object model) { context.Add(model); }
public void AddEntity(object data) { _context.Add(data); }
public void AddEntity(object model) { _ctx.Add(model); }
public void AddEntity(object model) { _logger.LogInformation("AddEntity was called"); _ctx.Add(model); }