本文整理汇总了C#中Product.AddCategory方法的典型用法代码示例。如果您正苦于以下问题:C# Product.AddCategory方法的具体用法?C# Product.AddCategory怎么用?C# Product.AddCategory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Product
的用法示例。
在下文中一共展示了Product.AddCategory方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyCategories
static void ApplyCategories(Product originalProduct, Product copiedProduct)
{
foreach (var productCategory in originalProduct.ProductCategories)
{
copiedProduct.AddCategory(productCategory.Category);
}
}
示例2: ApplyCategories
void ApplyCategories(Product originalProduct, Product copiedProduct)
{
foreach (var productCategory in originalProduct.ProductCategories)
{
var position = productCategoryOrder.NextPosition;
copiedProduct.AddCategory(productCategory.Category, position);
}
}
示例3: Should_delete_categories_that_are_no_longer_required
public void Should_delete_categories_that_are_no_longer_required()
{
var category11 = new Category { Id = 11 };
categoryRepository.Stub(r => r.GetById(11)).Return(category11);
var category14 = new Category { Id = 14 };
var category15 = new Category { Id = 15 };
var product = new Product();
product.AddCategory(category14);
product.AddCategory(category15);
context.SetProduct(product);
context.ProductViewData.CategoryIds.Add(11);
contributor.ContributeTo(context);
product.ProductCategories.Count.ShouldEqual(1);
product.ProductCategories[0].Category.Id.ShouldEqual(11);
}
示例4: Should_add_new_categories_remove_old_ones_and_leave_existing
public void Should_add_new_categories_remove_old_ones_and_leave_existing()
{
var category14 = new Category { Id = 14 }; // delete this one
var category15 = new Category { Id = 15 }; // leave this one
var category16 = new Category { Id = 16 }; // add this one
categoryRepository.Stub(r => r.GetById(16)).Return(category16);
var product = new Product();
product.AddCategory(category14);
product.AddCategory(category15);
context.SetProduct(product);
context.ProductViewData.CategoryIds.Add(15);
context.ProductViewData.CategoryIds.Add(16);
contributor.ContributeTo(context);
product.ProductCategories.Count.ShouldEqual(2);
product.ProductCategories[0].Category.ShouldBeTheSameAs(category15);
product.ProductCategories[1].Category.ShouldBeTheSameAs(category16);
}
示例5: Should_be_able_to_create_a_product
public void Should_be_able_to_create_a_product()
{
var product = new Product
{
Name = "Sophie",
Description = "A nice sloop",
Price = new Money(86.22M),
IsActive = true,
Position = 1
};
var size = new Size
{
Name = "10cm"
};
var image = new Image
{
Description = "sophie1.jpg",
FileName = new Guid("3DF66C48-ED24-4004-A258-8CD9D56A18C6")
};
InSession(session =>
{
var category = session.Get<Category>(categoryId);
using (DomainEvent.TurnOff())
{
product.AddSize(size);
}
product.AddCategory(category);
product.AddProductImage(image, 1);
session.SaveOrUpdate(product);
});
// now delete the image
InSession(session =>
{
var sameProduct = session.Get<Product>(product.Id);
var productImage = sameProduct.ProductImages[0];
sameProduct.ProductImages.Remove(productImage);
});
}
示例6: CreateProduct
static Product CreateProduct(Category category)
{
var product = new Product
{
Id = 144,
Name = "Super Widget",
Description = "Some product description",
Price = new Money(34.56M),
Position = 6,
Weight = 345,
IsActive = true
};
product.AddSize(new Size
{
Id = 21,
IsActive = true,
IsInStock = true,
Name = "Small"
});
product.AddSize(new Size
{
Id = 22,
IsActive = true,
IsInStock = true,
Name = "Medium"
});
product.AddCategory(category, 0);
product.AddProductImage(new Image { Id = 3 }, 1);
return product;
}