/// <summary> /// Deletes a manufacturer /// </summary> /// <param name="manufacturer">Manufacturer</param> public virtual void DeleteManufacturer(Manufacturer manufacturer) { if (manufacturer == null) throw new ArgumentNullException("manufacturer"); manufacturer.Deleted = true; UpdateManufacturer(manufacturer); }
public void Can_save_and_load_manufacturer() { var manufacturer = new Manufacturer { Name = "Name", Description = "Description 1", ManufacturerTemplateId = 1, MetaKeywords = "Meta keywords", MetaDescription = "Meta description", MetaTitle = "Meta title", PictureId = 3, PageSize = 4, AllowCustomersToSelectPageSize = true, PageSizeOptions = "4, 2, 8, 12", PriceRanges = "1-3;", 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(manufacturer); fromDb.ShouldNotBeNull(); fromDb.Name.ShouldEqual("Name"); fromDb.Description.ShouldEqual("Description 1"); fromDb.ManufacturerTemplateId.ShouldEqual(1); fromDb.MetaKeywords.ShouldEqual("Meta keywords"); fromDb.MetaDescription.ShouldEqual("Meta description"); 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.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)); }
public void Can_save_and_load_manufacturer_with_productManufacturers() { var manufacturer = new Manufacturer { Name = "Name", Description = "Description 1", MetaKeywords = "Meta keywords", MetaDescription = "Meta description", MetaTitle = "Meta title", SeName = "SE name", PictureId = 3, PageSize = 4, AllowCustomersToSelectPageSize = true, PageSizeOptions = "4, 2, 8, 12", PriceRanges = "1-3;", Published = true, Deleted = false, DisplayOrder = 5, CreatedOnUtc = new DateTime(2010, 01, 01), UpdatedOnUtc = new DateTime(2010, 01, 02) }; manufacturer.ProductManufacturers.Add ( new ProductManufacturer { 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(manufacturer); fromDb.ShouldNotBeNull(); fromDb.Name.ShouldEqual("Name"); fromDb.ProductManufacturers.ShouldNotBeNull(); (fromDb.ProductManufacturers.Count == 1).ShouldBeTrue(); fromDb.ProductManufacturers.First().IsFeaturedProduct.ShouldEqual(true); }
protected virtual void PrepareDiscountModel(ManufacturerModel model, Manufacturer manufacturer, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); model.AvailableDiscounts = _discountService .GetAllDiscounts(DiscountType.AssignedToManufacturers, showHidden: true) .Select(d => d.ToModel()) .ToList(); if (!excludeProperties && manufacturer != null) { model.SelectedDiscountIds = manufacturer.AppliedDiscounts.Select(d => d.Id).ToArray(); } }
protected virtual void InstallManufacturers() { var pictureService = EngineContext.Current.Resolve<IPictureService>(); var sampleImagesPath = _webHelper.MapPath("~/content/samples/"); var manufacturerTemplateInGridAndLines = _manufacturerTemplateRepository.Table.FirstOrDefault(pt => pt.Name == "Products in Grid or Lines"); if (manufacturerTemplateInGridAndLines == null) throw new Exception("Manufacturer template cannot be loaded"); var allManufacturers = new List<Manufacturer>(); var manufacturerAsus = new Manufacturer { Id = 1, Name = "Apple", ManufacturerTemplateId = manufacturerTemplateInGridAndLines.Id, PageSize = 6, AllowCustomersToSelectPageSize = true, PageSizeOptions = "6, 3, 9", Published = true, PictureId = pictureService.InsertPicture(File.ReadAllBytes(sampleImagesPath + "manufacturer_apple.jpg"), "image/pjpeg", pictureService.GetPictureSeName("Apple")).Id, DisplayOrder = 1, CreatedOnUtc = DateTime.UtcNow, UpdatedOnUtc = DateTime.UtcNow }; _manufacturerRepository.Insert(manufacturerAsus); allManufacturers.Add(manufacturerAsus); var manufacturerHp = new Manufacturer { Id = 2, Name = "HP", ManufacturerTemplateId = manufacturerTemplateInGridAndLines.Id, PageSize = 6, AllowCustomersToSelectPageSize = true, PageSizeOptions = "6, 3, 9", Published = true, PictureId = pictureService.InsertPicture(File.ReadAllBytes(sampleImagesPath + "manufacturer_hp.jpg"), "image/pjpeg", pictureService.GetPictureSeName("Hp")).Id, DisplayOrder = 5, CreatedOnUtc = DateTime.UtcNow, UpdatedOnUtc = DateTime.UtcNow }; _manufacturerRepository.Insert(manufacturerHp); allManufacturers.Add(manufacturerHp); var manufacturerNike = new Manufacturer { Id = 3, Name = "Nike", ManufacturerTemplateId = manufacturerTemplateInGridAndLines.Id, PageSize = 6, AllowCustomersToSelectPageSize = true, PageSizeOptions = "6, 3, 9", Published = true, PictureId = pictureService.InsertPicture(File.ReadAllBytes(sampleImagesPath + "manufacturer_nike.jpg"), "image/pjpeg", pictureService.GetPictureSeName("Nike")).Id, DisplayOrder = 5, CreatedOnUtc = DateTime.UtcNow, UpdatedOnUtc = DateTime.UtcNow }; _manufacturerRepository.Insert(manufacturerNike); allManufacturers.Add(manufacturerNike); //search engine names foreach (var manufacturer in allManufacturers) { manufacturer.SeName = manufacturer.ValidateSeName("", manufacturer.Name, true); _urlRecordRepository.Insert(new UrlRecord { EntityId = manufacturer.Id, EntityName = "Manufacturer", LanguageId = 0, IsActive = true, Slug = manufacturer.SeName }); _manufacturerRepository.Update(manufacturer); } }
protected virtual void PrepareAclModel(ManufacturerModel model, Manufacturer manufacturer, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); model.AvailableCustomerRoles = _customerService .GetAllCustomerRoles(true) .Select(cr => cr.ToModel()) .ToList(); if (!excludeProperties) { if (manufacturer != null) { model.SelectedCustomerRoleIds = manufacturer.CustomerRoles.ToArray(); } } }
protected void UpdateLocales(Manufacturer manufacturer, ManufacturerModel model) { foreach (var localized in model.Locales) { _localizedEntityService.SaveLocalizedValue(manufacturer, x => x.Name, localized.Name, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(manufacturer, x => x.Description, localized.Description, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(manufacturer, x => x.MetaKeywords, localized.MetaKeywords, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(manufacturer, x => x.MetaDescription, localized.MetaDescription, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(manufacturer, x => x.MetaTitle, localized.MetaTitle, localized.LanguageId); //search engine name var seName = manufacturer.ValidateSeName(localized.SeName, localized.Name, false); _urlRecordService.SaveSlug(manufacturer, seName, localized.LanguageId); } }
private void PrepareStoresMappingModel(ManufacturerModel model, Manufacturer manufacturer, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); model.AvailableStores = _storeService .GetAllStores() .Select(s => s.ToModel()) .ToList(); if (!excludeProperties) { if (manufacturer != null) { model.SelectedStoreIds = _storeMappingService.GetStoresIdsWithAccess(manufacturer); } else { model.SelectedStoreIds = new int[0]; } } }
private void PrepareAclModel(ManufacturerModel model, Manufacturer manufacturer, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); model.AvailableCustomerRoles = _customerService .GetAllCustomerRoles(true) .Select(cr => cr.ToModel()) .ToList(); if (!excludeProperties) { if (manufacturer != null) { model.SelectedCustomerRoleIds = _aclService.GetCustomerRoleIdsWithAccess(manufacturer); } else { model.SelectedCustomerRoleIds = new int[0]; } } }
private Manufacturer ResolveBrand(string brandName) { Manufacturer brand = _manufacturerService.GetAllManufacturers(brandName).FirstOrDefault(); if (brand != null) return brand; brand = new Manufacturer { Name = brandName, AllowCustomersToSelectPageSize = true, //Description = brandName, MetaDescription = brandName, MetaKeywords = brandName, MetaTitle = brandName, ManufacturerTemplateId = 1, LimitedToStores = false, DisplayOrder = 1, PageSize = 8, PageSizeOptions = "4,8,12", SubjectToAcl = false, Published = true, CreatedOnUtc = DateTime.UtcNow, UpdatedOnUtc = DateTime.UtcNow }; _manufacturerService.InsertManufacturer(brand); _urlRecordService.SaveSlug(brand, brand.ValidateSeName(brandName, brandName, true), 0); return _manufacturerService.GetAllManufacturers(brandName).First(); }
protected virtual void PrepareStoresMappingModel(ManufacturerModel model, Manufacturer manufacturer, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); if (!excludeProperties && manufacturer != null) model.SelectedStoreIds = _storeMappingService.GetStoresIdsWithAccess(manufacturer).ToList(); var allStores = _storeService.GetAllStores(); foreach (var store in allStores) { model.AvailableStores.Add(new SelectListItem { Text = store.Name, Value = store.Id.ToString(), Selected = model.SelectedStoreIds.Contains(store.Id) }); } }
protected virtual void PrepareAclModel(ManufacturerModel model, Manufacturer manufacturer, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); if (!excludeProperties && manufacturer != null) model.SelectedCustomerRoleIds = _aclService.GetCustomerRoleIdsWithAccess(manufacturer).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) }); } }
protected virtual void PrepareDiscountModel(ManufacturerModel model, Manufacturer manufacturer, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); if (!excludeProperties && manufacturer != null) model.SelectedDiscountIds = manufacturer.AppliedDiscounts.Select(d => d.Id).ToList(); foreach (var discount in _discountService.GetAllDiscounts(DiscountType.AssignedToManufacturers, showHidden: true)) { model.AvailableDiscounts.Add(new SelectListItem { Text = discount.Name, Value = discount.Id.ToString(), Selected = model.SelectedDiscountIds.Contains(discount.Id) }); } }
protected virtual List<LocalizedProperty> UpdateLocales(Manufacturer manufacturer, ManufacturerModel model) { List<LocalizedProperty> localized = new List<LocalizedProperty>(); foreach (var local in model.Locales) { if (!(String.IsNullOrEmpty(local.Description))) localized.Add(new LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "Description", LocaleValue = local.Description, _id = ObjectId.GenerateNewId().ToString(), Id = localized.Count > 0 ? localized.Max(x => x.Id) + 1 : 1, }); if (!(String.IsNullOrEmpty(local.MetaDescription))) localized.Add(new LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "MetaDescription", LocaleValue = local.MetaDescription, _id = ObjectId.GenerateNewId().ToString(), Id = localized.Count > 0 ? localized.Max(x => x.Id) + 1 : 1, }); if (!(String.IsNullOrEmpty(local.MetaKeywords))) localized.Add(new LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "MetaKeywords", LocaleValue = local.MetaKeywords, _id = ObjectId.GenerateNewId().ToString(), Id = localized.Count > 0 ? localized.Max(x => x.Id) + 1 : 1, }); if (!(String.IsNullOrEmpty(local.MetaTitle))) localized.Add(new LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "MetaTitle", LocaleValue = local.MetaTitle, _id = ObjectId.GenerateNewId().ToString(), Id = localized.Count > 0 ? localized.Max(x => x.Id) + 1 : 1, }); if (!(String.IsNullOrEmpty(local.Name))) localized.Add(new LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "Name", LocaleValue = local.Name, _id = ObjectId.GenerateNewId().ToString(), Id = localized.Count > 0 ? localized.Max(x => x.Id) + 1 : 1, }); //search engine name var seName = manufacturer.ValidateSeName(local.SeName, local.Name, false); _urlRecordService.SaveSlug(manufacturer, seName, local.LanguageId); if (!(String.IsNullOrEmpty(seName))) localized.Add(new LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "SeName", LocaleValue = seName, _id = ObjectId.GenerateNewId().ToString(), Id = localized.Count > 0 ? localized.Max(x => x.Id) + 1 : 1, }); } return localized; }
protected virtual void PrepareStoresMappingModel(ManufacturerModel model, Manufacturer manufacturer, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); model.AvailableStores = _storeService .GetAllStores() .Select(s => s.ToModel()) .ToList(); if (!excludeProperties) { if (manufacturer != null) { model.SelectedStoreIds = manufacturer.Stores.ToArray(); } } }
public static Manufacturer ToEntity(this ManufacturerModel model, Manufacturer destination) { return Mapper.Map(model, destination); }
protected void UpdatePictureSeoNames(Manufacturer manufacturer) { var picture = _pictureService.GetPictureById(manufacturer.PictureId); if (picture != null) _pictureService.SetSeoFilename(picture.Id, _pictureService.GetPictureSeName(manufacturer.Name)); }
protected virtual void InstallManufacturers() { var manufacturerTemplateInGridAndLines = _manufacturerTemplateRepository.Table.FirstOrDefault(pt => pt.Name == "Products in Grid or Lines"); var allManufacturers = new List<Manufacturer>(); var manufacturerAsus = new Manufacturer { Name = "ASUS", ManufacturerTemplateId = manufacturerTemplateInGridAndLines.Id, PageSize = 4, AllowCustomersToSelectPageSize = true, PageSizeOptions = "8, 4, 12", Published = true, DisplayOrder = 2, CreatedOnUtc = DateTime.UtcNow, UpdatedOnUtc = DateTime.UtcNow }; _manufacturerRepository.Insert(manufacturerAsus); allManufacturers.Add(manufacturerAsus); var manufacturerHp = new Manufacturer { Name = "HP", ManufacturerTemplateId = manufacturerTemplateInGridAndLines.Id, PageSize = 4, AllowCustomersToSelectPageSize = true, PageSizeOptions = "8, 4, 12", Published = true, DisplayOrder = 5, CreatedOnUtc = DateTime.UtcNow, UpdatedOnUtc = DateTime.UtcNow }; _manufacturerRepository.Insert(manufacturerHp); allManufacturers.Add(manufacturerHp); //search engine names foreach (var manufacturer in allManufacturers) { _urlRecordRepository.Insert(new UrlRecord() { EntityId = manufacturer.Id, EntityName = "Manufacturer", LanguageId = 0, IsActive = true, Slug = manufacturer.ValidateSeName("", manufacturer.Name, true) }); } }
protected void SaveManufacturerAcl(Manufacturer manufacturer, ManufacturerModel model) { var existingAclRecords = _aclService.GetAclRecords(manufacturer); 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(manufacturer, customerRole.Id); } else { //removed role var aclRecordToDelete = existingAclRecords.FirstOrDefault(acl => acl.CustomerRoleId == customerRole.Id); if (aclRecordToDelete != null) _aclService.DeleteAclRecord(aclRecordToDelete); } } }
protected void UpdateLocales(Manufacturer manufacturer, ManufacturerModel model) { foreach (var localized in model.Locales) { _localizedEntityService.SaveLocalizedValue(manufacturer, x => x.Name, localized.Name, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(manufacturer, x => x.Description, localized.Description, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(manufacturer, x => x.MetaKeywords, localized.MetaKeywords, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(manufacturer, x => x.MetaDescription, localized.MetaDescription, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(manufacturer, x => x.MetaTitle, localized.MetaTitle, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(manufacturer, x => x.SeName, localized.SeName, localized.LanguageId); } }
protected void SaveStoreMappings(Manufacturer manufacturer, ManufacturerModel model) { var existingStoreMappings = _storeMappingService.GetStoreMappings(manufacturer); 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(manufacturer, store.Id); } else { //removed role var storeMappingToDelete = existingStoreMappings.FirstOrDefault(sm => sm.StoreId == store.Id); if (storeMappingToDelete != null) _storeMappingService.DeleteStoreMapping(storeMappingToDelete); } } }
/// <summary> /// Update HasDiscountsApplied property (used for performance optimization) /// </summary> /// <param name="manufacturer">Manufacturer</param> public virtual void UpdateHasDiscountsApplied(Manufacturer manufacturer) { if (manufacturer == null) throw new ArgumentNullException("manufacturer"); manufacturer.HasDiscountsApplied = manufacturer.AppliedDiscounts.Count > 0; UpdateManufacturer(manufacturer); }
/// <summary> /// Updates the manufacturer /// </summary> /// <param name="manufacturer">Manufacturer</param> public virtual void UpdateManufacturer(Manufacturer manufacturer) { if (manufacturer == null) throw new ArgumentNullException("manufacturer"); _manufacturerRepository.Update(manufacturer); //cache _cacheManager.RemoveByPattern(MANUFACTURERS_PATTERN_KEY); _cacheManager.RemoveByPattern(PRODUCTMANUFACTURERS_PATTERN_KEY); //event notification _eventPublisher.EntityUpdated(manufacturer); }
/// <summary> /// Deletes a manufacturer /// </summary> /// <param name="manufacturer">Manufacturer</param> public virtual void DeleteManufacturer(Manufacturer manufacturer) { if (manufacturer == null) throw new ArgumentNullException("manufacturer"); var builder = Builders<Product>.Update; var updatefilter = builder.PullFilter(x => x.ProductManufacturers, y => y.ManufacturerId == manufacturer.Id); var result = _productRepository.Collection.UpdateManyAsync(new BsonDocument(), updatefilter).Result; _cacheManager.RemoveByPattern(PRODUCTS_PATTERN_KEY); _cacheManager.RemoveByPattern(MANUFACTURERS_PATTERN_KEY); _manufacturerRepository.Delete(manufacturer); }