/// <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(nameof(customerAttributeValue)); } _customerAttributeValueRepository.Update(customerAttributeValue); _cacheManager.RemoveByPattern(NopCustomerServiceDefaults.CustomerAttributesPatternCacheKey); _cacheManager.RemoveByPattern(NopCustomerServiceDefaults.CustomerAttributeValuesPatternCacheKey); //event notification _eventPublisher.EntityUpdated(customerAttributeValue); }
/// <summary> /// Deletes a customer attribute value /// </summary> /// <param name="customerAttributeValue">Customer attribute value</param> public virtual void DeleteCustomerAttributeValue(CustomerAttributeValue customerAttributeValue) { if (customerAttributeValue == null) { throw new ArgumentNullException(nameof(customerAttributeValue)); } _customerAttributeValueRepository.Delete(customerAttributeValue); _cacheManager.RemoveByPattern(CUSTOMERATTRIBUTES_PATTERN_KEY); _cacheManager.RemoveByPattern(CUSTOMERATTRIBUTEVALUES_PATTERN_KEY); //event notification _eventPublisher.EntityDeleted(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(nameof(customerAttributeValue)); } _customerAttributeValueRepository.Insert(customerAttributeValue); _cacheManager.RemoveByPrefix(NopCustomerServiceDefaults.CustomerAttributesPrefixCacheKey); _cacheManager.RemoveByPrefix(NopCustomerServiceDefaults.CustomerAttributeValuesPrefixCacheKey); //event notification _eventPublisher.EntityInserted(customerAttributeValue); }
public override void Install() { // create customer attributes var requiredPasswordChangeCustomerAttribute = GetRequiredPasswordChangeCustomerAttribute(); if (requiredPasswordChangeCustomerAttribute == null) { var reqPassChangeCustAttr = new CustomerAttribute() { Name = RequirePasswordChangePluginCustomerAttributeNames.RequiredPasswordChange, AttributeControlType = AttributeControlType.RadioList, AttributeControlTypeId = (int)AttributeControlType.RadioList, IsRequired = false, }; _customerAttributeService.InsertCustomerAttribute(reqPassChangeCustAttr); var reqPassChangeCustAttrValueYes = new CustomerAttributeValue() { CustomerAttribute = reqPassChangeCustAttr, CustomerAttributeId = reqPassChangeCustAttr.Id, IsPreSelected = true, DisplayOrder = int.MinValue, Name = RequirePasswordChangePluginCustomerAttributeValueNames.RequiredPasswordChangeYes }; var reqPassChangeCustAttrValueNo = new CustomerAttributeValue() { CustomerAttribute = reqPassChangeCustAttr, CustomerAttributeId = reqPassChangeCustAttr.Id, IsPreSelected = false, DisplayOrder = int.MaxValue, Name = RequirePasswordChangePluginCustomerAttributeValueNames.RequiredPasswordChangeNo }; _customerAttributeService.InsertCustomerAttributeValue(reqPassChangeCustAttrValueYes); _customerAttributeService.InsertCustomerAttributeValue(reqPassChangeCustAttrValueNo); } //locales foreach (var localeResourceKvp in GetLocaleResourceStrings()) { this.AddOrUpdatePluginLocaleResource(localeResourceKvp.Key, localeResourceKvp.Value); } base.Install(); }
/// <summary> /// Inserts a customer attribute value /// </summary> /// <param name="customerAttributeValue">Customer attribute value</param> public virtual async Task InsertCustomerAttributeValue(CustomerAttributeValue customerAttributeValue) { if (customerAttributeValue == null) { throw new ArgumentNullException("customerAttributeValue"); } var updatebuilder = Builders <CustomerAttribute> .Update; var update = updatebuilder.AddToSet(p => p.CustomerAttributeValues, customerAttributeValue); await _customerAttributeRepository.Collection.UpdateOneAsync(new BsonDocument("_id", customerAttributeValue.CustomerAttributeId), update); _cacheManager.RemoveByPattern(CUSTOMERATTRIBUTES_PATTERN_KEY); _cacheManager.RemoveByPattern(CUSTOMERATTRIBUTEVALUES_PATTERN_KEY); //event notification await _eventPublisher.EntityInserted(customerAttributeValue); }
/// <summary> /// Deletes a customer attribute value /// </summary> /// <param name="customerAttributeValue">Customer attribute value</param> public virtual async Task DeleteCustomerAttributeValue(CustomerAttributeValue customerAttributeValue) { if (customerAttributeValue == null) { throw new ArgumentNullException(nameof(customerAttributeValue)); } var updatebuilder = Builders <CustomerAttribute> .Update; var update = updatebuilder.Pull(p => p.CustomerAttributeValues, customerAttributeValue); await _customerAttributeRepository.Collection.UpdateOneAsync(new BsonDocument("_id", customerAttributeValue.CustomerAttributeId), update); await _cacheBase.RemoveByPrefix(CacheKey.CUSTOMERATTRIBUTES_PATTERN_KEY); await _cacheBase.RemoveByPrefix(CacheKey.CUSTOMERATTRIBUTEVALUES_PATTERN_KEY); //event notification await _mediator.EntityDeleted(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); }
public virtual IActionResult ValueCreatePopup(CustomerAttributeValueModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings)) { return(AccessDeniedView()); } //try to get a customer attribute with the specified id var customerAttribute = _customerAttributeService.GetCustomerAttributeById(model.CustomerAttributeId); if (customerAttribute == null) { 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); //activity log _customerActivityService.InsertActivity("AddNewCustomerAttributeValue", string.Format(_localizationService.GetResource("ActivityLog.AddNewCustomerAttributeValue"), cav.Id), cav); UpdateValueLocales(cav, model); ViewBag.RefreshPage = true; return(View(model)); } //prepare model model = _customerAttributeModelFactory.PrepareCustomerAttributeValueModel(model, customerAttribute, null, true); //if we got this far, something failed, redisplay form return(View(model)); }
/// <summary> /// Deletes a customer attribute value /// </summary> /// <param name="customerAttributeValue">Customer attribute value</param> public virtual async Task DeleteCustomerAttributeValue(CustomerAttributeValue customerAttributeValue) { if (customerAttributeValue == null) { throw new ArgumentNullException(nameof(customerAttributeValue)); } var ca = await _customerAttributeRepository.GetByIdAsync(customerAttributeValue.CustomerAttributeId); ca.CustomerAttributeValues.Remove(ca.CustomerAttributeValues.FirstOrDefault(c => c.Id == customerAttributeValue.Id)); await _customerAttributeRepository.UpdateAsync(ca); await _cacheBase.RemoveByPrefix(CacheKey.CUSTOMERATTRIBUTES_PATTERN_KEY); await _cacheBase.RemoveByPrefix(CacheKey.CUSTOMERATTRIBUTEVALUES_PATTERN_KEY); //event notification await _mediator.EntityDeleted(customerAttributeValue); }
public virtual 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); //activity log _customerActivityService.InsertActivity("AddNewCustomerAttributeValue", _localizationService.GetResource("ActivityLog.AddNewCustomerAttributeValue"), cav.Id); 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)); }
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 { Id = customerAttribute.CustomerAttributeValues.Count > 0 ? customerAttribute.CustomerAttributeValues.Max(x => x.Id) + 1: 1, _id = ObjectId.GenerateNewId().ToString(), CustomerAttributeId = model.CustomerAttributeId, Name = model.Name, IsPreSelected = model.IsPreSelected, DisplayOrder = model.DisplayOrder }; cav.Locales = UpdateValueLocales(cav, model); _customerAttributeService.InsertCustomerAttributeValue(cav); ViewBag.RefreshPage = true; ViewBag.btnId = btnId; ViewBag.formId = formId; return(View(model)); } //If we got this far, something failed, redisplay form return(View(model)); }
//customer attributes value public static CustomerAttributeValueModel ToModel(this CustomerAttributeValue entity) { return(entity.MapTo <CustomerAttributeValue, CustomerAttributeValueModel>()); }
public virtual CustomerAttributeValue UpdateCustomerAttributeValueModel(CustomerAttributeValueModel model, CustomerAttributeValue customerAttributeValue) { customerAttributeValue = model.ToEntity(customerAttributeValue); _customerAttributeService.UpdateCustomerAttributeValue(customerAttributeValue); return(customerAttributeValue); }
/// <summary> /// Updates the customer attribute value /// </summary> /// <param name="customerAttributeValue">Customer attribute value</param> public void UpdateCustomerAttributeValue(CustomerAttributeValue customerAttributeValue) { _customerAttributeService.UpdateCustomerAttributeValue(customerAttributeValue); }
/// <summary> /// Inserts a customer attribute value /// </summary> /// <param name="customerAttributeValue">Customer attribute value</param> public void InsertCustomerAttributeValue(CustomerAttributeValue customerAttributeValue) { _customerAttributeService.InsertCustomerAttributeValue(customerAttributeValue); }
/// <summary> /// Deletes a customer attribute value /// </summary> /// <param name="customerAttributeValue">Customer attribute value</param> public void DeleteCustomerAttributeValue(CustomerAttributeValue customerAttributeValue) { _customerAttributeService.DeleteCustomerAttributeValue(customerAttributeValue); }
public virtual async Task <CustomerAttributeValue> UpdateCustomerAttributeValueModel(CustomerAttributeValueModel model, CustomerAttributeValue customerAttributeValue) { customerAttributeValue = model.ToEntity(customerAttributeValue); await _customerAttributeService.UpdateCustomerAttributeValue(customerAttributeValue); return(customerAttributeValue); }
/// <summary> /// Deletes a customer attribute value /// </summary> /// <param name="customerAttributeValue">Customer attribute value</param> public virtual async Task DeleteCustomerAttributeValueAsync(CustomerAttributeValue customerAttributeValue) { await _customerAttributeValueRepository.DeleteAsync(customerAttributeValue); }
/// <summary> /// Inserts a customer attribute value /// </summary> /// <param name="customerAttributeValue">Customer attribute value</param> public virtual async Task InsertCustomerAttributeValueAsync(CustomerAttributeValue customerAttributeValue) { await _customerAttributeValueRepository.InsertAsync(customerAttributeValue); }
/// <summary> /// Prepare customer attribute value model /// </summary> /// <param name="model">Customer attribute value model</param> /// <param name="customerAttribute">Customer attribute</param> /// <param name="customerAttributeValue">Customer attribute value</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns>Customer attribute value model</returns> public virtual CustomerAttributeValueModel PrepareCustomerAttributeValueModel(CustomerAttributeValueModel model, CustomerAttribute customerAttribute, CustomerAttributeValue customerAttributeValue, bool excludeProperties = false) { if (customerAttribute == null) { throw new ArgumentNullException(nameof(customerAttribute)); } Action <CustomerAttributeValueLocalizedModel, int> localizedModelConfiguration = null; if (customerAttributeValue != null) { //fill in model values from the entity model = model ?? new CustomerAttributeValueModel { Name = customerAttributeValue.Name, IsPreSelected = customerAttributeValue.IsPreSelected, DisplayOrder = customerAttributeValue.DisplayOrder }; //define localized model configuration action localizedModelConfiguration = (locale, languageId) => { locale.Name = customerAttributeValue.GetLocalized(entity => entity.Name, languageId, false, false); }; } model.CustomerAttributeId = customerAttribute.Id; //prepare localized models if (!excludeProperties) { model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration); } return(model); }
public static CustomerAttributeValue ToEntity(this CustomerAttributeValueModel model, CustomerAttributeValue destination) { return(model.MapTo(destination)); }
/// <summary> /// Inserts a customer attribute value /// </summary> /// <param name="customerAttributeValue">Customer attribute value</param> public virtual void InsertCustomerAttributeValue(CustomerAttributeValue customerAttributeValue) { _customerAttributeValueRepository.Insert(customerAttributeValue); }
/// <summary> /// Prepare customer attribute value model /// </summary> /// <param name="model">Customer attribute value model</param> /// <param name="customerAttribute">Customer attribute</param> /// <param name="customerAttributeValue">Customer attribute value</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns>Customer attribute value model</returns> public virtual async Task <CustomerAttributeValueModel> PrepareCustomerAttributeValueModelAsync(CustomerAttributeValueModel model, CustomerAttribute customerAttribute, CustomerAttributeValue customerAttributeValue, bool excludeProperties = false) { if (customerAttribute == null) { throw new ArgumentNullException(nameof(customerAttribute)); } Action <CustomerAttributeValueLocalizedModel, int> localizedModelConfiguration = null; if (customerAttributeValue != null) { //fill in model values from the entity model ??= customerAttributeValue.ToModel <CustomerAttributeValueModel>(); //define localized model configuration action localizedModelConfiguration = async(locale, languageId) => { locale.Name = await _localizationService.GetLocalizedAsync(customerAttributeValue, entity => entity.Name, languageId, false, false); }; } model.CustomerAttributeId = customerAttribute.Id; //prepare localized models if (!excludeProperties) { model.Locales = await _localizedModelFactory.PrepareLocalizedModelsAsync(localizedModelConfiguration); } return(model); }
public virtual CustomerAttributeValueModel PrepareCustomerAttributeValueModel(CustomerAttributeValue customerAttributeValue) { var model = customerAttributeValue.ToModel(); return(model); }
/// <summary> /// Deletes a customer attribute value /// </summary> /// <param name="customerAttributeValue">Customer attribute value</param> public virtual void DeleteCustomerAttributeValue(CustomerAttributeValue customerAttributeValue) { _customerAttributeValueRepository.Delete(customerAttributeValue); }