public async Task <IActionResult> Comment(CommentViewModel model) { ViewData["ReCaptchaKey"] = _configuration.GetSection("GoogleReCaptcha:key").Value; if (model != null) { if (!ModelState.IsValid) { return(RedirectToAction("Post", new { id = model.PostId })); } if (ReCaptchaPassed( Request.Form["g-recaptcha-response"], _configuration.GetSection("GoogleReCaptcha:secret").Value, _logger ).Result) { var entity = new DAL.Models.Comment { Author = await _userManager.GetUserAsync(User).ConfigureAwait(false), AuthorId = _userManager.GetUserId(User), PostId = model.PostId, Created = DateTime.Now, Text = model.Text }; _unitOfWork.CommentRepository.Add(entity); _unitOfWork.PostRepository.Get(model.PostId); _unitOfWork.Commit(); return(RedirectToAction("Post", new { id = model.PostId })); } } return(RedirectToAction("Post", new { id = model.PostId })); //If not - retry }
public static LOCAL.Models.Comment toLocal(this DAL.Models.Comment comment) { return(new LOCAL.Models.Comment { CommentId = comment.CommentId, Note = comment.Note, CommentText = comment.CommentText, CommentDate = comment.CommentDate, UserId = comment.UserId, VideoGameId = comment.VideoGameId }); }
public IActionResult Create(Models.BlogPostViewModel model) //Checking if added comment is valid and saving it to database { if (ModelState.IsValid) { var entity = new DAL.Models.Comment { Text = model.AddedComment.Text, AuthorId = UserManager_.GetUserId(User), PostId = model.Id, PostingTime = DateTime.Now }; UnitOfWork_.CommentsRepository.Add(entity); UnitOfWork_.Commit(); return(RedirectToAction("Show", "Post", new { id = model.Id })); } return(View("Show", model)); //If not - retry }
public static DTO.Models.Comment CommentDTOToCommentDAO(this DAL.Models.Comment Comment) { return(new DTO.Models.Comment(Comment.Id, Comment.CommentValue, Comment.Note, Comment.IdClient, Comment.IdWine)); }