コード例 #1
0
ファイル: PostController.cs プロジェクト: gudmbk/VLN2-hopur1
        public ActionResult PostComment(FormCollection collection)
        {
            Comment comment = new Comment();
            string  text    = collection["comment"];
            string  id      = collection["PostId"];

            int postId = Int32.Parse(id);

            if (String.IsNullOrEmpty(text))
            {
                return(RedirectToAction("ChildHome", "User"));
            }
            comment.Body       = text;
            comment.UserId     = User.Identity.GetUserId();
            comment.PostId     = postId;
            comment.PosterName = _userService.GetFullNameById(User.Identity.GetUserId());
            if (comment.UserId != null)
            {
                _postService.AddComment(comment);
                if (_postService.OnUserWall(postId))
                {
                    return(RedirectToAction("Profile", "User", new { userId = _postService.GetToUserIdPostId(postId) }));
                }
                return(RedirectToAction("Profile", "Group", new { groupId = _groupService.FindGroupId(postId) }));
            }
            return(View("Error"));
        }
コード例 #2
0
        public async Task <IActionResult> AddComment(string id, string content)
        {
            var user = _userService.GetByEmail(User.Identity.Name).Result;

            _postService.AddComment(id, content, user.UserName);
            var posts = _postService.GetAllByProfile(user).ToList();

            return(View("_Posts", posts));
        }
コード例 #3
0
        public IActionResult AddComment(string id, PostCommentModel comment)
        {
            var profile = _postService.Get(id);

            if (profile == null)
            {
                return(NotFound());
            }
            _postService.AddComment(comment, id);

            return(NoContent());
        }
コード例 #4
0
ファイル: PostController.cs プロジェクト: Meyhem/polymicron
        public async Task <IActionResult> Comment(int id, CommentModel model)
        {
            var recap = ReCaptchaPassed(Request.Form["g-recaptcha-response"], config.GetSection("GoogleReCaptcha:secret").Value);

            if (!recap)
            {
                AddBox("Bad captcha", BoxType.Error, "Captcha");
            }

            if (!ModelState.IsValid)
            {
                if (model.Name == null)
                {
                    AddBox("Provide a name to be distinguished", BoxType.Error, "InputName");
                }
                else if (model.Name.Length > 20)
                {
                    AddBox("Must be up to 20 chars", BoxType.Error, "InputName");
                }

                if (model.Text == null)
                {
                    AddBox("Provide a comment text", BoxType.Error, "InputText");
                }
                else if (model.Text.Length > 255)
                {
                    AddBox("255 chars max", BoxType.Error, "InputText");
                }
            }
            else
            {
                await postService.AddComment(id, model);
            }

            return(RedirectToAction("Post", "Post", new { id }));
        }
コード例 #5
0
 private void Add(object sender, RoutedEventArgs e)
 {
     services.AddComment(Text.Text, postId, userService.GetUser(username));
     Close();
 }