コード例 #1
0
        public ActionResult Details(int?id)
        {
            if (!id.HasValue)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var post = UserPost.GetPostById(id.Value);

            if (post == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new PostViewModel
            {
                Id         = id.Value,
                Title      = post.Title,
                Body       = post.Body,
                CreateDate = post.CreateDate.ToShortDateString()
            };

            if (Request.UrlReferrer != null &&
                !string.IsNullOrEmpty(Request.UrlReferrer.PathAndQuery) &&
                Request.UrlReferrer.PathAndQuery.Contains("PostFilter"))
            {
                viewModel.ReturnUri = Request.UrlReferrer.PathAndQuery;
            }

            return(View(viewModel));
        }
コード例 #2
0
        // GET: Message
        public ActionResult CreateMessage(int postId)
        {
            MessageViewModel message_model = new MessageViewModel();

            message_model.Sender   = User.Identity.GetUserName();
            message_model.Receiver = UserPost.GetPostById(postId).Author.UserName;
            message_model.postId   = postId;
            return(View(message_model));
        }
コード例 #3
0
        public ActionResult Delete(int?id)
        {
            if (!id.HasValue)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var post = UserPost.GetPostById(id.Value);

            if (post == null)
            {
                return(HttpNotFound());
            }

            return(View(post));
        }
コード例 #4
0
        public ActionResult Edit(int?id)
        {
            if (!id.HasValue)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var post = UserPost.GetPostById(id.Value);

            if (post == null)
            {
                return(HttpNotFound());
            }

            if ((post.ExpirationDate.HasValue && post.ExpirationDate.Value.CompareTo(DateTime.Today) < 0) || post.Deleted)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            return(View(post));
        }
コード例 #5
0
        public ActionResult Edit(int id, [Bind(Include = "Title,Body")] PostViewModel post)
        {
            if (ModelState.IsValid)
            {
                var postDb = UserPost.GetPostById(id);

                if ((postDb.ExpirationDate.HasValue && postDb.ExpirationDate.Value.CompareTo(DateTime.Today) < 0) || postDb.Deleted)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                UserPost.UpdatePost(User.Identity.GetUserId(), id, post.Title, post.Body, out var errors);

                if (errors.Length > 0)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, errors.ToString()));
                }

                return(RedirectToAction("Index"));
            }
            return(View(post));
        }