Exemplo n.º 1
0
        /// <summary>
        /// Prepare product attribute model
        /// </summary>
        /// <param name="model">Product attribute model</param>
        /// <param name="productAttribute">Product attribute</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Product attribute model</returns>
        public virtual ProductAttributeModel PrepareProductAttributeModel(ProductAttributeModel model,
                                                                          ProductAttribute productAttribute, bool excludeProperties = false)
        {
            Action <ProductAttributeLocalizedModel, int> localizedModelConfiguration = null;

            if (productAttribute != null)
            {
                //fill in model values from the entity
                model = model ?? productAttribute.ToModel <ProductAttributeModel>();

                //prepare nested search models
                PreparePredefinedProductAttributeValueSearchModel(model.PredefinedProductAttributeValueSearchModel, productAttribute);
                PrepareProductAttributeProductSearchModel(model.ProductAttributeProductSearchModel, productAttribute);

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name        = _localizationService.GetLocalized(productAttribute, entity => entity.Name, languageId, false, false);
                    locale.Description = _localizationService.GetLocalized(productAttribute, entity => entity.Description, languageId, false, false);
                };
            }

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            return(model);
        }
Exemplo n.º 2
0
        public async Task <IHttpActionResult> Delete(int id)
        {
            ProductAttribute entity = await ProductAttributeService.FindOneAsync(id);

            if (entity == null)
            {
                return(NotFound());
            }
            await ProductAttributeService.DeleteAsync(entity);

            return(Ok(entity.ToModel()));
        }