/// <summary>
        /// Update a localized checkout attribute value
        /// </summary>
        /// <param name="checkoutAttributeValueLocalized">Localized checkout attribute value</param>
        public void UpdateCheckoutAttributeValueLocalized(CheckoutAttributeValueLocalized checkoutAttributeValueLocalized)
        {
            if (checkoutAttributeValueLocalized == null)
            {
                throw new ArgumentNullException("checkoutAttributeValueLocalized");
            }

            checkoutAttributeValueLocalized.Name = CommonHelper.EnsureNotNull(checkoutAttributeValueLocalized.Name);
            checkoutAttributeValueLocalized.Name = CommonHelper.EnsureMaximumLength(checkoutAttributeValueLocalized.Name, 100);

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


            if (!_context.IsAttached(checkoutAttributeValueLocalized))
            {
                _context.CheckoutAttributeValueLocalized.Attach(checkoutAttributeValueLocalized);
            }

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

            if (this.CacheEnabled)
            {
                _cacheManager.RemoveByPattern(CHECKOUTATTRIBUTES_PATTERN_KEY);
                _cacheManager.RemoveByPattern(CHECKOUTATTRIBUTEVALUES_PATTERN_KEY);
            }
        }
        private static CheckoutAttributeValueLocalized DBMapping(DBCheckoutAttributeValueLocalized dbItem)
        {
            if (dbItem == null)
            {
                return(null);
            }

            var item = new CheckoutAttributeValueLocalized();

            item.CheckoutAttributeValueLocalizedId = dbItem.CheckoutAttributeValueLocalizedId;
            item.CheckoutAttributeValueId          = dbItem.CheckoutAttributeValueId;
            item.LanguageId = dbItem.LanguageId;
            item.Name       = dbItem.Name;

            return(item);
        }
        /// <summary>
        /// Inserts a localized checkout attribute value
        /// </summary>
        /// <param name="checkoutAttributeValueLocalized">Localized checkout attribute value</param>
        public void InsertCheckoutAttributeValueLocalized(CheckoutAttributeValueLocalized checkoutAttributeValueLocalized)
        {
            if (checkoutAttributeValueLocalized == null)
            {
                throw new ArgumentNullException("checkoutAttributeValueLocalized");
            }

            checkoutAttributeValueLocalized.Name = CommonHelper.EnsureNotNull(checkoutAttributeValueLocalized.Name);
            checkoutAttributeValueLocalized.Name = CommonHelper.EnsureMaximumLength(checkoutAttributeValueLocalized.Name, 100);



            _context.CheckoutAttributeValueLocalized.AddObject(checkoutAttributeValueLocalized);
            _context.SaveChanges();

            if (this.CacheEnabled)
            {
                _cacheManager.RemoveByPattern(CHECKOUTATTRIBUTES_PATTERN_KEY);
                _cacheManager.RemoveByPattern(CHECKOUTATTRIBUTEVALUES_PATTERN_KEY);
            }
        }
        protected void SaveLocalizableContentGrid(CheckoutAttributeValue cav)
        {
            if (cav == null)
                return;

            if (!this.HasLocalizableContent)
                return;

            foreach (GridViewRow row in gvValues.Rows)
            {
                Repeater rptrLanguageDivs2 = row.FindControl("rptrLanguageDivs2") as Repeater;
                if (rptrLanguageDivs2 != null)
                {
                    HiddenField hfCheckoutAttributeValueId = row.FindControl("hfCheckoutAttributeValueId") as HiddenField;
                    int cavId = int.Parse(hfCheckoutAttributeValueId.Value);
                    if (cavId == cav.CheckoutAttributeValueId)
                    {
                        foreach (RepeaterItem item in rptrLanguageDivs2.Items)
                        {
                            if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                            {
                                var txtLocalizedName = (TextBox)item.FindControl("txtLocalizedName");
                                var lblLanguageId = (Label)item.FindControl("lblLanguageId");

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

                                bool allFieldsAreEmpty = string.IsNullOrEmpty(name);

                                var content = this.CheckoutAttributeService.GetCheckoutAttributeValueLocalizedByCheckoutAttributeValueIdAndLanguageId(cav.CheckoutAttributeValueId, 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 CheckoutAttributeValueLocalized()
                                        {
                                            CheckoutAttributeValueId = cav.CheckoutAttributeValueId,
                                            LanguageId = languageId,
                                            Name = name
                                        };
                                        this.CheckoutAttributeService.InsertCheckoutAttributeValueLocalized(content);
                                    }
                                }
                                else
                                {
                                    if (languageId > 0)
                                    {
                                        content.LanguageId = languageId;
                                        content.Name = name;
                                        this.CheckoutAttributeService.UpdateCheckoutAttributeValueLocalized(content);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }