public void AddComment(Comment comment) { try { context.Comments.Add(comment); context.SaveChanges(); } catch { } }
public ActionResult _AddComment(AddCommentModel comment) { if (ModelState.IsValid) { var ToAdd = new Comment { ThemeId = comment.ThemeId, UserId = comment.UserId, CommentText = comment.CommentText, CreationDate = DateTime.Now }; if (User.IsInRole("moder") || User.IsInRole("admin")) { ToAdd.IsAdmitted = true; repository.AddComment(ToAdd); TempData["success"] = "Сообщение создано."; } else { repository.AddComment(ToAdd); TempData["success"] = "Сообщение добавлено, но другие пользователи увидят его только после проверки."; } } else { TempData["failure"] ="Сообщение не было создано."; } return RedirectToAction("Theme", "Forum", new { id = comment.ThemeId, page = Math.Ceiling((double)repository.Comments.Where(c=>c.ThemeId == comment.ThemeId).Count()/10) }); }