public void Delete(Order 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 all OrderJunctions that // refer to this table List <OrderJunction> orderJunctionList = Database.OrderJunction .Where(o => o.OrderId == entity.Id).ToList(); OrderJunctionRepository orderJunctionRepo = new OrderJunctionRepository(Database); foreach (var orderJunction in orderJunctionList) { orderJunctionRepo.Delete(orderJunction); } Database.Remove(entity); }
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); }
public OrderRepository(PizzaStoreDBContext database) { Database = database ?? throw new ArgumentNullException(nameof(database)); orderJunctionRepo = new OrderJunctionRepository(database); pizzaJunctionRepo = new PizzaJunctionRepository(database); Database.Database.EnsureCreated(); }
public void Delete(PizzaJunction entity) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } // Need to remove any OrderJunction entities that // reference this PizzaJunction List <OrderJunction> orderJunctions = Database.OrderJunction .Where(o => o.PizzaId == entity.PizzaId).ToList(); OrderJunctionRepository orderJunctionRepo = new OrderJunctionRepository(Database); foreach (var orderJunction in orderJunctions) { orderJunctionRepo.Delete(orderJunction); } // Ensure the PizzaJunction exists within the database // GetById will throw an exception if not entity = GetById(entity.PizzaId, entity.IngredientId); Database.Remove(entity); }