Example #1
0
        /// <summary>
        /// Updates the category template
        /// </summary>
        /// <param name="categoryTemplate">Category template</param>
        public void UpdateCategoryTemplate(CategoryTemplate categoryTemplate)
        {
            if (categoryTemplate == null)
            {
                throw new ArgumentNullException("categoryTemplate");
            }

            categoryTemplate.Name         = CommonHelper.EnsureNotNull(categoryTemplate.Name);
            categoryTemplate.Name         = CommonHelper.EnsureMaximumLength(categoryTemplate.Name, 100);
            categoryTemplate.TemplatePath = CommonHelper.EnsureNotNull(categoryTemplate.TemplatePath);
            categoryTemplate.TemplatePath = CommonHelper.EnsureMaximumLength(categoryTemplate.TemplatePath, 200);


            if (!_context.IsAttached(categoryTemplate))
            {
                _context.CategoryTemplates.Attach(categoryTemplate);
            }

            _context.SaveChanges();

            if (this.CacheEnabled)
            {
                _cacheManager.RemoveByPattern(CATEGORYTEMPLATES_PATTERN_KEY);
            }
        }
        public CategoryTemplate SaveInfo()
        {
            CategoryTemplate categoryTemplate = this.TemplateService.GetCategoryTemplateById(this.CategoryTemplateId);

            if (categoryTemplate != null)
            {
                categoryTemplate.Name = txtName.Text;
                categoryTemplate.TemplatePath = txtTemplatePath.Text;
                categoryTemplate.DisplayOrder = txtDisplayOrder.Value;
                categoryTemplate.UpdatedOn = DateTime.UtcNow;
                this.TemplateService.UpdateCategoryTemplate(categoryTemplate);
            }
            else
            {
                DateTime now = DateTime.UtcNow;
                categoryTemplate = new CategoryTemplate()
                {
                    Name = txtName.Text,
                    TemplatePath = txtTemplatePath.Text,
                    DisplayOrder = txtDisplayOrder.Value,
                    CreatedOn = now,
                    UpdatedOn = now
                };
                this.TemplateService.InsertCategoryTemplate(categoryTemplate);
            }

            return categoryTemplate;
        }
        /// <summary>
        /// Gets a category template
        /// </summary>
        /// <param name="CategoryTemplateID">Category template identifier</param>
        /// <returns>A category template</returns>
        public static CategoryTemplate GetCategoryTemplateByID(int CategoryTemplateID)
        {
            if (CategoryTemplateID == 0)
            {
                return(null);
            }

            string key  = string.Format(CATEGORYTEMPLATES_BY_ID_KEY, CategoryTemplateID);
            object obj2 = NopCache.Get(key);

            if (TemplateManager.CacheEnabled && (obj2 != null))
            {
                return((CategoryTemplate)obj2);
            }

            DBCategoryTemplate dbItem = DBProviderManager <DBTemplateProvider> .Provider.GetCategoryTemplateByID(CategoryTemplateID);

            CategoryTemplate categoryTemplate = DBMapping(dbItem);

            if (TemplateManager.CacheEnabled)
            {
                NopCache.Max(key, categoryTemplate);
            }
            return(categoryTemplate);
        }
        private static CategoryTemplateCollection DBMapping(DBCategoryTemplateCollection dbCollection)
        {
            if (dbCollection == null)
            {
                return(null);
            }

            CategoryTemplateCollection collection = new CategoryTemplateCollection();

            foreach (DBCategoryTemplate dbItem in dbCollection)
            {
                CategoryTemplate item = DBMapping(dbItem);
                collection.Add(item);
            }

            return(collection);
        }
Example #5
0
        private static CategoryTemplate DBMapping(DBCategoryTemplate dbItem)
        {
            if (dbItem == null)
            {
                return(null);
            }

            var item = new CategoryTemplate();

            item.CategoryTemplateId = dbItem.CategoryTemplateId;
            item.Name         = dbItem.Name;
            item.TemplatePath = dbItem.TemplatePath;
            item.DisplayOrder = dbItem.DisplayOrder;
            item.CreatedOn    = dbItem.CreatedOn;
            item.UpdatedOn    = dbItem.UpdatedOn;

            return(item);
        }
        /// <summary>
        /// Updates the category template
        /// </summary>
        /// <param name="CategoryTemplateID">Category template identifier</param>
        /// <param name="Name">The name</param>
        /// <param name="TemplatePath">The template path</param>
        /// <param name="DisplayOrder">The display order</param>
        /// <param name="CreatedOn">The date and time of instance creation</param>
        /// <param name="UpdatedOn">The date and time of instance update</param>
        /// <returns>A category template</returns>
        public static CategoryTemplate UpdateCategoryTemplate(int CategoryTemplateID, string Name, string TemplatePath,
                                                              int DisplayOrder, DateTime CreatedOn, DateTime UpdatedOn)
        {
            CreatedOn = DateTimeHelper.ConvertToUtcTime(CreatedOn);
            UpdatedOn = DateTimeHelper.ConvertToUtcTime(UpdatedOn);

            DBCategoryTemplate dbItem = DBProviderManager <DBTemplateProvider> .Provider.UpdateCategoryTemplate(CategoryTemplateID, Name, TemplatePath,
                                                                                                                DisplayOrder, CreatedOn, UpdatedOn);

            CategoryTemplate categoryTemplate = DBMapping(dbItem);

            if (TemplateManager.CacheEnabled)
            {
                NopCache.RemoveByPattern(CATEGORYTEMPLATES_PATTERN_KEY);
            }

            return(categoryTemplate);
        }
Example #7
0
        /// <summary>
        /// Updates the category template
        /// </summary>
        /// <param name="categoryTemplate">Category template</param>
        public void UpdateCategoryTemplate(CategoryTemplate categoryTemplate)
        {
            if (categoryTemplate == null)
                throw new ArgumentNullException("categoryTemplate");

            categoryTemplate.Name = CommonHelper.EnsureNotNull(categoryTemplate.Name);
            categoryTemplate.Name = CommonHelper.EnsureMaximumLength(categoryTemplate.Name, 100);
            categoryTemplate.TemplatePath = CommonHelper.EnsureNotNull(categoryTemplate.TemplatePath);
            categoryTemplate.TemplatePath = CommonHelper.EnsureMaximumLength(categoryTemplate.TemplatePath, 200);

            if (!_context.IsAttached(categoryTemplate))
                _context.CategoryTemplates.Attach(categoryTemplate);

            _context.SaveChanges();

            if (this.CacheEnabled)
            {
                _cacheManager.RemoveByPattern(CATEGORYTEMPLATES_PATTERN_KEY);
            }
        }