Example #1
0
        public IActionResult OnPost(int restaurantId)
        {
            Restaurant = _restaurantData.GetById(restaurantId);
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            if (Comment.Text != null)
            {
                _commentData.Add(Comment);
                _commentData.Commit();
                return(RedirectToPage("./Detail", new { restaurantId = Comment.RestaurantId }));
            }

            else if (Rating.Score != 0)
            {
                _ratingData.AddOrUpdate(Rating);
                _ratingData.Commit();
                return(RedirectToPage("./Detail", new { restaurantId = Comment.RestaurantId }));
            }
            else
            {
                return(RedirectToPage("./Detail", new { restaurantId = Comment.RestaurantId }));
            }
        }
Example #2
0
        public ActionResult NewComment(Comment comment)
        {
            if (ModelState.IsValid)
            {
                comment.PostTime = DateTime.Now;
                commentData.Add(comment, comment.PostID);
                return(RedirectToAction("PostDetails", new { id = comment.PostID }));
            }

            return(View());
        }
Example #3
0
        public IActionResult Create(CommentEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                var comment = new Comment
                {
                    Text = model.Text
                };

                _commentData.Add(comment);
                _commentData.Commit();

                return(RedirectToAction("Details", new { id = comment.Id }));
            }
            return(View());
        }
Example #4
0
        public ActionResult Create([Bind(Include = "CommentId,UserName,Text,UserRatig,DateCreated,DateEdited,PostID")] Comment comment)
        {
            comment.DateCreated = DateTime.Now;
            comment.DateEdited  = DateTime.Now;

            var posts = _db.GetAllPosts();

            ViewBag.PostID = new SelectList(posts, "PostId", "Text", comment.PostID);

            if (ModelState.IsValid)
            {
                _db.Add(comment);
                return(RedirectToAction("Details", new { id = comment.CommentId }));
            }
            return(View(comment));
        }
Example #5
0
        public IActionResult Comment(int id, CommentEditViewModel comment)
        {
            var user = _userManager.GetUserAsync(User).Result;
            var post = _postData.Get(id);

            if (ModelState.IsValid)
            {
                var newComment = new Comment()
                {
                    Post      = post,
                    Content   = comment.Content,
                    Commenter = user
                };
                newComment = _commentData.Add(newComment);
                _commentData.Commit();
                return(RedirectToAction("Details", new { id = post.Id }));
            }

            return(RedirectToAction("Index"));
        }
Example #6
0
        public IActionResult Details(int id, DetailPostViewModel model)
        {
            if (!ModelState.IsValid)
            {
                RedirectToAction("Details", "Home", id);
            }

            try
            {
                var comment = new Comment
                {
                    DescriptionOfComment = model.CommentText,
                    NicknameOfCommenter  = model.CommentNick
                };

                comment = _commentData.Add(comment, id);
                return(RedirectToAction("Details", "Home", id));
            }
            catch (Exception)
            {
                return(RedirectToAction("Index", "Home"));
            }
        }