Example #1
0
        public ItemController(PackContext context)
        {
            _context = context;

            if (_context.PackItems.Count() == 0)
            {
                // Create a new PackItem if collection is empty,
                // which means you can't delete all PackItem.
                _context.PackItems.Add(new PackItem {
                    Description = "Item1"
                });
                _context.SaveChanges();
            }
        }
Example #2
0
        public ListController(PackContext context)
        {
            _context = context;

            if (_context.PackLists.Count() == 0)
            {
                // Create a new PackList if collection is empty,
                // which means you can't delete all PackList.
                PackList packList1 = new PackList {
                    Description = "List1"
                };
                packList1.PackItems.Add(new PackItem {
                    Description = "PackItem1ListItem1", Weight = 25, Volume = 30
                });
                packList1.PackItems.Add(new PackItem {
                    Description = "PackItem1ListItem2", Weight = 5, Volume = 10
                });

                _context.PackLists.Add(packList1);

                _context.SaveChanges();
            }
        }