public ActionResult ApproveReview(Reviews review) { var game = db.Games.Find(review.GameId); game.State = State.Modified; var gameReview = game.Reviews.FirstOrDefault(r => r.ReviewId == review.ReviewId); gameReview.IsApproved = true; gameReview.State = State.Modified; if (ModelState.IsValid) { db.Games.Add(game); db.Entry(game).State = StateHelpers.ConvertState(game.State); db.SaveChanges(); TempData["toast"] = "<script> $(document).ready(function () {" + "toastr.options = { 'positionClass': 'toast-bottom-right' };" + "toastr.success('Review has been approved.');});</script>"; return RedirectToAction("EmployeeReviewsIndex"); } return View(review); }
public ActionResult Create(ReviewViewModel reviewViewModel, int id) { var memberId = _db.Members.Where(m => m.DisplayName == User.Identity.Name) .Select(i => i.UserId) .FirstOrDefault(); var displayName = _db.Members.Where(m => m.DisplayName == User.Identity.Name) .Select(i => i.DisplayName) .FirstOrDefault(); // need the game and modify the average review score - Need the number of reviews // get the number of reviews var game = UoW.Games.GetAll().FirstOrDefault(g => g.GameId == id); var numberOfReviews = game.NumberOfReviews.GetValueOrDefault(); if (numberOfReviews < 1) { game.NumberOfReviews = 1; } else { game.NumberOfReviews++; } numberOfReviews = game.NumberOfReviews.Value; var sumOfGameReviews = UoW.Reviews.GetAll().Where(r => r.GameId == id).Select(a => a.MemberRating).ToList(); sumOfGameReviews.Add(reviewViewModel.GameRatingOutOf10); game.AverageReviewScore = sumOfGameReviews.GetAverage(numberOfReviews); var review = new Reviews(); if (ModelState.IsValid) { review.Comments = reviewViewModel.Comments; review.IsApproved = false; review.ReviewDate = DateTime.Now; review.GameId = id; review.MemberId = memberId; review.MemberRating = reviewViewModel.GameRatingOutOf10; review.DisplayName = displayName; try { UoW.Games.Update(game); UoW.Reviews.Add(review); UoW.SaveChanges(); } catch (Exception e) { ViewData["message"] = "Error. " + e.InnerException; } TempData["toast"] = "<script> $(document).ready(function () {" + "toastr.options = { 'positionClass': 'toast-bottom-right' };" + "toastr.success('Review has been sent to a moderator for approval.');});</script>"; return RedirectToAction("Details", "Game", new { id = id}); } return View(reviewViewModel); }