/// <summary> /// Updates the address attribute value /// </summary> /// <param name="addressAttributeValue">Address attribute value</param> public virtual async Task UpdateAddressAttributeValue(AddressAttributeValue addressAttributeValue) { if (addressAttributeValue == null) { throw new ArgumentNullException(nameof(addressAttributeValue)); } var builder = Builders <AddressAttribute> .Filter; var filter = builder.Eq(x => x.Id, addressAttributeValue.AddressAttributeId); filter = filter & builder.ElemMatch(x => x.AddressAttributeValues, y => y.Id == addressAttributeValue.Id); var update = Builders <AddressAttribute> .Update .Set(x => x.AddressAttributeValues.ElementAt(-1).DisplayOrder, addressAttributeValue.DisplayOrder) .Set(x => x.AddressAttributeValues.ElementAt(-1).IsPreSelected, addressAttributeValue.IsPreSelected) .Set(x => x.AddressAttributeValues.ElementAt(-1).Locales, addressAttributeValue.Locales) .Set(x => x.AddressAttributeValues.ElementAt(-1).Name, addressAttributeValue.Name); await _addressAttributeRepository.Collection.UpdateManyAsync(filter, update); await _cacheBase.RemoveByPrefix(CacheKey.ADDRESSATTRIBUTES_PATTERN_KEY); await _cacheBase.RemoveByPrefix(CacheKey.ADDRESSATTRIBUTEVALUES_PATTERN_KEY); //event notification await _mediator.EntityUpdated(addressAttributeValue); }
/// <summary> /// Updates the address attribute value /// </summary> /// <param name="addressAttributeValue">Address attribute value</param> public virtual void UpdateAddressAttributeValue(AddressAttributeValue addressAttributeValue) { if (addressAttributeValue == null) { throw new ArgumentNullException("addressAttributeValue"); } var builder = Builders <AddressAttribute> .Filter; var filter = builder.Eq(x => x.Id, addressAttributeValue.AddressAttributeId); filter = filter & builder.ElemMatch(x => x.AddressAttributeValues, y => y.Id == addressAttributeValue.Id); var update = Builders <AddressAttribute> .Update .Set(x => x.AddressAttributeValues.ElementAt(-1).DisplayOrder, addressAttributeValue.DisplayOrder) .Set(x => x.AddressAttributeValues.ElementAt(-1).IsPreSelected, addressAttributeValue.IsPreSelected) .Set(x => x.AddressAttributeValues.ElementAt(-1).Locales, addressAttributeValue.Locales) .Set(x => x.AddressAttributeValues.ElementAt(-1).Name, addressAttributeValue.Name); var result = _addressAttributeRepository.Collection.UpdateManyAsync(filter, update).Result; _cacheManager.RemoveByPattern(ADDRESSATTRIBUTES_PATTERN_KEY); _cacheManager.RemoveByPattern(ADDRESSATTRIBUTEVALUES_PATTERN_KEY); //event notification _eventPublisher.EntityUpdated(addressAttributeValue); }
/// <summary> /// Prepare address attribute value model /// </summary> /// <param name="model">Address attribute value model</param> /// <param name="addressAttribute">Address attribute</param> /// <param name="addressAttributeValue">Address attribute value</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns>Address attribute value model</returns> public virtual AddressAttributeValueModel PrepareAddressAttributeValueModel(AddressAttributeValueModel model, AddressAttribute addressAttribute, AddressAttributeValue addressAttributeValue, bool excludeProperties = false) { if (addressAttribute == null) throw new ArgumentNullException(nameof(addressAttribute)); Action<AddressAttributeValueLocalizedModel, int> localizedModelConfiguration = null; if (addressAttributeValue != null) { //fill in model values from the entity model = model ?? addressAttributeValue.ToModel<AddressAttributeValueModel>(); //define localized model configuration action localizedModelConfiguration = (locale, languageId) => { locale.Name = _localizationService.GetLocalized(addressAttributeValue, entity => entity.Name, languageId, false, false); }; } model.AddressAttributeId = addressAttribute.Id; //prepare localized models if (!excludeProperties) model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration); return model; }
public void Can_save_and_load_addressAttributeValue() { var cav = new AddressAttributeValue { Name = "Name 2", IsPreSelected = true, DisplayOrder = 1, AddressAttribute = new AddressAttribute { 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.AddressAttribute.ShouldNotBeNull(); fromDb.AddressAttribute.Name.ShouldEqual("Name 1"); }
/// <summary> /// Updates the address attribute value /// </summary> /// <param name="addressAttributeValue">Address attribute value</param> public virtual void UpdateAddressAttributeValue(AddressAttributeValue addressAttributeValue) { if (addressAttributeValue == null) { throw new ArgumentNullException(nameof(addressAttributeValue)); } _addressAttributeValueRepository.Update(addressAttributeValue); }
/// <returns>A task that represents the asynchronous operation</returns> protected virtual async Task UpdateValueLocalesAsync(AddressAttributeValue addressAttributeValue, AddressAttributeValueModel model) { foreach (var localized in model.Locales) { await _localizedEntityService.SaveLocalizedValueAsync(addressAttributeValue, x => x.Name, localized.Name, localized.LanguageId); } }
protected virtual void UpdateValueLocales(AddressAttributeValue addressAttributeValue, AddressAttributeValueModel model) { foreach (var localized in model.Locales) { _localizedEntityService.SaveLocalizedValue(addressAttributeValue, x => x.Name, localized.Name, localized.LanguageId); } }
/// <summary> /// Deletes an address attribute value /// </summary> /// <param name="addressAttributeValue">Address attribute value</param> public virtual void DeleteAddressAttributeValue(AddressAttributeValue addressAttributeValue) { if (addressAttributeValue == null) { throw new ArgumentNullException("addressAttributeValue"); } _addressAttributeValueRepository.Delete(addressAttributeValue); //_unitOfWork.Commit(); }
/// <summary> /// Updates the address attribute value /// </summary> /// <param name="addressAttributeValue">Address attribute value</param> public virtual void UpdateAddressAttributeValue(AddressAttributeValue addressAttributeValue) { if (addressAttributeValue == null) { throw new ArgumentNullException(nameof(addressAttributeValue)); } _addressAttributeValueRepository.Update(addressAttributeValue); //event notification _eventPublisher.EntityUpdated(addressAttributeValue); }
public ActionResult ValueCreatePopup(string btnId, string formId, AddressAttributeValueModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings)) { return(AccessDeniedView()); } var addressAttribute = _addressAttributeService.GetAddressAttributeById(model.AddressAttributeId); if (addressAttribute == null) { //No address attribute found with the specified id return(RedirectToAction("List")); } if (ModelState.IsValid) { var cav = new AddressAttributeValue { Id = addressAttribute.AddressAttributeValues.Count > 0 ? addressAttribute.AddressAttributeValues.Max(x => x.Id) + 1: 1, _id = ObjectId.GenerateNewId().ToString(), AddressAttributeId = model.AddressAttributeId, Name = model.Name, IsPreSelected = model.IsPreSelected, DisplayOrder = model.DisplayOrder }; addressAttribute.Locales.Clear(); foreach (var local in model.Locales) { if (!(String.IsNullOrEmpty(local.Name))) { addressAttribute.Locales.Add(new Core.Domain.Localization.LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "Name", LocaleValue = local.Name }); } } _addressAttributeService.InsertAddressAttributeValue(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 address attribute value /// </summary> /// <param name="addressAttributeValue">Address attribute value</param> public virtual void UpdateAddressAttributeValue(AddressAttributeValue addressAttributeValue) { if (addressAttributeValue == null) { throw new ArgumentNullException(nameof(addressAttributeValue)); } _addressAttributeValueRepository.Update(addressAttributeValue); _cacheManager.RemoveByPrefix(NopCommonDefaults.AddressAttributesPrefixCacheKey); _cacheManager.RemoveByPrefix(NopCommonDefaults.AddressAttributeValuesPrefixCacheKey); //event notification _eventPublisher.EntityUpdated(addressAttributeValue); }
/// <summary> /// Inserts an address attribute value /// </summary> /// <param name="addressAttributeValue">Address attribute value</param> public virtual void InsertAddressAttributeValue(AddressAttributeValue addressAttributeValue) { if (addressAttributeValue == null) { throw new ArgumentNullException(nameof(addressAttributeValue)); } _addressAttributeValueRepository.Insert(addressAttributeValue); _cacheManager.RemoveByPattern(NopCommonDefaults.AddressAttributesPatternCacheKey); _cacheManager.RemoveByPattern(NopCommonDefaults.AddressAttributeValuesPatternCacheKey); //event notification _eventPublisher.EntityInserted(addressAttributeValue); }
/// <summary> /// Updates the address attribute value /// </summary> /// <param name="addressAttributeValue">Address attribute value</param> public virtual void UpdateAddressAttributeValue(AddressAttributeValue addressAttributeValue) { if (addressAttributeValue == null) { throw new ArgumentNullException("addressAttributeValue"); } _addressAttributeValueRepository.Update(addressAttributeValue); _cacheManager.RemoveByPattern(ADDRESSATTRIBUTES_PATTERN_KEY); _cacheManager.RemoveByPattern(ADDRESSATTRIBUTEVALUES_PATTERN_KEY); //event notification _eventPublisher.EntityUpdated(addressAttributeValue); }
/// <summary> /// Updates the address attribute value /// </summary> /// <param name="addressAttributeValue">Address attribute value</param> public virtual void UpdateAddressAttributeValue(AddressAttributeValue addressAttributeValue) { if (addressAttributeValue == null) { throw new ArgumentNullException("addressAttributeValue"); } _addressAttributeValueRepository.Update(addressAttributeValue); _cacheManager.GetCache(CACHE_NAME_ADDRESSATTRIBUTES).Clear(); _cacheManager.GetCache(CACHE_NAME_ADDRESSATTRIBUTEVALUES).Clear(); //event notification //_eventPublisher.EntityUpdated(addressAttributeValue); }
/// <summary> /// Deletes an address attribute value /// </summary> /// <param name="addressAttributeValue">Address attribute value</param> public virtual async Task DeleteAddressAttributeValue(AddressAttributeValue addressAttributeValue) { if (addressAttributeValue == null) { throw new ArgumentNullException(nameof(addressAttributeValue)); } await _addressAttributeRepository.PullFilter(addressAttributeValue.AddressAttributeId, x => x.AddressAttributeValues, z => z.Id, addressAttributeValue.Id); await _cacheBase.RemoveByPrefix(CacheKey.ADDRESSATTRIBUTES_PATTERN_KEY); await _cacheBase.RemoveByPrefix(CacheKey.ADDRESSATTRIBUTEVALUES_PATTERN_KEY); //event notification await _mediator.EntityDeleted(addressAttributeValue); }
/// <summary> /// Inserts an address attribute value /// </summary> /// <param name="addressAttributeValue">Address attribute value</param> public virtual async Task InsertAddressAttributeValue(AddressAttributeValue addressAttributeValue) { if (addressAttributeValue == null) { throw new ArgumentNullException("addressAttributeValue"); } var updatebuilder = Builders <AddressAttribute> .Update; var update = updatebuilder.AddToSet(p => p.AddressAttributeValues, addressAttributeValue); await _addressAttributeRepository.Collection.UpdateOneAsync(new BsonDocument("_id", addressAttributeValue.AddressAttributeId), update); _cacheManager.RemoveByPattern(ADDRESSATTRIBUTES_PATTERN_KEY); _cacheManager.RemoveByPattern(ADDRESSATTRIBUTEVALUES_PATTERN_KEY); //event notification await _eventPublisher.EntityInserted(addressAttributeValue); }
public virtual IActionResult ValueCreatePopup(AddressAttributeValueModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings)) { return(AccessDeniedView()); } //try to get an address attribute with the specified id var addressAttribute = _addressAttributeService.GetAddressAttributeById(model.AddressAttributeId); if (addressAttribute == null) { return(RedirectToAction("List")); } if (ModelState.IsValid) { var addressAttributeValue = new AddressAttributeValue { AddressAttributeId = model.AddressAttributeId, Name = model.Name, IsPreSelected = model.IsPreSelected, DisplayOrder = model.DisplayOrder }; _addressAttributeService.InsertAddressAttributeValue(addressAttributeValue); //activity log _customerActivityService.InsertActivity("AddNewAddressAttributeValue", string.Format(_localizationService.GetResource("ActivityLog.AddNewAddressAttributeValue"), addressAttributeValue.Id), addressAttributeValue); UpdateValueLocales(addressAttributeValue, model); ViewBag.RefreshPage = true; return(View(model)); } //prepare model model = _addressAttributeModelFactory.PrepareAddressAttributeValueModel(model, addressAttribute, null, true); //if we got this far, something failed, redisplay form return(View(model)); }
/// <summary> /// Deletes an address attribute value /// </summary> /// <param name="addressAttributeValue">Address attribute value</param> public virtual async Task DeleteAddressAttributeValue(AddressAttributeValue addressAttributeValue) { if (addressAttributeValue == null) { throw new ArgumentNullException(nameof(addressAttributeValue)); } var updatebuilder = Builders <AddressAttribute> .Update; var update = updatebuilder.Pull(p => p.AddressAttributeValues, addressAttributeValue); await _addressAttributeRepository.Collection.UpdateOneAsync(new BsonDocument("_id", addressAttributeValue.AddressAttributeId), update); await _cacheBase.RemoveByPrefix(CacheKey.ADDRESSATTRIBUTES_PATTERN_KEY); await _cacheBase.RemoveByPrefix(CacheKey.ADDRESSATTRIBUTEVALUES_PATTERN_KEY); //event notification await _mediator.EntityDeleted(addressAttributeValue); }
public virtual ActionResult ValueCreatePopup(string btnId, string formId, AddressAttributeValueModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings)) { return(AccessDeniedView()); } var addressAttribute = _addressAttributeService.GetAddressAttributeById(model.AddressAttributeId); if (addressAttribute == null) { //No address attribute found with the specified id return(RedirectToAction("List")); } if (ModelState.IsValid) { var cav = new AddressAttributeValue { AddressAttributeId = model.AddressAttributeId, Name = model.Name, IsPreSelected = model.IsPreSelected, DisplayOrder = model.DisplayOrder, PriceAdjustment = model.PriceAdjustment }; _addressAttributeService.InsertAddressAttributeValue(cav); //activity log _customerActivityService.InsertActivity("AddNewAddressAttributeValue", _localizationService.GetResource("ActivityLog.AddNewAddressAttributeValue"), 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)); }
/// <summary> /// Deletes an address attribute value /// </summary> /// <param name="addressAttributeValue">Address attribute value</param> public virtual void DeleteAddressAttributeValue(AddressAttributeValue addressAttributeValue) { _addressAttributeValueRepository.Delete(addressAttributeValue); }
/// <summary> /// Prepare address attribute value model /// </summary> /// <param name="model">Address attribute value model</param> /// <param name="addressAttribute">Address attribute</param> /// <param name="addressAttributeValue">Address attribute value</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the address attribute value model /// </returns> public virtual async Task <AddressAttributeValueModel> PrepareAddressAttributeValueModelAsync(AddressAttributeValueModel model, AddressAttribute addressAttribute, AddressAttributeValue addressAttributeValue, bool excludeProperties = false) { if (addressAttribute == null) { throw new ArgumentNullException(nameof(addressAttribute)); } Func <AddressAttributeValueLocalizedModel, int, Task> localizedModelConfiguration = null; if (addressAttributeValue != null) { //fill in model values from the entity model ??= addressAttributeValue.ToModel <AddressAttributeValueModel>(); //define localized model configuration action localizedModelConfiguration = async(locale, languageId) => { locale.Name = await _localizationService.GetLocalizedAsync(addressAttributeValue, entity => entity.Name, languageId, false, false); }; } model.AddressAttributeId = addressAttribute.Id; //prepare localized models if (!excludeProperties) { model.Locales = await _localizedModelFactory.PrepareLocalizedModelsAsync(localizedModelConfiguration); } return(model); }
public static AddressAttributeValue ToEntity(this AddressAttributeValueModel model, AddressAttributeValue destination) { return(model.MapTo(destination)); }
//attributes value public static AddressAttributeValueModel ToModel(this AddressAttributeValue entity) { return(entity.MapTo <AddressAttributeValue, AddressAttributeValueModel>()); }
/// <summary> /// Prepare address attribute value model /// </summary> /// <param name="model">Address attribute value model</param> /// <param name="addressAttribute">Address attribute</param> /// <param name="addressAttributeValue">Address attribute value</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns>Address attribute value model</returns> public virtual AddressAttributeValueModel PrepareAddressAttributeValueModel(AddressAttributeValueModel model, AddressAttribute addressAttribute, AddressAttributeValue addressAttributeValue, bool excludeProperties = false) { if (addressAttribute == null) { throw new ArgumentNullException(nameof(addressAttribute)); } Action <AddressAttributeValueLocalizedModel, int> localizedModelConfiguration = null; if (addressAttributeValue != null) { //fill in model values from the entity model = model ?? new AddressAttributeValueModel { Name = addressAttributeValue.Name, IsPreSelected = addressAttributeValue.IsPreSelected, DisplayOrder = addressAttributeValue.DisplayOrder }; //define localized model configuration action localizedModelConfiguration = (locale, languageId) => { locale.Name = addressAttributeValue.GetLocalized(entity => entity.Name, languageId, false, false); }; } model.AddressAttributeId = addressAttribute.Id; //prepare localized models if (!excludeProperties) { model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration); } return(model); }
/// <summary> /// Updates the address attribute value /// </summary> /// <param name="addressAttributeValue">Address attribute value</param> /// <returns>A task that represents the asynchronous operation</returns> public virtual async Task UpdateAddressAttributeValueAsync(AddressAttributeValue addressAttributeValue) { await _addressAttributeValueRepository.UpdateAsync(addressAttributeValue); }
/// <summary> /// Inserts an address attribute value /// </summary> /// <param name="addressAttributeValue">Address attribute value</param> /// <returns>A task that represents the asynchronous operation</returns> public virtual async Task InsertAddressAttributeValueAsync(AddressAttributeValue addressAttributeValue) { await _addressAttributeValueRepository.InsertAsync(addressAttributeValue); }
public virtual AddressAttributeValue UpdateAddressAttributeValueModel(AddressAttributeValueModel model, AddressAttributeValue addressAttributeValue) { addressAttributeValue = model.ToEntity(addressAttributeValue); _addressAttributeService.UpdateAddressAttributeValue(addressAttributeValue); return(addressAttributeValue); }
public virtual AddressAttributeValueModel PrepareAddressAttributeValueModel(AddressAttributeValue addressAttributeValue) { var model = addressAttributeValue.ToModel(); return(model); }
/// <summary> /// Inserts an address attribute value /// </summary> /// <param name="addressAttributeValue">Address attribute value</param> public virtual void InsertAddressAttributeValue(AddressAttributeValue addressAttributeValue) { _addressAttributeValueRepository.Insert(addressAttributeValue); }
/// <summary> /// Updates the address attribute value /// </summary> /// <param name="addressAttributeValue">Address attribute value</param> public virtual void UpdateAddressAttributeValue(AddressAttributeValue addressAttributeValue) { _addressAttributeValueRepository.Update(addressAttributeValue); }