public ActionResult Create(int? categoryId)
        {
            var model = new SnippetModel();

            if (categoryId.HasValue)
                model.CategoryId = categoryId;

            return View(model);
        }
        public ActionResult Create(SnippetModel snippetModel)
        {
            if (!ModelState.IsValid)
                return View(snippetModel);

            var userService = new UserService();
            var categoryService = new CategoryService();

            var snippet = new Snippet();
            snippet.BodyRaw = snippetModel.Snippet.BodyRaw;
            snippet.Body = new Markdown().Transform(snippetModel.Snippet.BodyRaw).ToSafeHtml();
            snippet.DateCreated = DateTime.Now;
            snippet.DateEdited = DateTime.Now;
            snippet.Title = snippetModel.Snippet.Title;
            snippet.Slug = snippetModel.Snippet.Title.Slugify();
            snippet.Author = userService.GetByUsername(User.Identity.Name);
            snippet.Category = categoryService.GetById(snippetModel.CategoryId.Value);

            _snippetService.Create(snippet);
            _snippetService.Save();

            TempData["Message"] = "The snippet has been created. <a href=\"{0}\">View the snippet.</a>".FormatWith(snippet.Link);
            return RedirectToAction("Index");
        }
        public ActionResult Edit(int id, SnippetModel snippetModel)
        {
            if (!ModelState.IsValid)
                return View(snippetModel);

            var categoryService = new CategoryService();
            var snippet = _snippetService.GetById(id);

            if (snippet == null)
                return View("NotFound", new NotFoundModel());

            if (!snippet.CanEdit(User as User))
                return View("AccessDenied");

            snippet.BodyRaw = snippetModel.Snippet.BodyRaw;
            snippet.Body = new Markdown().Transform(snippetModel.Snippet.BodyRaw).ToSafeHtml();
            snippet.DateEdited = DateTime.Now;
            snippet.Title = snippetModel.Snippet.Title;
            snippet.Slug = snippetModel.Snippet.Title.Slugify();
            snippet.Category = categoryService.GetById(snippetModel.CategoryId.Value);

            _snippetService.Save();

            TempData["Message"] = "The snippet has been updated. <a href=\"{0}\">View the snippet.</a>".FormatWith(snippet.Link);
            return RedirectToAction("Index");
        }
        public ActionResult Edit(int id)
        {
            var snippet = _snippetService.GetById(id);

            if (snippet == null)
                return View("NotFound", new NotFoundModel());

            if (!snippet.CanEdit(User as User))
                return View("AccessDenied");

            var model = new SnippetModel(snippet);

            return View(model);
        }