Exemple #1
0
        public ActionResult Translate(string culture, ProductModel model, string @return)
        {
            var product     = CurrentInstance.Database.Repository <Product>().Find(model.Id);
            var productType = product.ProductType;
            var controls    = FormControls.Controls().ToList();

            var translations = new List <PropertyTranslation>();

            translations.Add(new PropertyTranslation("Name", product.Name, model.Name));

            foreach (var definition in productType.CustomFieldDefinitions)
            {
                var field   = model.CustomFields.FirstOrDefault(c => c.FieldName == definition.Name);
                var control = controls.Find(c => c.Name == definition.ControlType);

                if (!control.IsSelectionList && !control.IsValuesPredefined)
                {
                    var originalField = product.CustomFields.FirstOrDefault(f => f.FieldName == definition.Name);
                    translations.Add(new PropertyTranslation("CustomFields[" + field.FieldName + "]", originalField == null ? null : originalField.FieldValue, field.FieldValue));
                }
            }

            _translationStore.AddOrUpdate(CultureInfo.GetCultureInfo(culture), new EntityKey(typeof(Product), model.Id), translations);

            foreach (var variant in model.Variants)
            {
                var originalVariant = product.Variants.FirstOrDefault(v => v.Id == variant.Id);
                var variantKey      = new EntityKey(typeof(ProductVariant), variant.Id);
                _translationStore.AddOrUpdate(CultureInfo.GetCultureInfo(culture), variantKey, GetVariantTranslations(variant, originalVariant, productType, controls));
            }

            return(AjaxForm().RedirectTo(@return));
        }
Exemple #2
0
        public ActionResult Translate(string culture, CategoryModel model, string @return)
        {
            var key      = new EntityKey(typeof(Category), model.Id);
            var category = _repository.Find(model.Id);

            _translationStore.AddOrUpdate(CultureInfo.GetCultureInfo(culture), key, new List <PropertyTranslation>
            {
                new PropertyTranslation("Name", category.Name, model.Name),
                new PropertyTranslation("Description", category.Description, model.Description)
            });

            return(AjaxForm().RedirectTo(@return));
        }
Exemple #3
0
        public ActionResult Translate(BrandModel model, string culture, string @return)
        {
            var brandKey = new EntityKey(typeof(Brand), model.Id);
            var brand    = _brandService.Find(model.Id);

            var props = new List <PropertyTranslation>
            {
                new PropertyTranslation("Name", brand.Name, model.Name),
                new PropertyTranslation("Description", brand.Description, model.Description)
            };

            _translationStore.AddOrUpdate(CultureInfo.GetCultureInfo(culture), brandKey, props);

            return(AjaxForm().RedirectTo(@return));
        }
        public ActionResult Translate(int id, string culture, ProductTypeModel model, string @return)
        {
            var entityKey   = new EntityKey(typeof(ProductType), id);
            var productType = _repository.Find(model.Id);

            var props = new List <PropertyTranslation>();

            foreach (var field in model.CustomFieldDefinitions)
            {
                var originalField = productType.CustomFieldDefinitions.Find(field.Id);
                UpdateFieldTranslation(originalField, field, "CustomFieldDefinitions[" + field.Name + "].", props);
            }
            foreach (var field in model.VariantFieldDefinitions)
            {
                var originalField = productType.VariantFieldDefinitions.Find(field.Id);
                UpdateFieldTranslation(originalField, field, "VariantFieldDefinitions[" + field.Name + "].", props);
            }

            _translationStore.AddOrUpdate(CultureInfo.GetCultureInfo(culture), entityKey, props);

            return(AjaxForm().RedirectTo(@return));
        }