public PartialViewResult PartialTutorials(int?page = 1) { int pageSize = SiteConfigTool.GetValue <int>("home-tutorial-page-size"); if (pageSize == 0) { pageSize = 5; } int skipPage = pageSize * (page.Value == 1 ? 0 : page.Value - 1); int takepage = pageSize; var lst = _tutorialRepository.GetAllTutorialWithCategoryWithComments .Select(a => new SideMenuModelItem() { Posted = a.DateCreated.Value, Title = a.Name, ID = a.ID, Href = Url.Action("View", "Tutorial", new { cat = a.TutorialCategory.ID, id = a.ID, name = a.Name.ToSlug() }), Content = a.HtmlContent.ToHtmlDecode(), CommentCount = a.Comments.Count() }) .Skip(skipPage).Take(takepage) .OrderByDescending(t => t.CommentCount); return(PartialView("_PagingTutorialsPartial", lst)); }
public ActionResult Save(CommentModel model) { string ip = HttpServerTool.GetIpAddress(this.Request); string ipToBlocked = SiteConfigTool.GetValue <string>("blockedip"); if (!ipToBlocked.IsNullOrEmptyTrimmed() && ipToBlocked.Split(new char[] { ',' }).Any(_ => _ == ip)) { return(Content(String.Empty)); } var recaptchaHelper = this.GetRecaptchaVerificationHelper(); if (recaptchaHelper.Response.IsNullOrEmptyTrimmed()) { return new JsonResult { Data = new { Error = true, ErrorMessage = "Invalid recaptcha value" } } } ; var recaptchaResult = recaptchaHelper.VerifyRecaptchaResponse(); if (recaptchaResult != RecaptchaVerificationResult.Success) { return new JsonResult { Data = new { Error = true, ErrorMessage = "Invalid recaptcha value" } } } ; if (ModelState.IsValid) { var comment = new Comment() { AnonymousName = model.AnonymousName, CommentText = model.CommentText, Email = model.Email, Website = model.Website, DateCreated = DateTime.Now, IsDeleted = false, IpAddress = HttpServerTool.GetIpAddress(this.Request) }; if (model.Tutorial_ID.HasValue) { comment.Tutorial_ID = model.Tutorial_ID.Value; } else if (model.Game_ID.HasValue) { comment.Game_ID = model.Game_ID.Value; } _commentRepository.Add(comment); _commentRepository.SaveChanges(); _emailService.SendNewComment(comment.AnonymousName, comment.CommentText, model.Title); } return(Content(String.Empty)); } } }