Example #1
0
        private static SpecificationAttributeOptionLocalized DBMapping(DBSpecificationAttributeOptionLocalized dbItem)
        {
            if (dbItem == null)
            {
                return(null);
            }

            var item = new SpecificationAttributeOptionLocalized();

            item.SpecificationAttributeOptionLocalizedId = dbItem.SpecificationAttributeOptionLocalizedId;
            item.SpecificationAttributeOptionId          = dbItem.SpecificationAttributeOptionId;
            item.LanguageId = dbItem.LanguageId;
            item.Name       = dbItem.Name;

            return(item);
        }
Example #2
0
        /// <summary>
        /// Inserts a localized specification attribute option
        /// </summary>
        /// <param name="specificationAttributeOptionLocalized">Localized specification attribute option</param>
        /// <returns>Localized specification attribute option</returns>
        public void InsertSpecificationAttributeOptionLocalized(SpecificationAttributeOptionLocalized specificationAttributeOptionLocalized)
        {
            if (specificationAttributeOptionLocalized == null)
            {
                throw new ArgumentNullException("specificationAttributeOptionLocalized");
            }

            specificationAttributeOptionLocalized.Name = CommonHelper.EnsureNotNull(specificationAttributeOptionLocalized.Name);
            specificationAttributeOptionLocalized.Name = CommonHelper.EnsureMaximumLength(specificationAttributeOptionLocalized.Name, 500);



            _context.SpecificationAttributeOptionLocalized.AddObject(specificationAttributeOptionLocalized);
            _context.SaveChanges();

            if (this.CacheEnabled)
            {
                _cacheManager.RemoveByPattern(SPECIFICATIONATTRIBUTE_PATTERN_KEY);
                _cacheManager.RemoveByPattern(SPECIFICATIONATTRIBUTEOPTION_PATTERN_KEY);
                _cacheManager.RemoveByPattern(PRODUCTSPECIFICATIONATTRIBUTE_PATTERN_KEY);
            }
        }
Example #3
0
        /// <summary>
        /// Update a localized specification attribute option
        /// </summary>
        /// <param name="specificationAttributeOptionLocalized">Localized specification attribute option</param>
        /// <returns>Localized specification attribute option</returns>
        public void UpdateSpecificationAttributeOptionLocalized(SpecificationAttributeOptionLocalized specificationAttributeOptionLocalized)
        {
            if (specificationAttributeOptionLocalized == null)
            {
                throw new ArgumentNullException("specificationAttributeOptionLocalized");
            }

            specificationAttributeOptionLocalized.Name = CommonHelper.EnsureNotNull(specificationAttributeOptionLocalized.Name);
            specificationAttributeOptionLocalized.Name = CommonHelper.EnsureMaximumLength(specificationAttributeOptionLocalized.Name, 500);

            bool allFieldsAreEmpty = string.IsNullOrEmpty(specificationAttributeOptionLocalized.Name);


            if (!_context.IsAttached(specificationAttributeOptionLocalized))
            {
                _context.SpecificationAttributeOptionLocalized.Attach(specificationAttributeOptionLocalized);
            }

            if (allFieldsAreEmpty)
            {
                //delete if all fields are empty
                _context.DeleteObject(specificationAttributeOptionLocalized);
                _context.SaveChanges();
            }
            else
            {
                _context.SaveChanges();
            }

            if (this.CacheEnabled)
            {
                _cacheManager.RemoveByPattern(SPECIFICATIONATTRIBUTE_PATTERN_KEY);
                _cacheManager.RemoveByPattern(SPECIFICATIONATTRIBUTEOPTION_PATTERN_KEY);
                _cacheManager.RemoveByPattern(PRODUCTSPECIFICATIONATTRIBUTE_PATTERN_KEY);
            }
        }
        protected void SaveLocalizableContentGrid(SpecificationAttributeOption sao)
        {
            if (sao == null)
                return;

            if (!this.HasLocalizableContent)
                return;

            foreach (GridViewRow row in grdSpecificationAttributeOptions.Rows)
            {
                Repeater rptrLanguageDivs2 = row.FindControl("rptrLanguageDivs2") as Repeater;
                if (rptrLanguageDivs2 != null)
                {
                    HiddenField hfSpecificationAttributeOptionId = row.FindControl("hfSpecificationAttributeOptionId") as HiddenField;
                    int saoId = int.Parse(hfSpecificationAttributeOptionId.Value);
                    if (saoId == sao.SpecificationAttributeOptionId)
                    {
                        foreach (RepeaterItem item in rptrLanguageDivs2.Items)
                        {
                            if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                            {
                                var txtLocalizedOptionName = (TextBox)item.FindControl("txtLocalizedOptionName");
                                var lblLanguageId = (Label)item.FindControl("lblLanguageId");

                                int languageId = int.Parse(lblLanguageId.Text);
                                string name = txtLocalizedOptionName.Text;

                                bool allFieldsAreEmpty = string.IsNullOrEmpty(name);

                                var content = this.SpecificationAttributeService.GetSpecificationAttributeOptionLocalizedBySpecificationAttributeOptionIdAndLanguageId(sao.SpecificationAttributeOptionId, languageId);
                                if (content == null)
                                {
                                    if (!allFieldsAreEmpty && languageId > 0)
                                    {
                                        //only insert if one of the fields are filled out (avoid too many empty records in db...)
                                        content = new SpecificationAttributeOptionLocalized()
                                        {
                                            SpecificationAttributeOptionId = sao.SpecificationAttributeOptionId,
                                            LanguageId = languageId,
                                            Name = name
                                        };
                                        this.SpecificationAttributeService.InsertSpecificationAttributeOptionLocalized(content);
                                    }
                                }
                                else
                                {
                                    if (languageId > 0)
                                    {
                                        content.LanguageId = languageId;
                                        content.Name = name;
                                        this.SpecificationAttributeService.UpdateSpecificationAttributeOptionLocalized(content);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }