예제 #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 }));
            }
        }
예제 #2
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());
        }
예제 #3
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"));
        }