/// <summary> /// Prepare specification attribute model /// </summary> /// <param name="model">Specification attribute model</param> /// <param name="specificationAttribute">Specification attribute</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns>Specification attribute model</returns> public virtual SpecificationAttributeModel PrepareSpecificationAttributeModel(SpecificationAttributeModel model, SpecificationAttribute specificationAttribute, bool excludeProperties = false) { Action <SpecificationAttributeLocalizedModel, int> localizedModelConfiguration = null; if (specificationAttribute != null) { //fill in model values from the entity model ??= specificationAttribute.ToModel <SpecificationAttributeModel>(); //prepare nested search models PrepareSpecificationAttributeOptionSearchModel(model.SpecificationAttributeOptionSearchModel, specificationAttribute); PrepareSpecificationAttributeProductSearchModel(model.SpecificationAttributeProductSearchModel, specificationAttribute); //define localized model configuration action localizedModelConfiguration = (locale, languageId) => { locale.Name = _localizationService.GetLocalized(specificationAttribute, entity => entity.Name, languageId, false, false); }; } //prepare localized models if (!excludeProperties) { model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration); } return(model); }
/// <summary> /// Prepare specification attribute model /// </summary> /// <param name="model">Specification attribute model</param> /// <param name="specificationAttribute">Specification attribute</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 specification attribute model /// </returns> public virtual async Task <SpecificationAttributeModel> PrepareSpecificationAttributeModelAsync(SpecificationAttributeModel model, SpecificationAttribute specificationAttribute, bool excludeProperties = false) { Func <SpecificationAttributeLocalizedModel, int, Task> localizedModelConfiguration = null; if (specificationAttribute != null) { //fill in model values from the entity model ??= specificationAttribute.ToModel <SpecificationAttributeModel>(); //prepare nested search models PrepareSpecificationAttributeOptionSearchModel(model.SpecificationAttributeOptionSearchModel, specificationAttribute); PrepareSpecificationAttributeProductSearchModel(model.SpecificationAttributeProductSearchModel, specificationAttribute); //define localized model configuration action localizedModelConfiguration = async(locale, languageId) => { locale.Name = await _localizationService.GetLocalizedAsync(specificationAttribute, entity => entity.Name, languageId, false, false); }; } //prepare localized models if (!excludeProperties) { model.Locales = await _localizedModelFactory.PrepareLocalizedModelsAsync(localizedModelConfiguration); await _baseAdminModelFactory.PrepareSpecificationAttributeGroupsAsync(model.AvailableGroups, defaultItemText : await _localizationService.GetResourceAsync("Admin.Catalog.Attributes.SpecificationAttributes.SpecificationAttribute.Fields.SpecificationAttributeGroup.None")); } return(model); }
public async Task <IHttpActionResult> Delete(int id) { SpecificationAttribute entity = await SpecificationAttributeService.FindOneAsync(id); if (entity == null) { return(NotFound()); } await SpecificationAttributeService.DeleteAsync(entity); return(Ok(entity.ToModel())); }