public ActionResult CommentSubmit([Bind(Include = "ID,Content,score,UserID,MovieID")] MovieComment comment) { comment.CommentTime = DateTime.Now; comment.User = userManage.Find(comment.UserID); int isUser = commentMange.Count(p => p.UserID == comment.UserID && p.MovieID == comment.MovieID); if (isUser > 0) { return(Content("<h1 class='text-center' style='color:#fff;'>您已评论过此电影!</h1>")); } if (ModelState.IsValid) { commentMange.Add(comment); comment.User.SweetScore = comment.User.SweetScore++; userManage.Update(comment.User); var _comment = commentMange.FindList(p => p.MovieID == comment.MovieID); _comment = _comment.OrderBy(p => p.CommentTime); const int pageSize = 5; return(PartialView("CommentList", _comment.ToPagedList(1, pageSize))); } return(Content("<h1 class='text-center' style='color:#fff;'>评论失败</h1>")); }
public ActionResult Add(AddCommentViewModel commentViewModel) { if (commentManage.HasUserComment(commentViewModel.UserID, commentViewModel.MovieID)) { return(View("Prompt", new Prompt() { Title = "添加失败", Message = "当前用户已对当前电影评论\n注意!每个用户对每个电影只能评论一次!", Buttons = new List <string>() { "<a href=\"" + Url.Action("Index", "Comment") + "\" class=\"btn btn-default\">评论管理</a>", "<a href=\"" + Url.Action("Add", "Comment") + "\" class=\"btn btn-default\">重新添加</a>" } } )); } if (ModelState.IsValid) { MovieComment _comment = new MovieComment(); _comment.UserID = commentViewModel.UserID; _comment.MovieID = commentViewModel.MovieID; _comment.CommentTime = commentViewModel.CommentTime; _comment.Content = commentViewModel.Content; _comment.Score = commentViewModel.Score; var _user = userManage.Find(commentViewModel.UserID); if (_user.Userstatus == DAL.Models.User.UserStatus.未启用) { return(View("Prompt", new Prompt() { Title = "添加评论失败", Message = "当前用户已被冻结,无法评论!请先启用当前用户", Buttons = new List <string>() { "<a href=\"" + Url.Action("Index", "Comment") + "\" class=\"btn btn-default\">评论管理</a>", "<a href=\"" + Url.Action("Add", "Comment") + "\" class=\"btn btn-default\">重新添加</a>" } } )); } var _resp = commentManage.Add(_comment); if (_resp.Code == 1) { return(View("Prompt", new Prompt() { Title = "添加评论成功", Message = "您已为此用户添加了评论", Buttons = new List <string>() { "<a href=\"" + Url.Action("Index", "Comment") + "\" class=\"btn btn-default\">评论管理</a>", "<a href=\"" + Url.Action("Add", "Comment") + "\" class=\"btn btn-default\">继续添加</a>" } } )); } else { ModelState.AddModelError("", _resp.Message); } } else { return(View(commentViewModel)); } var _users = new UserManage().FindList(); List <SelectListItem> _userlistItems = new List <SelectListItem>(_users.Count()); foreach (var _user in _users) { _userlistItems.Add(new SelectListItem() { Text = _user.Username, Value = _user.ID.ToString() }); } ViewBag.Users = _userlistItems; var _movies = new MovieManage().FindList(); List <SelectListItem> _movielistItems = new List <SelectListItem>(_movies.Count()); foreach (var _movie in _movies) { _movielistItems.Add(new SelectListItem() { Text = _movie.MovieName, Value = _movie.ID.ToString() }); } ViewBag.Movies = _movielistItems; return(View(commentViewModel)); }