Exemplo n.º 1
0
        public void AddOrder(Order model)
        {
            foreach (var item in model.Items)
            {
                item.Product = context.Products.Find(item.Product.Id);
            }

            context.Add(model);
        }
Exemplo n.º 2
0
 public void AddEntity(object model)
 {
     try
     {
         _context.Add(model);
     }
     catch (Exception ex)
     {
         _logger.LogError($"Failed to save new entity {ex}");
     }
 }
Exemplo n.º 3
0
        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();
        }
Exemplo n.º 4
0
 public void AddEntity(object order)
 {
     _context.Add(order);
 }
Exemplo n.º 5
0
 public void AddEntity(object model)
 {
     dutchContext.Add(model);
 }
Exemplo n.º 6
0
 public void AddEntity(object player)
 {
     _ctx.Add(player);
 }
Exemplo n.º 7
0
 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.
 }
Exemplo n.º 9
0
 public void AddEntity(object entity)
 {
     _ctx.Add(entity);
 }
Exemplo n.º 10
0
 public void AddEntity(object model)
 {
     // Pushes into context, but does not commit/save.
     _ctx.Add(model);
 }
Exemplo n.º 11
0
        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();
            }
        }
Exemplo n.º 12
0
 public void AddEntity(Object model)
 {
     _context.Add(model);
 }
Exemplo n.º 13
0
 public void AddModel(object data)
 {
     context.Add(data);
 }
Exemplo n.º 14
0
 public void AddEntity(object model)
 {
     context.Add(model);
 }
Exemplo n.º 15
0
 public void AddEntity(object data)
 {
     _context.Add(data);
 }
Exemplo n.º 16
0
 public void AddEntity(object model)
 {
     _ctx.Add(model);
 }
Exemplo n.º 17
0
 public void AddEntity(object model)
 {
     _logger.LogInformation("AddEntity was called");
     _ctx.Add(model);
 }