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"); }
public void Can_save_and_load_category() { var category = new Category { Name = "Books", Description = "Description 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, 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.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.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)); }
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; }
public static Category ToEntity(this CategoryModel model, Category destination) { return Mapper.Map(model, destination); }
/// <summary> /// Update HasDiscountsApplied property (used for performance optimization) /// </summary> /// <param name="category">Category</param> public virtual void UpdateHasDiscountsApplied(Category category) { if (category == null) throw new ArgumentNullException("category"); category.HasDiscountsApplied = category.AppliedDiscounts.Count > 0; UpdateCategory(category); }
/// <summary> /// Inserts category /// </summary> /// <param name="category">Category</param> public virtual void InsertCategory(Category category) { if (category == null) throw new ArgumentNullException("category"); _categoryRepository.Insert(category); //cache _cacheManager.RemoveByPattern(CATEGORIES_PATTERN_KEY); _cacheManager.RemoveByPattern(PRODUCTCATEGORIES_PATTERN_KEY); //event notification _eventPublisher.EntityInserted(category); }
/// <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); }
protected 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 _aclService.Authorize(category) && //ACL _storeMappingService.Authorize(category)) //Store mapping { breadCrumb.Add(category); category = _categoryService.GetCategoryById(category.ParentCategoryId); } breadCrumb.Reverse(); return breadCrumb; }
/// <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); } }
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]; } } }
private void PrepareStoresMappingModel(CategoryModel model, Category category, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); model.AvailableStores = _storeService .GetAllStores() .Select(s => s.ToModel()) .ToList(); if (!excludeProperties) { if (category != null) { model.SelectedStoreIds = _storeMappingService.GetStoresIdsWithAccess(category); } else { model.SelectedStoreIds = new int[0]; } } }
protected void UpdatePictureSeoNames(Category category) { var picture = _pictureService.GetPictureById(category.PictureId); if (picture != null) _pictureService.SetSeoFilename(picture.Id, _pictureService.GetPictureSeName(category.Name)); }
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); } }
protected void SaveStoreMappings(Category category, CategoryModel model) { var existingStoreMappings = _storeMappingService.GetStoreMappings(category); var allStores = _storeService.GetAllStores(); foreach (var store in allStores) { if (model.SelectedStoreIds != null && model.SelectedStoreIds.Contains(store.Id)) { //new role if (existingStoreMappings.Count(sm => sm.StoreId == store.Id) == 0) _storeMappingService.InsertStoreMapping(category, store.Id); } else { //removed role var storeMappingToDelete = existingStoreMappings.FirstOrDefault(sm => sm.StoreId == store.Id); if (storeMappingToDelete != null) _storeMappingService.DeleteStoreMapping(storeMappingToDelete); } } }
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); } } }
protected void PrepareDiscountModel(CategoryModel model, Category category, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); var discounts = _discountService.GetAllDiscounts(DiscountType.AssignedToCategories, null, true); model.AvailableDiscounts = discounts.ToList(); if (!excludeProperties) { model.SelectedDiscountIds = category.AppliedDiscounts.Select(d => d.Id).ToArray(); } }