protected void AdjustCrossSellLinking(int firstProductId, int secondProductId, CrossSellState crossSellState) { RelatedProduct toReleatedProduct = RelatedProductDataSource.Load(firstProductId, secondProductId); RelatedProduct fromReleatedProduct = RelatedProductDataSource.Load(secondProductId, firstProductId); switch (crossSellState) { case CrossSellState.Unlinked: if (toReleatedProduct != null) { toReleatedProduct.Delete(); } if (fromReleatedProduct != null) { fromReleatedProduct.Delete(); } break; case CrossSellState.CrossLinked: if (toReleatedProduct == null) { toReleatedProduct = new RelatedProduct(firstProductId, secondProductId); toReleatedProduct.Save(); } if (fromReleatedProduct == null) { fromReleatedProduct = new RelatedProduct(secondProductId, firstProductId); fromReleatedProduct.Save(); } break; case CrossSellState.LinksTo: if (toReleatedProduct == null) { toReleatedProduct = new RelatedProduct(firstProductId, secondProductId); toReleatedProduct.Save(); } if (fromReleatedProduct != null) { fromReleatedProduct.Delete(); } break; case CrossSellState.LinkedFrom: if (toReleatedProduct != null) { toReleatedProduct.Delete(); } if (fromReleatedProduct == null) { fromReleatedProduct = new RelatedProduct(secondProductId, firstProductId); fromReleatedProduct.Save(); } break; } }