public ActionResult Delete(int id, CommentsModel model)
        {
            if (_commentsService.Delete(model))
                return RedirectToAction("Delete", "Comments", new { id, postBack = "success" });

            ModelState.AddModelError("", "Comment not deleted successfully.");

            return View(new CommentsModel(_commentsService.Retrieve(id)));
        }
        public ActionResult Update(int id, CommentsModel model)
        {
            if (ModelState.IsValid)
            {
                if (_commentsService.Update(model))
                    return RedirectToAction("Update", "Comments", new { id, postBack = "success" });

                ModelState.AddModelError("", "Comment not edited successfully.");
            }

            ViewBag.submitText = "Update";

            return View(model);
        }
Exemplo n.º 3
0
        public List<CommentsModel> ToList(List<Object> comments)
        {
            List<CommentsModel> commentsList = new List<CommentsModel>();

            if (comments.Any())
                foreach(Object comment in comments)
                {
                    CommentsModel commentsModel = new CommentsModel();

                    ModelHelper.Map(commentsModel, comment);

                    commentsList.Add(commentsModel);
                }

            return commentsList;
        }
        public ActionResult Create(CommentsModel model)
        {
            if (ModelState.IsValid)
            {
                int createdCommentId = _commentsService.Create(model);

                if (createdCommentId != 0)
                    return RedirectToAction("Create", "Comments", new { postBack = "success"});
                
                ModelState.AddModelError("", "Comment not added successfully.");
            }

            ViewBag.submitText = "Create";

            return View(model);
        }