Пример #1
0
        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 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);
        }