Example #1
0
        public ActionResult SaveComment(string friendlyUrl, SinglePostVm vm)
        {
            try
            {
                var post = DataSession.Load <Post>(Post.Idprefix + friendlyUrl);

                post.Comments.Add(new Comment
                {
                    Id          = Guid.NewGuid().ToString(),
                    IsPublished = false,
                    Title       = vm.Comment.Title,
                    Content     = vm.Comment.Content,
                    Author      = vm.Comment.Author,
                    Email       = vm.Comment.Email,
                    Url         = vm.Comment.Url
                });
                DataSession.SaveChanges();
                TempData["success"] = "Kommentaren skickad för granskning";

                return(Redirect("/posts/" + post.FriendlyUrl));
            }
            catch (Exception)
            {
                TempData["error"] = "Kommentaren har inte skickats för granskning, försök igen.";
            }
            return(RedirectToAction("Index"));
        }
        public ActionResult DeleteConfirmed(string id)
        {
            var blog = DataSession.Load <Blog>(("blogs/" + id));

            DataSession.Delete(blog);
            DataSession.SaveChanges();

            return(RedirectToAction("Index"));
        }
        //Kommentaren godkänns och publiceras på bloggen.
        public ActionResult Confirm(string postId, string commentId)
        {
            var post = DataSession.Load <Post>((Post.Idprefix + postId));

            foreach (var t in post.Comments.Where(t => t.Id == commentId))
            {
                t.IsPublished = true;
            }
            DataSession.SaveChanges();
            UpdateModel("Index");
            return(RedirectToAction("Index"));
        }
        // GET: Blogs/Delete/5
        public ActionResult Delete(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var blog = DataSession.Load <Blog>(("blogs/" + id));

            if (blog == null)
            {
                return(HttpNotFound());
            }
            return(View(blog));
        }
Example #5
0
        // GET: Posts/Delete/5
        public ActionResult Delete(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var post = DataSession.Load <Post>("posts/" + id);

            if (post == null)
            {
                return(HttpNotFound());
            }
            return(View(post));
        }
        //POST: Delete Comment
        public ActionResult DeleteConfirmed(string postId, string commentId)
        {
            var post = DataSession.Load <Post>((Post.Idprefix + postId));

            for (var i = 0; i < post.Comments.Count; i++)
            {
                if (post.Comments[i].Id == commentId)
                {
                    post.Comments.RemoveAt(i);
                }
            }
            DataSession.SaveChanges();
            UpdateModel("Index");
            return(RedirectToAction("Index"));
        }
Example #7
0
        //Index Blog
        public ActionResult Index()
        {
            var listOfPosts =
                DataSession.Query <Post, Posts_View>()
                .Where(o => o.BlogReference == BlogId && o.Status == PostStatus.Active)
                .ToList();

            var blogs = DataSession.Load <Blog>(BlogId);

            var mainPostVm = new MainPostVm {
                Posts = listOfPosts, BlogRef = BlogId, Blogs = blogs
            };

            //_Layout för att visa samma på alla bloggar.
            ViewBag.BlogName    = blogs.BlogName;
            ViewBag.Description = blogs.Description;
            ViewBag.Url         = blogs.Url;

            return(View(mainPostVm));
        }
Example #8
0
        public ActionResult DeleteConfirmed(string id)
        {
            try
            {
                var post = DataSession.Load <Post>("posts/" + id);
                DataSession.Delete(post);
                DataSession.SaveChanges();

                TempData["success"] = "Inlägget är nu borttagen";
                UpdateModel("Index");

                return(RedirectToAction("Index"));
            }
            catch (Exception)
            {
                TempData["error"] = "Borttagning av posten misslyckades!";
                RedirectToAction("Delete", new { id });
            }
            return(RedirectToAction("Index"));
        }
Example #9
0
        // GET: Posts/Edit/5
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var post  = DataSession.Load <Post>("posts/" + id);
            var blogs = DataSession.Advanced.LoadStartingWith <Blog>("blogs/" + id);

            ViewBag.blog = new SelectList(blogs, "BlogName");
            foreach (var tag in post.InternalTags)
            {
                post.Tags += tag + ", ";
            }

            if (post == null)
            {
                throw new HttpException(404, "Posten du begärde finns inte eller har just blivit borttagen");
            }
            return(View(post));
        }