Exemple #1
0
        /// <summary>
        /// Inserts a localized category
        /// </summary>
        /// <param name="categoryLocalized">Localized category</param>
        public void InsertCategoryLocalized(CategoryLocalized categoryLocalized)
        {
            if (categoryLocalized == null)
            {
                throw new ArgumentNullException("categoryLocalized");
            }

            categoryLocalized.Name            = CommonHelper.EnsureNotNull(categoryLocalized.Name);
            categoryLocalized.Name            = CommonHelper.EnsureMaximumLength(categoryLocalized.Name, 400);
            categoryLocalized.Description     = CommonHelper.EnsureNotNull(categoryLocalized.Description);
            categoryLocalized.MetaKeywords    = CommonHelper.EnsureNotNull(categoryLocalized.MetaKeywords);
            categoryLocalized.MetaKeywords    = CommonHelper.EnsureMaximumLength(categoryLocalized.MetaKeywords, 400);
            categoryLocalized.MetaDescription = CommonHelper.EnsureNotNull(categoryLocalized.MetaDescription);
            categoryLocalized.MetaDescription = CommonHelper.EnsureMaximumLength(categoryLocalized.MetaDescription, 4000);
            categoryLocalized.MetaTitle       = CommonHelper.EnsureNotNull(categoryLocalized.MetaTitle);
            categoryLocalized.MetaTitle       = CommonHelper.EnsureMaximumLength(categoryLocalized.MetaTitle, 400);
            categoryLocalized.SEName          = CommonHelper.EnsureNotNull(categoryLocalized.SEName);
            categoryLocalized.SEName          = CommonHelper.EnsureMaximumLength(categoryLocalized.SEName, 100);



            _context.CategoryLocalized.AddObject(categoryLocalized);
            _context.SaveChanges();

            if (this.CategoriesCacheEnabled)
            {
                _cacheManager.RemoveByPattern(CATEGORIES_PATTERN_KEY);
            }
        }
Exemple #2
0
        /// <summary>
        /// Update a localized category
        /// </summary>
        /// <param name="categoryLocalized">Localized category</param>
        public void UpdateCategoryLocalized(CategoryLocalized categoryLocalized)
        {
            if (categoryLocalized == null)
            {
                throw new ArgumentNullException("categoryLocalized");
            }

            categoryLocalized.Name            = CommonHelper.EnsureNotNull(categoryLocalized.Name);
            categoryLocalized.Name            = CommonHelper.EnsureMaximumLength(categoryLocalized.Name, 400);
            categoryLocalized.Description     = CommonHelper.EnsureNotNull(categoryLocalized.Description);
            categoryLocalized.MetaKeywords    = CommonHelper.EnsureNotNull(categoryLocalized.MetaKeywords);
            categoryLocalized.MetaKeywords    = CommonHelper.EnsureMaximumLength(categoryLocalized.MetaKeywords, 400);
            categoryLocalized.MetaDescription = CommonHelper.EnsureNotNull(categoryLocalized.MetaDescription);
            categoryLocalized.MetaDescription = CommonHelper.EnsureMaximumLength(categoryLocalized.MetaDescription, 4000);
            categoryLocalized.MetaTitle       = CommonHelper.EnsureNotNull(categoryLocalized.MetaTitle);
            categoryLocalized.MetaTitle       = CommonHelper.EnsureMaximumLength(categoryLocalized.MetaTitle, 400);
            categoryLocalized.SEName          = CommonHelper.EnsureNotNull(categoryLocalized.SEName);
            categoryLocalized.SEName          = CommonHelper.EnsureMaximumLength(categoryLocalized.SEName, 100);

            bool allFieldsAreEmpty = string.IsNullOrEmpty(categoryLocalized.Name) &&
                                     string.IsNullOrEmpty(categoryLocalized.Description) &&
                                     string.IsNullOrEmpty(categoryLocalized.MetaKeywords) &&
                                     string.IsNullOrEmpty(categoryLocalized.MetaDescription) &&
                                     string.IsNullOrEmpty(categoryLocalized.MetaTitle) &&
                                     string.IsNullOrEmpty(categoryLocalized.SEName);


            if (!_context.IsAttached(categoryLocalized))
            {
                _context.CategoryLocalized.Attach(categoryLocalized);
            }

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

            if (this.CategoriesCacheEnabled)
            {
                _cacheManager.RemoveByPattern(CATEGORIES_PATTERN_KEY);
            }
        }
