public void Can_save_and_load_customerAttributeValue() { var cav = new CustomerAttributeValue() { Name = "Name 2", IsPreSelected = true, DisplayOrder = 1, CustomerAttribute = new CustomerAttribute() { Name = "Name 1", IsRequired = true, AttributeControlType = AttributeControlType.DropdownList, DisplayOrder = 2 } }; var fromDb = SaveAndLoadEntity(cav); fromDb.ShouldNotBeNull(); fromDb.Name.ShouldEqual("Name 2"); fromDb.IsPreSelected.ShouldEqual(true); fromDb.DisplayOrder.ShouldEqual(1); fromDb.CustomerAttribute.ShouldNotBeNull(); fromDb.CustomerAttribute.Name.ShouldEqual("Name 1"); }
protected virtual void UpdateValueLocales(CustomerAttributeValue customerAttributeValue, CustomerAttributeValueModel model) { foreach (var localized in model.Locales) { _localizedEntityService.SaveLocalizedValue(customerAttributeValue, x => x.Name, localized.Name, localized.LanguageId); } }
/// <summary> /// Updates the customer attribute value /// </summary> /// <param name="customerAttributeValue">Customer attribute value</param> public virtual void UpdateCustomerAttributeValue(CustomerAttributeValue customerAttributeValue) { if (customerAttributeValue == null) throw new ArgumentNullException("customerAttributeValue"); _customerAttributeValueRepository.Update(customerAttributeValue); _cacheManager.RemoveByPattern(CUSTOMERATTRIBUTES_PATTERN_KEY); _cacheManager.RemoveByPattern(CUSTOMERATTRIBUTEVALUES_PATTERN_KEY); //event notification _eventPublisher.EntityUpdated(customerAttributeValue); }
public ActionResult ValueCreatePopup(string btnId, string formId, CustomerAttributeValueModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings)) return AccessDeniedView(); var customerAttribute = _customerAttributeService.GetCustomerAttributeById(model.CustomerAttributeId); if (customerAttribute == null) //No customer attribute found with the specified id return RedirectToAction("List"); if (ModelState.IsValid) { var cav = new CustomerAttributeValue { CustomerAttributeId = model.CustomerAttributeId, Name = model.Name, IsPreSelected = model.IsPreSelected, DisplayOrder = model.DisplayOrder }; _customerAttributeService.InsertCustomerAttributeValue(cav); UpdateValueLocales(cav, model); ViewBag.RefreshPage = true; ViewBag.btnId = btnId; ViewBag.formId = formId; return View(model); } //If we got this far, something failed, redisplay form return View(model); }
/// <summary> /// Updates the customer attribute value /// </summary> /// <param name="customerAttributeValue">Customer attribute value</param> public virtual void UpdateCustomerAttributeValue(CustomerAttributeValue customerAttributeValue) { if (customerAttributeValue == null) throw new ArgumentNullException("customerAttributeValue"); var builder = Builders<CustomerAttribute>.Filter; var filter = builder.Eq(x => x.Id, customerAttributeValue.CustomerAttributeId); filter = filter & builder.ElemMatch(x => x.CustomerAttributeValues, y => y.Id == customerAttributeValue.Id); var update = Builders<CustomerAttribute>.Update .Set(x => x.CustomerAttributeValues.ElementAt(-1).DisplayOrder, customerAttributeValue.DisplayOrder) .Set(x => x.CustomerAttributeValues.ElementAt(-1).IsPreSelected, customerAttributeValue.IsPreSelected) .Set(x => x.CustomerAttributeValues.ElementAt(-1).Locales, customerAttributeValue.Locales) .Set(x => x.CustomerAttributeValues.ElementAt(-1).Name, customerAttributeValue.Name); var result = _customerAttributeRepository.Collection.UpdateManyAsync(filter, update).Result; _cacheManager.RemoveByPattern(CUSTOMERATTRIBUTES_PATTERN_KEY); _cacheManager.RemoveByPattern(CUSTOMERATTRIBUTEVALUES_PATTERN_KEY); //event notification _eventPublisher.EntityUpdated(customerAttributeValue); }
/// <summary> /// Inserts a customer attribute value /// </summary> /// <param name="customerAttributeValue">Customer attribute value</param> public virtual void InsertCustomerAttributeValue(CustomerAttributeValue customerAttributeValue) { if (customerAttributeValue == null) throw new ArgumentNullException("customerAttributeValue"); var updatebuilder = Builders<CustomerAttribute>.Update; var update = updatebuilder.AddToSet(p => p.CustomerAttributeValues, customerAttributeValue); _customerAttributeRepository.Collection.UpdateOneAsync(new BsonDocument("Id", customerAttributeValue.CustomerAttributeId), update); _cacheManager.RemoveByPattern(CUSTOMERATTRIBUTES_PATTERN_KEY); _cacheManager.RemoveByPattern(CUSTOMERATTRIBUTEVALUES_PATTERN_KEY); //event notification _eventPublisher.EntityInserted(customerAttributeValue); }
protected virtual List<LocalizedProperty> UpdateValueLocales(CustomerAttributeValue customerAttributeValue, CustomerAttributeValueModel model) { List<LocalizedProperty> localized = new List<LocalizedProperty>(); foreach (var local in model.Locales) { if (!(String.IsNullOrEmpty(local.Name))) localized.Add(new LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "Name", LocaleValue = local.Name }); } return localized; }