public CategoryModel(Category category)
        {
            Category = category;
            CategoryList = new CategoryService().GetCategoryList();

            if (Category != null && Category.ParentCategory != null)
                ParentCategoryId = Category.ParentCategory.CategoryId;
        }
Exemple #2
0
        public Snippet(string title, string bodyRaw, Category category, User author)
        {
            Title = title;
            Slug = title.Slugify();
            BodyRaw = bodyRaw;
            Category = category;
            Author = author;
            DateCreated = DateTime.Now;
            DateEdited = DateTime.Now;

            Markdown m = new Markdown();
            Body = m.Transform(bodyRaw);
        }
        public void GenerateSampleData(DatabaseContext context)
        {
            var user = new User("admin", "5447aed2fdae62d1a4ce8b832beaf865");
            user.Role = Role.SuperAdmin;

            var category1 = new Category("Sample");
            var category2 = new Category("JavaScript");
            var category3 = new Category("HTML");
            var category4 = new Category("CSS");

            context.Categories.Add(category1);
            context.Categories.Add(category2);
            context.Categories.Add(category3);
            context.Categories.Add(category4);

            var snippet1 = new Snippet("Welcome to Snippet Box", "This snippet post is a sample. Login to your new Snippet Box with admin/admin.", category1, user);
            context.Users.Add(user);
            context.Snippets.Add(snippet1);
        }
        public ActionResult Create(CategoryModel categoryModel)
        {
            if (!ModelState.IsValid)
                return View(categoryModel);

            var category = new Category();
            category.Name = categoryModel.Category.Name;
            category.Slug = categoryModel.Category.Slug ?? category.Name.Slugify();
            category.ParentCategory = categoryModel.ParentCategoryId.HasValue
                 ? _categoryService.GetById(categoryModel.ParentCategoryId.Value)
                 : null;

            _categoryService.Create(category);
            _categoryService.Save();

            _cache.RemoveAll("categoryMenu");

            return RedirectToAction("Index");
        }
Exemple #5
0
        private static void AppendSubCategories(StringBuilder sb, Category category, int currentCategoryId, int tabs)
        {
            var childrenCategories = category.ChildrenCategories.Where(cat => !cat.IsDeleted).ToList();

            if (!childrenCategories.Any())
                return;

            sb.AppendWithTabs("<ul>", tabs);

            foreach (var childrenCategory in childrenCategories.OrderBy(x => x.Name)) {
                var isCurrent = currentCategoryId == childrenCategory.CategoryId;

                sb.AppendWithTabs("<li>", tabs + 1);
                sb.AppendWithTabs("<a href=\"{0}\"{1}>{2}</a> <span class=\"count\">({3})</span>".FormatWith(childrenCategory.Link, isCurrent ? "class=\"current\"" : "", childrenCategory.Name, childrenCategory.Snippets.Count), tabs + 2);

                if (childrenCategory.ChildrenCategories != null) {
                    AppendSubCategories(sb, childrenCategory, currentCategoryId, tabs + 2);
                }

                sb.AppendWithTabs("</li>", tabs + 1);
            }

            sb.AppendWithTabs("</ul>", tabs);
        }
 public CategoryDetailsModel(Category category, IPagedList<Snippet> snippets)
 {
     Category = category;
     Snippets = snippets;
 }
Exemple #7
0
 public Category(string name, Category parentCategory)
 {
     Name = name;
     ParentCategory = parentCategory;
     Slug = name.Slugify();
 }