Example #1
0
 async public void AddComment(int id, string text)
 {
     int     userId  = _userRepo.GetByUsername(User.Identity.Name).Id;
     Comment comment = new Comment
     {
         MemeId    = id,
         CreatorId = userId,
         Text      = text
     };
     await _memeRepo.AddCommentAsync(comment);
 }
        async public Task <ActionResult> Comment(int id, [Bind(Include = "Id, Text, Rating, CreatorId")] Comment comment)
        {
            if (string.IsNullOrWhiteSpace(comment.Text))
            {
                ModelState.AddModelError("", "Text can't be empty");
            }
            if (ModelState.IsValid)
            {
                User creator = _userRepo.GetByUsername(User.Identity.Name);

                Comment newComment = new Comment()
                {
                    CreatorId = creator.Id,
                    MemeId    = id,
                    Text      = comment.Text,
                };
                await _memeRepo.AddCommentAsync(newComment);

                return(RedirectToAction("Details", new { id = id }));
            }
            return(View("Comment"));
        }