コード例 #1
0
        private void SetWhateverUserIsTrustedCommenter(PostViewModel vm)
        {
            if (Request.IsAuthenticated)
            {
                var user = RavenSession.GetCurrentUser();
                vm.Input = user.MapTo <CommentInput>();
                vm.IsTrustedCommenter  = true;
                vm.IsLoggedInCommenter = true;
                return;
            }

            var cookie = Request.Cookies[CommenterUtil.CommenterCookieName];

            if (cookie == null)
            {
                return;
            }

            var commenter = RavenSession.GetCommenter(cookie.Value);

            if (commenter == null)
            {
                vm.IsLoggedInCommenter = false;
                Response.Cookies.Set(new HttpCookie(CommenterUtil.CommenterCookieName)
                {
                    Expires = DateTime.Now.AddYears(-1)
                });
                return;
            }

            vm.IsLoggedInCommenter = string.IsNullOrWhiteSpace(commenter.OpenId) == false;
            vm.Input = commenter.MapTo <CommentInput>();
            vm.IsTrustedCommenter = commenter.IsTrustedCommenter == true;
        }
コード例 #2
0
        public ActionResult Edit(PostInput input, int id)
        {
            if (!ModelState.IsValid)
            {
                return(View("Edit", input));
            }

            var post = RavenSession.Load <Post>(id) ?? new Post();

            input.MapPropertiesToInstance(post);

            var user = RavenSession.GetCurrentUser();

            if (string.IsNullOrEmpty(post.AuthorId))
            {
                post.AuthorId = user.Id;
            }
            else
            {
                post.LastEditedByUserId = user.Id;
                post.LastEditedAt       = DateTimeOffset.Now;
            }

            RavenSession.Store(post);

            var postReference = post.MapTo <PostReference>();

            return(RedirectToAction("Details", new { Id = postReference.DomainId, postReference.Slug }));
        }
コード例 #3
0
        public ActionResult Update(PostInput input)
        {
            if (!ModelState.IsValid)
            {
                return(View("Edit", input));
            }

            var post = RavenSession.Load <Post>(input.Id) ?? new Post {
                CreatedAt = DateTimeOffset.Now
            };

            input.MapPropertiesToInstance(post);

            // Be able to record the user making the actual post
            var user = RavenSession.GetCurrentUser();

            if (string.IsNullOrEmpty(post.AuthorId))
            {
                post.AuthorId = user.Id;
            }
            else
            {
                post.LastEditedByUserId = user.Id;
                post.LastEditedAt       = DateTimeOffset.Now;
            }

            if (post.PublishAt == DateTimeOffset.MinValue)
            {
                var postScheduleringStrategy = new PostSchedulingStrategy(RavenSession, DateTimeOffset.Now);
                post.PublishAt = postScheduleringStrategy.Schedule();
            }

            // Actually save the post now
            RavenSession.Store(post);

            if (input.IsNewPost())
            {
                // Create the post comments object and link between it and the post
                var comments = new PostComments
                {
                    Comments = new List <PostComments.Comment>(),
                    Spam     = new List <PostComments.Comment>(),
                    Post     = new PostComments.PostReference
                    {
                        Id        = post.Id,
                        PublishAt = post.PublishAt,
                    }
                };

                RavenSession.Store(comments);

                // Once the Comments have been saved, update and save the post
                post.CommentsId = comments.Id;
                RavenSession.Store(post);
            }

            return(RedirectToAction("Details", new { Id = post.MapTo <PostReference>().DomainId }));
        }
コード例 #4
0
        public ActionResult Index()
        {
            ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";

            var a = RavenSession.GetCurrentUser();


            return(View());
        }
コード例 #5
0
        public virtual ActionResult AdministrationPanel()
        {
            var user = RavenSession.GetCurrentUser();

            var vm = new CurrentUserViewModel();

            if (user != null)
            {
                vm.FullName = user.FullName;
            }
            return(View(vm));
        }
コード例 #6
0
        public ActionResult Add(PostInput input)
        {
            if (!ModelState.IsValid)
            {
                return(View("Edit", input));
            }

            // Be able to record the user making the actual post
            var user = RavenSession.GetCurrentUser();

            // Create the post comments object and link between it and the post
            var comments = new PostComments
            {
                Comments = new List <PostComments.Comment>(),
                Spam     = new List <PostComments.Comment>()
            };

            RavenSession.Store(comments);

            // Create new post object
            var post = new Post
            {
                Tags               = TagsResolver.ResolveTagsInput(input.Tags),
                PublishAt          = input.PublishAt,
                AllowComments      = input.AllowComments,
                AuthorId           = user.Id,
                LastEditedByUserId = user.Id,
                LastEditedAt       = DateTimeOffset.Now,
                CommentsId         = comments.Id,
                ContentType        = input.ContentType,
                Body               = input.Body,
                CreatedAt          = DateTimeOffset.Now,
                Title              = input.Title,
            };

            if (post.PublishAt == DateTimeOffset.MinValue)
            {
                var postScheduleringStrategy = new PostSchedulingStrategy(RavenSession, DateTimeOffset.Now);
                post.PublishAt = postScheduleringStrategy.Schedule();
            }

            // Actually save the post now
            RavenSession.Store(post);
            comments.Post = new PostComments.PostReference
            {
                Id        = post.Id,
                PublishAt = post.PublishAt,
            };

            return(RedirectToAction("Details", new { id = post.Id.ToIntId() }));
        }