本文整理汇总了C#中Nop.Core.Domain.Catalog.Category类的典型用法代码示例。如果您正苦于以下问题:C# Category类的具体用法?C# Category怎么用?C# Category使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Category类属于Nop.Core.Domain.Catalog命名空间,在下文中一共展示了Category类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Entities_with_same_id_but_different_type_should_not_be_equal
public void Entities_with_same_id_but_different_type_should_not_be_equal() {
int id = 10;
var p1 = new Product { Id = id };
var c1 = new Category { Id = id };
Assert.AreNotEqual(p1, c1, "Entities of different types should not be equal, even if they have the same id");
}
示例2: DeleteCategory
/// <summary>
/// Delete category
/// </summary>
/// <param name="category">Category</param>
public virtual void DeleteCategory(Category category)
{
if (category == null)
throw new ArgumentNullException("category");
category.Deleted = true;
UpdateCategory(category);
}
示例3: Can_save_and_load_category
public void Can_save_and_load_category()
{
var category = new Category
{
Name = "Books",
Description = "Description 1",
CategoryTemplateId = 1,
MetaKeywords = "Meta keywords",
MetaDescription = "Meta description",
MetaTitle = "Meta title",
ParentCategoryId = 2,
PictureId = 3,
PageSize = 4,
AllowCustomersToSelectPageSize = true,
PageSizeOptions = "4, 2, 8, 12",
PriceRanges = "1-3;",
ShowOnHomePage = false,
IncludeInTopMenu = true,
HasDiscountsApplied = true,
Published = true,
SubjectToAcl = true,
LimitedToStores = true,
Deleted = false,
DisplayOrder = 5,
CreatedOnUtc = new DateTime(2010, 01, 01),
UpdatedOnUtc = new DateTime(2010, 01, 02),
};
var fromDb = SaveAndLoadEntity(category);
fromDb.ShouldNotBeNull();
fromDb.Name.ShouldEqual("Books");
fromDb.Description.ShouldEqual("Description 1");
fromDb.CategoryTemplateId.ShouldEqual(1);
fromDb.MetaKeywords.ShouldEqual("Meta keywords");
fromDb.MetaDescription.ShouldEqual("Meta description");
fromDb.ParentCategoryId.ShouldEqual(2);
fromDb.PictureId.ShouldEqual(3);
fromDb.PageSize.ShouldEqual(4);
fromDb.AllowCustomersToSelectPageSize.ShouldEqual(true);
fromDb.PageSizeOptions.ShouldEqual("4, 2, 8, 12");
fromDb.PriceRanges.ShouldEqual("1-3;");
fromDb.ShowOnHomePage.ShouldEqual(false);
fromDb.IncludeInTopMenu.ShouldEqual(true);
fromDb.HasDiscountsApplied.ShouldEqual(true);
fromDb.Published.ShouldEqual(true);
fromDb.SubjectToAcl.ShouldEqual(true);
fromDb.LimitedToStores.ShouldEqual(true);
fromDb.Deleted.ShouldEqual(false);
fromDb.DisplayOrder.ShouldEqual(5);
fromDb.CreatedOnUtc.ShouldEqual(new DateTime(2010, 01, 01));
fromDb.UpdatedOnUtc.ShouldEqual(new DateTime(2010, 01, 02));
}
示例4: DeleteCategory
/// <summary>
/// Delete category
/// </summary>
/// <param name="category">Category</param>
public virtual void DeleteCategory(Category category)
{
if (category == null)
throw new ArgumentNullException("category");
category.Deleted = true;
UpdateCategory(category);
//set a ParentCategory property of the children to 0
var subcategories = GetAllCategoriesByParentCategoryId(category.Id);
foreach (var subcategory in subcategories)
{
subcategory.ParentCategoryId = 0;
UpdateCategory(subcategory);
}
}
示例5: Can_save_and_load_category_with_productCategories
public void Can_save_and_load_category_with_productCategories()
{
var category = new Category
{
Name = "Books",
Description = "Description 1",
MetaKeywords = "Meta keywords",
MetaDescription = "Meta description",
MetaTitle = "Meta title",
SeName = "SE name",
ParentCategoryId = 2,
PictureId = 3,
PageSize = 4,
AllowCustomersToSelectPageSize = true,
PageSizeOptions = "4, 2, 8, 12",
PriceRanges = "1-3;",
ShowOnHomePage = false,
Published = true,
Deleted = false,
DisplayOrder = 5,
CreatedOnUtc = new DateTime(2010, 01, 01),
UpdatedOnUtc = new DateTime(2010, 01, 02)
};
category.ProductCategories.Add
(
new ProductCategory
{
IsFeaturedProduct = true,
DisplayOrder = 1,
Product = new Product()
{
Name = "Name 1",
Published = true,
Deleted = false,
CreatedOnUtc = new DateTime(2010, 01, 01),
UpdatedOnUtc = new DateTime(2010, 01, 02)
}
}
);
var fromDb = SaveAndLoadEntity(category);
fromDb.ShouldNotBeNull();
fromDb.Name.ShouldEqual("Books");
fromDb.ProductCategories.ShouldNotBeNull();
(fromDb.ProductCategories.Count == 1).ShouldBeTrue();
fromDb.ProductCategories.First().IsFeaturedProduct.ShouldEqual(true);
}
示例6: GetCategoryBreadCrumb
private IList<Category> GetCategoryBreadCrumb(Category category)
{
if (category == null)
throw new ArgumentNullException("category");
var breadCrumb = new List<Category>();
while (category != null && //category is not null
!category.Deleted && //category is not deleted
category.Published) //category is published
{
breadCrumb.Add(category);
category = _categoryService.GetCategoryById(category.ParentCategoryId);
}
breadCrumb.Reverse();
return breadCrumb;
}
示例7: SaveCategoryAcl
protected void SaveCategoryAcl(Category category, CategoryModel model)
{
var existingAclRecords = _aclService.GetAclRecords(category);
var allCustomerRoles = _customerService.GetAllCustomerRoles(true);
foreach (var customerRole in allCustomerRoles)
{
if (model.SelectedCustomerRoleIds != null && model.SelectedCustomerRoleIds.Contains(customerRole.Id))
{
//new role
if (existingAclRecords.Count(acl => acl.CustomerRoleId == customerRole.Id) == 0)
_aclService.InsertAclRecord(category, customerRole.Id);
}
else
{
//removed role
var aclRecordToDelete = existingAclRecords.FirstOrDefault(acl => acl.CustomerRoleId == customerRole.Id);
if (aclRecordToDelete != null)
_aclService.DeleteAclRecord(aclRecordToDelete);
}
}
}
示例8: PrepareAclModel
private void PrepareAclModel(CategoryModel model, Category category, bool excludeProperties)
{
if (model == null)
throw new ArgumentNullException("model");
model.AvailableCustomerRoles = _customerService
.GetAllCustomerRoles(true)
.Select(cr => cr.ToModel())
.ToList();
if (!excludeProperties)
{
if (category != null)
{
model.SelectedCustomerRoleIds = _aclService.GetCustomerRoleIdsWithAccess(category);
}
else
{
model.SelectedCustomerRoleIds = new int[0];
}
}
}
示例9: LoadSpecsFilters
public virtual void LoadSpecsFilters(Category category,
ISpecificationAttributeService specificationAttributeService, IWebHelper webHelper,
IWorkContext workContext)
{
if (category == null)
throw new ArgumentNullException("category");
var alreadyFilteredOptions = GetAlreadyFilteredSpecs(specificationAttributeService, webHelper, workContext);
var notFilteredOptions = GetNotFilteredSpecs(category.Id,
specificationAttributeService, webHelper, workContext);
if (alreadyFilteredOptions.Count > 0 || notFilteredOptions.Count > 0)
{
this.Enabled = true;
this.AlreadyFilteredItems = alreadyFilteredOptions.ToList().Select(x =>
{
var item = new SpecificationFilterItem();
item.SpecificationAttributeName = x.SpecificationAttributeName;
item.SpecificationAttributeOptionName = x.SpecificationAttributeOptionName;
return item;
}).ToList();
this.NotFilteredItems = notFilteredOptions.ToList().Select(x =>
{
var item = new SpecificationFilterItem();
item.SpecificationAttributeName = x.SpecificationAttributeName;
item.SpecificationAttributeOptionName = x.SpecificationAttributeOptionName;
//filter URL
var alreadyFilteredOptionIds = GetAlreadyFilteredSpecOptionIds(webHelper);
if (!alreadyFilteredOptionIds.Contains(x.SpecificationAttributeOptionId))
alreadyFilteredOptionIds.Add(x.SpecificationAttributeOptionId);
string newQueryParam = GenerateFilteredSpecQueryParam(alreadyFilteredOptionIds);
string filterUrl = webHelper.ModifyQueryString(webHelper.GetThisPageUrl(true), QUERYSTRINGPARAM + "=" + newQueryParam, null);
filterUrl = ExcludeQueryStringParams(filterUrl, webHelper);
item.FilterUrl = filterUrl;
return item;
}).ToList();
//remove filter URL
string removeFilterUrl = webHelper.RemoveQueryString(webHelper.GetThisPageUrl(true), QUERYSTRINGPARAM);
removeFilterUrl = ExcludeQueryStringParams(removeFilterUrl, webHelper);
this.RemoveFilterUrl = removeFilterUrl;
}
else
{
this.Enabled = false;
}
}
示例10: UpdateCategory
/// <summary>
/// Updates the category
/// </summary>
/// <param name="category">Category</param>
public virtual void UpdateCategory(Category category)
{
if (category == null)
throw new ArgumentNullException("category");
//validate category hierarchy
var parentCategory = GetCategoryById(category.ParentCategoryId);
while (parentCategory != null)
{
if (category.Id == parentCategory.Id)
{
category.ParentCategoryId = 0;
break;
}
parentCategory = GetCategoryById(parentCategory.ParentCategoryId);
}
_categoryRepository.Update(category);
//cache
_cacheManager.RemoveByPattern(CATEGORIES_PATTERN_KEY);
_cacheManager.RemoveByPattern(PRODUCTCATEGORIES_PATTERN_KEY);
//event notification
_eventPublisher.EntityUpdated(category);
}
示例11: PrepareAclModel
protected virtual void PrepareAclModel(CategoryModel model, Category category, bool excludeProperties)
{
if (model == null)
throw new ArgumentNullException("model");
if (!excludeProperties && category != null)
model.SelectedCustomerRoleIds = _aclService.GetCustomerRoleIdsWithAccess(category).ToList();
var allRoles = _customerService.GetAllCustomerRoles(true);
foreach (var role in allRoles)
{
model.AvailableCustomerRoles.Add(new SelectListItem
{
Text = role.Name,
Value = role.Id.ToString(),
Selected = model.SelectedCustomerRoleIds.Contains(role.Id)
});
}
}
示例12: UpdateLocales
protected void UpdateLocales(Category category, CategoryModel model)
{
foreach (var localized in model.Locales)
{
_localizedEntityService.SaveLocalizedValue(category,
x => x.Name,
localized.Name,
localized.LanguageId);
_localizedEntityService.SaveLocalizedValue(category,
x => x.Description,
localized.Description,
localized.LanguageId);
_localizedEntityService.SaveLocalizedValue(category,
x => x.MetaKeywords,
localized.MetaKeywords,
localized.LanguageId);
_localizedEntityService.SaveLocalizedValue(category,
x => x.MetaDescription,
localized.MetaDescription,
localized.LanguageId);
_localizedEntityService.SaveLocalizedValue(category,
x => x.MetaTitle,
localized.MetaTitle,
localized.LanguageId);
//search engine name
var seName = category.ValidateSeName(localized.SeName, localized.Name, false);
_urlRecordService.SaveSlug(category, seName, localized.LanguageId);
}
}
示例13: PrepareAclModel
protected virtual void PrepareAclModel(CategoryModel model, Category category, bool excludeProperties)
{
if (model == null)
throw new ArgumentNullException("model");
model.AvailableCustomerRoles = _customerService
.GetAllCustomerRoles(true)
.Select(cr => cr.ToModel())
.ToList();
if (!excludeProperties)
{
if (category != null)
{
model.SelectedCustomerRoleIds = category.CustomerRoles.ToArray();
}
}
}
示例14: ResolveCategory
private Category ResolveCategory(string categoryName, Category parentCategory)
{
Category currentCategory = _categoryService.GetAllCategories(categoryName).FirstOrDefault();
if (currentCategory != null) return currentCategory;
currentCategory = new Category
{
Name = categoryName,
MetaTitle = categoryName,
MetaDescription = categoryName,
MetaKeywords = categoryName,
AllowCustomersToSelectPageSize = true,
HasDiscountsApplied = false,
CategoryTemplateId = 1,
//Description = categoryName,
DisplayOrder = 1,
IncludeInTopMenu = false,
PageSize = 8,
PageSizeOptions = "12,8,4",
ParentCategoryId = parentCategory != null ? parentCategory.Id : 0,
ShowOnHomePage = false,
SubjectToAcl = false,
LimitedToStores = false,
Published = true,
CreatedOnUtc = DateTime.UtcNow,
UpdatedOnUtc = DateTime.UtcNow
};
_categoryService.InsertCategory(currentCategory);
_urlRecordService.SaveSlug(currentCategory, currentCategory.ValidateSeName(categoryName, categoryName, true),
0);
return _categoryService.GetAllCategories(categoryName).First();
}
示例15: GetC5ProductCategories
private ICollection<Category> GetC5ProductCategories(C5Product c5Product)
{
var categories = new List<Category>();
foreach (var categoryName in c5Product.CategoryName.Split(','))
{
var existingCategories = _categoryService.GetAllCategories(categoryName, true);
if (existingCategories.Count > 1)
{
foreach (var category in existingCategories)
{
_categoryService.DeleteCategory(category);
}
}
if (existingCategories.Count > 0)
{
categories.Add(existingCategories.First());
}
else {
var category = new Category()
{
CreatedOnUtc = DateTime.UtcNow,
UpdatedOnUtc = DateTime.UtcNow,
Name = c5Product.CategoryName,
Published = true
};
_categoryService.InsertCategory(category);
categories.Add(category);
}
}
return categories;
}