Beispiel #1
0
 public static void InitializeMapper(PizzaStoreDBContext database)
 {
     Database          = database ?? throw new ArgumentNullException(nameof(database));
     inventoryRepo     = new dbr.InventoryJunctionRepository(database);
     ingredientRepo    = new dbr.IngredientRepository(database);
     orderJunctionRepo = new dbr.OrderJunctionRepository(database);
     pizzaRepo         = new dbr.PizzaJunctionRepository(database);
 }
Beispiel #2
0
        public OrderRepository(PizzaStoreDBContext database)
        {
            Database          = database ?? throw new ArgumentNullException(nameof(database));
            orderJunctionRepo = new OrderJunctionRepository(database);
            pizzaJunctionRepo = new PizzaJunctionRepository(database);

            Database.Database.EnsureCreated();
        }
Beispiel #3
0
        public void Delete(Ingredient entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            // Ensure the entity exists within the
            //  database. GetById will throw an
            //  exception for us if it does not
            entity = GetById(entity.Id);

            // Need to remove ingredient from the InventoryJunction
            //  and PizzaJunction tables
            // Find all InventoryJunctions that contain this ingredient
            List <InventoryJunction> inventoryList = Database.InventoryJunction
                                                     .Where(inv => inv.IngredientId == entity.Id).ToList();
            // For each inventory with ingredient in it, remove
            //  it from the InventoryJunction table
            InventoryJunctionRepository inventoryRepo = new InventoryJunctionRepository(Database);

            foreach (var inventoryJunction in inventoryList)
            {
                inventoryRepo.Delete(inventoryJunction);
            }
            // Now do the same for the PizzaJunction table
            List <PizzaJunction> pizzaList = Database.PizzaJunction
                                             .Where(pizza => pizza.IngredientId == entity.Id).ToList();
            PizzaJunctionRepository pizzaRepo = new PizzaJunctionRepository(Database);

            foreach (var pizzaJunction in pizzaList)
            {
                pizzaRepo.Delete(pizzaJunction);
            }

            Database.Remove(GetById(entity.Id));
        }