Exemplo n.º 1
0
        public ActionResult Delete(int id)
        {
            Post post = this.GetPost(id);

            if (post == default(Post) || post.IsDeleted)
            {
                return(this.RedirectToAction("BadRequest", "Error"));
            }

            PostDeleteBindingModel postToDelete = new PostDeleteBindingModel()
            {
                Id     = post.PostId,
                Text   = post.Text.Text,
                Thread = new IdentifiableThreadBindingModel()
                {
                    Id    = post.Thread.ThreadId,
                    Title = post.Thread.Title
                }
            };

            return(this.View(postToDelete));
        }
Exemplo n.º 2
0
        public ActionResult Delete(int id, PostDeleteBindingModel model)
        {
            Post postToDelete = this.GetPost(id);

            if (postToDelete == default(Post) || postToDelete.IsDeleted || id != model.Id)
            {
                return(this.RedirectToAction("BadRequest", "Error"));
            }

            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            postToDelete.IsDeleted = true;

            this.UnitOfWork
            .PostRepository
            .Update(postToDelete);

            this.UnitOfWork.SaveChanges();

            return(this.RedirectToAction("Home", "Home"));
        }