コード例 #1
0
ファイル: BlogController.cs プロジェクト: sgwill/familyblog
        public ActionResult Create(BlogCreateModel viewData)
        {
            EnsureInjectables();

            if (string.IsNullOrEmpty(viewData.Title))
                ModelState.AddModelError("Title", "You must supply a Title");
            if (string.IsNullOrEmpty(viewData.Entry))
                viewData.Entry = Request.Form["textEntry"];
            if (string.IsNullOrEmpty(viewData.Entry))
                ModelState.AddModelError("Entry", "You must enter your Entry!");
            var previousEntry = BlogRepository.LoadBySlug(viewData.Title.BlogUrl());
            if (previousEntry != null)
                ModelState.AddModelError("DuplicateTitle", "An Entry with this Title already exists. Please enter a different Title.");

            if (!ModelState.IsValid)
                return View("Create", viewData);

            var blogEntry = BlogRepository.New();
            TryUpdateModel<IBlog>(blogEntry);
            BlogRepository.Save(blogEntry);

            if (blogEntry.IsPublished)
            {
                Cache.Remove(new BlogListCacheKey().GenerateKey("SidebarList"));
                Cache.Remove(new BlogListCountCacheKey().GenerateKey(blogEntry.AuthorName));
                // todo - clear family too
            }

            return RedirectToAction("UserList");
        }
コード例 #2
0
ファイル: BlogController.cs プロジェクト: sgwill/familyblog
        public ActionResult Create(string user)
        {
            EnsureInjectables();

            if (user.ToLower() != HttpContext.User.Identity.Name.ToLower())
                return RedirectToAction("Create", "Blog", new { user = HttpContext.User.Identity.Name });

            var dbUser = UserRepository.Load(user);
            if (dbUser == null)
            {
                var family = FamilyRepository.Load(user);
                if (family != null)
                    TempData["Message"] = "Cannot create blog entries as Family";
                return RedirectToAction("Index", "Home");
            }

            var viewData = new BlogCreateModel();
            viewData.AuthorID = dbUser.UniqueKey;

            return View("Create", viewData);
        }
コード例 #3
0
ファイル: BlogController.cs プロジェクト: sgwill/familyblog
        public ActionResult Edit(BlogCreateModel viewData)
        {
            EnsureInjectables();

            if (string.IsNullOrEmpty(viewData.Entry))
                viewData.Entry = Request.Form["textEntry"];
            if (string.IsNullOrEmpty(viewData.Entry))
                ModelState.AddModelError("Entry", "You must enter your Entry!");

            if (!ModelState.IsValid)
                return View("Edit", viewData);

            var blog = BlogRepository.LoadBySlug(viewData.Title.BlogUrl());
            blog.Entry = viewData.Entry;
            blog.Tags = viewData.Tags;
            if (!blog.IsPublished && viewData.IsPublished)
                blog.IsPublished = viewData.IsPublished;
            BlogRepository.Save(blog);

            Cache.Remove(new BlogListCacheKey().GenerateKey("SidebarList"));

            return RedirectToAction("UserList");
        }
コード例 #4
0
ファイル: BlogController.cs プロジェクト: sgwill/familyblog
        public ActionResult Edit(string user, string slug)
        {
            EnsureInjectables();

            if (string.IsNullOrEmpty(slug))
                return RedirectToAction("Index", "Home");

            var blog = BlogRepository.LoadBySlug(slug);
            if (blog == null)// || blog.AuthorID != user)
                return RedirectToAction("Index", "Home");

            var data = new BlogCreateModel();
            data.Entry = blog.Entry;
            data.Title = blog.Title;
            data.Tags = blog.Tags;
            data.AuthorID = blog.AuthorID;
            data.IsEdit = true;
            data.IsPublished = blog.IsPublished;
            data.DatePublished = blog.IsPublished ? blog.DatePublished : null;
            data.UniqueKey = blog.UniqueKey;

            return View("Edit", data);
        }