Exemple #3
0
        private static CategoryLocalized DBMapping(DBCategoryLocalized dbItem)
        {
            if (dbItem == null)
            {
                return(null);
            }

            var item = new CategoryLocalized();

            item.CategoryLocalizedId = dbItem.CategoryLocalizedId;
            item.CategoryId          = dbItem.CategoryId;
            item.LanguageId          = dbItem.LanguageId;
            item.Name            = dbItem.Name;
            item.Description     = dbItem.Description;
            item.MetaKeywords    = dbItem.MetaKeywords;
            item.MetaDescription = dbItem.MetaDescription;
            item.MetaTitle       = dbItem.MetaTitle;
            item.SEName          = dbItem.SEName;

            return(item);
        }
        protected void SaveLocalizableContent(Category category)
        {
            if (category == null)
                return;

            if (!this.HasLocalizableContent)
                return;

            foreach (RepeaterItem item in rptrLanguageDivs.Items)
            {
                if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                {
                    var txtLocalizedMetaKeywords = (TextBox)item.FindControl("txtLocalizedMetaKeywords");
                    var txtLocalizedMetaDescription = (TextBox)item.FindControl("txtLocalizedMetaDescription");
                    var txtLocalizedMetaTitle = (TextBox)item.FindControl("txtLocalizedMetaTitle");
                    var txtLocalizedSEName = (TextBox)item.FindControl("txtLocalizedSEName");
                    var lblLanguageId = (Label)item.FindControl("lblLanguageId");

                    int languageId = int.Parse(lblLanguageId.Text);
                    string metaKeywords = txtLocalizedMetaKeywords.Text;
                    string metaDescription = txtLocalizedMetaDescription.Text;
                    string metaTitle = txtLocalizedMetaTitle.Text;
                    string seName = txtLocalizedSEName.Text;

                    bool allFieldsAreEmpty = (string.IsNullOrEmpty(metaKeywords) &&
                        string.IsNullOrEmpty(metaDescription) &&
                        string.IsNullOrEmpty(metaTitle) &&
                        string.IsNullOrEmpty(seName));

                    var content = this.CategoryService.GetCategoryLocalizedByCategoryIdAndLanguageId(category.CategoryId, 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 CategoryLocalized()
                            {
                                CategoryId = category.CategoryId,
                                LanguageId = languageId,
                                MetaKeywords = metaKeywords,
                                MetaDescription = metaDescription,
                                MetaTitle = metaTitle,
                                SEName = seName
                            };

                            this.CategoryService.InsertCategoryLocalized(content);
                        }
                    }
                    else
                    {
                        if (languageId > 0)
                        {
                            content.LanguageId = languageId;
                            content.MetaKeywords = metaKeywords;
                            content.MetaDescription = metaDescription;
                            content.MetaTitle = metaTitle;
                            content.SEName = seName;

                            this.CategoryService.UpdateCategoryLocalized(content);
                        }
                    }
                }
            }
        }
        protected void SaveLocalizableContent(Category category)
        {
            if (category == null)
                return;

            if (!this.HasLocalizableContent)
                return;

            foreach (RepeaterItem item in rptrLanguageDivs.Items)
            {
                if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                {
                    var txtLocalizedCategoryName = (TextBox)item.FindControl("txtLocalizedCategoryName");
                    var txtLocalizedDescription = (FCKeditor)item.FindControl("txtLocalizedDescription");
                    var lblLanguageId = (Label)item.FindControl("lblLanguageId");

                    int languageId = int.Parse(lblLanguageId.Text);
                    string name = txtLocalizedCategoryName.Text;
                    string description = txtLocalizedDescription.Value;

                    bool allFieldsAreEmpty = (string.IsNullOrEmpty(name) && string.IsNullOrEmpty(description));

                    var content = this.CategoryService.GetCategoryLocalizedByCategoryIdAndLanguageId(category.CategoryId, 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 CategoryLocalized()
                            {
                                CategoryId = category.CategoryId,
                                LanguageId = languageId,
                                Name = name,
                                Description = description
                            };

                            this.CategoryService.InsertCategoryLocalized(content);
                        }
                    }
                    else
                    {
                        if (languageId > 0)
                        {
                            content.LanguageId = languageId;
                            content.Name = name;
                            content.Description = description;

                            this.CategoryService.UpdateCategoryLocalized(content);
                        }
                    }
                }
            }
        }