Пример #1
0
        public ActionResult Action(int?Id)
        {
            CategoryActionVm model = new CategoryActionVm();

            if (Id.HasValue)
            {
                var category = CategoriesService.Instance.GetCategoryById(Id.Value);

                if (category == null)
                {
                    return(HttpNotFound());
                }

                model.PageTitle        = "Edit Category";
                model.PageDescription  = string.Format("Edit Category {0}.", category.Name);
                model.ParentCategoryID = category.ParentCategoryId.HasValue ? category.ParentCategoryId.Value : 0;
                model.Id          = category.Id;
                model.Name        = category.Name;
                model.Description = category.Description;
                model.IsFeatured  = category.isFeatured;
            }
            else
            {
                model.PageTitle       = "Create Category";
                model.PageDescription = "Create New Category";
            }

            model.Categories = CategoriesService.Instance.GetAllCategories();

            return(View(model));
        }
Пример #2
0
        public ActionResult Action(CategoryActionVm model)
        {
            if (model.Id > 0)
            {
                var category = CategoriesService.Instance.GetCategoryById(model.Id);
                if (category == null)
                {
                    return(HttpNotFound());
                }

                if (model.ParentCategoryID > 0)
                {
                    category.ParentCategoryId = model.ParentCategoryID;
                }
                else
                {
                    category.ParentCategoryId = null;
                    category.ParentCategory   = null;
                }

                category.Name          = model.Name;
                category.SanitizedName = model.Name.SanitizeLowerString();
                category.Description   = model.Description;
                category.isFeatured    = model.IsFeatured;
                category.DisplaySeqNo  = 1;

                CategoriesService.Instance.UpdateCategory(category);
            }
            else
            {
                Category category = new Category();
                if (model.ParentCategoryID > 0)
                {
                    category.ParentCategoryId = model.ParentCategoryID;
                }

                category.Name          = model.Name;
                category.SanitizedName = model.Name.SanitizeLowerString();
                category.Description   = model.Description;
                category.isFeatured    = model.IsFeatured;
                category.DisplaySeqNo  = 1;

                CategoriesService.Instance.SaveCategory(category);
            }

            return(RedirectToAction("Index"));
        }