/// <summary> /// Prepare vendor attribute value model /// </summary> /// <param name="model">Vendor attribute value model</param> /// <param name="vendorAttribute">Vendor attribute</param> /// <param name="vendorAttributeValue">Vendor attribute value</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns>Vendor attribute value model</returns> public virtual VendorAttributeValueModel PrepareVendorAttributeValueModel(VendorAttributeValueModel model, VendorAttribute vendorAttribute, VendorAttributeValue vendorAttributeValue, bool excludeProperties = false) { if (vendorAttribute == null) { throw new ArgumentNullException(nameof(vendorAttribute)); } Action <VendorAttributeValueLocalizedModel, int> localizedModelConfiguration = null; if (vendorAttributeValue != null) { //fill in model values from the entity model = model ?? vendorAttributeValue.ToModel <VendorAttributeValueModel>(); //define localized model configuration action localizedModelConfiguration = (locale, languageId) => { locale.Name = _localizationService.GetLocalized(vendorAttributeValue, entity => entity.Name, languageId, false, false); }; } model.VendorAttributeId = vendorAttribute.Id; //prepare localized models if (!excludeProperties) { model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration); } return(model); }
/// <summary> /// Adds a vendor attribute /// </summary> /// <param name="attributesXml">Attributes in XML format</param> /// <param name="vendorAttribute">Vendor attribute</param> /// <param name="value">Value</param> /// <returns>Attributes in XML format</returns> public virtual string AddVendorAttribute(string attributesXml, VendorAttribute vendorAttribute, string value) { var result = string.Empty; try { var xmlDoc = new XmlDocument(); if (string.IsNullOrEmpty(attributesXml)) { var element1 = xmlDoc.CreateElement("Attributes"); xmlDoc.AppendChild(element1); } else { xmlDoc.LoadXml(attributesXml); } var rootElement = (XmlElement)xmlDoc.SelectSingleNode(@"//Attributes"); XmlElement attributeElement = null; //find existing var nodeList1 = xmlDoc.SelectNodes(@"//Attributes/VendorAttribute"); foreach (XmlNode node1 in nodeList1) { if (node1.Attributes != null && node1.Attributes["ID"] != null) { var str1 = node1.Attributes["ID"].InnerText.Trim(); if (int.TryParse(str1, out int id)) { if (id == vendorAttribute.Id) { attributeElement = (XmlElement)node1; break; } } } } //create new one if not found if (attributeElement == null) { attributeElement = xmlDoc.CreateElement("VendorAttribute"); attributeElement.SetAttribute("ID", vendorAttribute.Id.ToString()); rootElement.AppendChild(attributeElement); } var attributeValueElement = xmlDoc.CreateElement("VendorAttributeValue"); attributeElement.AppendChild(attributeValueElement); var attributeValueValueElement = xmlDoc.CreateElement("Value"); attributeValueValueElement.InnerText = value; attributeValueElement.AppendChild(attributeValueValueElement); result = xmlDoc.OuterXml; } catch (Exception exc) { Debug.Write(exc.ToString()); } return(result); }
/// <summary> /// Prepare vendor attribute model /// </summary> /// <param name="model">Vendor attribute model</param> /// <param name="vendorAttribute">Vendor attribute</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns>Vendor attribute model</returns> public virtual VendorAttributeModel PrepareVendorAttributeModel(VendorAttributeModel model, VendorAttribute vendorAttribute, bool excludeProperties = false) { Action <VendorAttributeLocalizedModel, int> localizedModelConfiguration = null; if (vendorAttribute != null) { //fill in model values from the entity model = model ?? vendorAttribute.ToModel <VendorAttributeModel>(); //prepare nested search model PrepareVendorAttributeValueSearchModel(model.VendorAttributeValueSearchModel, vendorAttribute); //define localized model configuration action localizedModelConfiguration = (locale, languageId) => { locale.Name = _localizationService.GetLocalized(vendorAttribute, entity => entity.Name, languageId, false, false); }; } //prepare localized models if (!excludeProperties) { model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration); } return(model); }
/// <returns>A task that represents the asynchronous operation</returns> protected virtual async Task UpdateAttributeLocalesAsync(VendorAttribute vendorAttribute, VendorAttributeModel model) { foreach (var localized in model.Locales) { await _localizedEntityService.SaveLocalizedValueAsync(vendorAttribute, x => x.Name, localized.Name, localized.LanguageId); } }
protected virtual void UpdateAttributeLocales(VendorAttribute vendorAttribute, VendorAttributeModel model) { foreach (var localized in model.Locales) { _localizedEntityService.SaveLocalizedValue(vendorAttribute, x => x.Name, localized.Name, localized.LanguageId); } }
/// <summary> /// Updates a vendor attribute /// </summary> /// <param name="vendorAttribute">Vendor attribute</param> public virtual void UpdateVendorAttribute(VendorAttribute vendorAttribute) { if (vendorAttribute == null) { throw new ArgumentNullException(nameof(vendorAttribute)); } _vendorAttributeRepository.Update(vendorAttribute); //event notification _eventPublisher.EntityUpdated(vendorAttribute); }
/// <summary> /// Deletes a vendor attribute /// </summary> /// <param name="vendorAttribute">Vendor attribute</param> public virtual void DeleteVendorAttribute(VendorAttribute vendorAttribute) { if (vendorAttribute == null) { throw new ArgumentNullException(nameof(vendorAttribute)); } _vendorAttributeRepository.Delete(vendorAttribute); _cacheManager.RemoveByPattern(VENDORATTRIBUTES_PATTERN_KEY); _cacheManager.RemoveByPattern(VENDORATTRIBUTEVALUES_PATTERN_KEY); //event notification _eventPublisher.EntityDeleted(vendorAttribute); }
/// <summary> /// Updates a vendor attribute /// </summary> /// <param name="vendorAttribute">Vendor attribute</param> public virtual void UpdateVendorAttribute(VendorAttribute vendorAttribute) { if (vendorAttribute == null) { throw new ArgumentNullException(nameof(vendorAttribute)); } _vendorAttributeRepository.Update(vendorAttribute); _cacheManager.RemoveByPattern(GSVendorsServiceDefaults.VendorAttributesPatternCacheKey); _cacheManager.RemoveByPattern(GSVendorsServiceDefaults.VendorAttributeValuesPatternCacheKey); //event notification _eventPublisher.EntityUpdated(vendorAttribute); }
/// <summary> /// Inserts a vendor attribute /// </summary> /// <param name="vendorAttribute">Vendor attribute</param> public virtual void InsertVendorAttribute(VendorAttribute vendorAttribute) { if (vendorAttribute == null) { throw new ArgumentNullException(nameof(vendorAttribute)); } _vendorAttributeRepository.Insert(vendorAttribute); _cacheManager.RemoveByPrefix(QNetVendorsServiceDefaults.VendorAttributesPrefixCacheKey); _cacheManager.RemoveByPrefix(QNetVendorsServiceDefaults.VendorAttributeValuesPrefixCacheKey); //event notification _eventPublisher.EntityInserted(vendorAttribute); }
/// <summary> /// A value indicating whether this vendor attribute should have values /// </summary> /// <param name="vendorAttribute">Vendor attribute</param> /// <returns>True if the attribute should have values; otherwise false</returns> public static bool ShouldHaveValues(this VendorAttribute vendorAttribute) { if (vendorAttribute == null) { return(false); } if (vendorAttribute.AttributeControlType == AttributeControlType.TextBox || vendorAttribute.AttributeControlType == AttributeControlType.MultilineTextbox || vendorAttribute.AttributeControlType == AttributeControlType.Datepicker || vendorAttribute.AttributeControlType == AttributeControlType.FileUpload) { return(false); } //other attribute control types support values return(true); }
public static VendorAttribute ToEntity(this VendorAttributeModel model, VendorAttribute destination) { return(model.MapTo(destination)); }
/// <summary> /// Prepare vendor attribute value search model /// </summary> /// <param name="searchModel">Vendor attribute value search model</param> /// <param name="vendorAttribute">Vendor attribute</param> /// <returns>Vendor attribute value search model</returns> protected virtual VendorAttributeValueSearchModel PrepareVendorAttributeValueSearchModel(VendorAttributeValueSearchModel searchModel, VendorAttribute vendorAttribute) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (vendorAttribute == null) { throw new ArgumentNullException(nameof(vendorAttribute)); } searchModel.VendorAttributeId = vendorAttribute.Id; //prepare page parameters searchModel.SetGridPageSize(); return(searchModel); }
/// <summary> /// Prepare paged vendor attribute value list model /// </summary> /// <param name="searchModel">Vendor attribute value search model</param> /// <param name="vendorAttribute">Vendor attribute</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the vendor attribute value list model /// </returns> public virtual async Task <VendorAttributeValueListModel> PrepareVendorAttributeValueListModelAsync(VendorAttributeValueSearchModel searchModel, VendorAttribute vendorAttribute) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (vendorAttribute == null) { throw new ArgumentNullException(nameof(vendorAttribute)); } //get vendor attribute values var vendorAttributeValues = (await _vendorAttributeService.GetVendorAttributeValuesAsync(vendorAttribute.Id)).ToPagedList(searchModel); //prepare list model var model = new VendorAttributeValueListModel().PrepareToGrid(searchModel, vendorAttributeValues, () => { //fill in model values from the entity return(vendorAttributeValues.Select(value => value.ToModel <VendorAttributeValueModel>())); }); return(model); }
/// <summary> /// Updates a vendor attribute /// </summary> /// <param name="vendorAttribute">Vendor attribute</param> public virtual void UpdateVendorAttribute(VendorAttribute vendorAttribute) { _vendorAttributeRepository.Update(vendorAttribute); }
/// <summary> /// Inserts a vendor attribute /// </summary> /// <param name="vendorAttribute">Vendor attribute</param> public virtual void InsertVendorAttribute(VendorAttribute vendorAttribute) { _vendorAttributeRepository.Insert(vendorAttribute); }
/// <summary> /// Prepare paged vendor attribute value list model /// </summary> /// <param name="searchModel">Vendor attribute value search model</param> /// <param name="vendorAttribute">Vendor attribute</param> /// <returns>Vendor attribute value list model</returns> public virtual VendorAttributeValueListModel PrepareVendorAttributeValueListModel(VendorAttributeValueSearchModel searchModel, VendorAttribute vendorAttribute) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (vendorAttribute == null) { throw new ArgumentNullException(nameof(vendorAttribute)); } //get vendor attribute values var vendorAttributeValues = _vendorAttributeService.GetVendorAttributeValues(vendorAttribute.Id); //prepare list model var model = new VendorAttributeValueListModel { //fill in model values from the entity Data = vendorAttributeValues.PaginationByRequestModel(searchModel).Select(value => value.ToModel <VendorAttributeValueModel>()), Total = vendorAttributeValues.Count }; return(model); }
//attributes public static VendorAttributeModel ToModel(this VendorAttribute entity) { return(entity.MapTo <VendorAttribute, VendorAttributeModel>()); }
/// <summary> /// Deletes a vendor attribute /// </summary> /// <param name="vendorAttribute">Vendor attribute</param> public virtual void DeleteVendorAttribute(VendorAttribute vendorAttribute) { _vendorAttributeRepository.Delete(vendorAttribute); }
/// <summary> /// Deletes a vendor attribute /// </summary> /// <param name="vendorAttribute">Vendor attribute</param> /// <returns>A task that represents the asynchronous operation</returns> public virtual async Task DeleteVendorAttributeAsync(VendorAttribute vendorAttribute) { await _vendorAttributeRepository.DeleteAsync(vendorAttribute); }
/// <summary> /// Inserts a vendor attribute /// </summary> /// <param name="vendorAttribute">Vendor attribute</param> /// <returns>A task that represents the asynchronous operation</returns> public virtual async Task InsertVendorAttributeAsync(VendorAttribute vendorAttribute) { await _vendorAttributeRepository.InsertAsync(vendorAttribute); }