public IActionResult AddComment(GameProfileBundle bundle) { var user_id = HttpContext.Session.GetInt32("user_id"); if (user_id == null) { return(RedirectToAction("LoginAndRegister", "LoginAndRegister")); } var postedComment = bundle.Comment; if (ModelState.IsValid) { postedComment.user_id = (int)user_id; dbContext.ReviewResponses.Add(postedComment); dbContext.SaveChanges(); int totalComment = dbContext.ReviewResponses.Where(c => c.review_id == postedComment.review_id).Count(); var newCommentInfo = new Dictionary <string, object> { { "userName", HttpContext.Session.GetString("userName") }, { "comment", postedComment }, { "totalComment", totalComment }, }; return(Json(newCommentInfo)); } return(Json("Invalid")); }
public async Task <IActionResult> ShowGame(int gameId) { var user_id = HttpContext.Session.GetInt32("user_id"); if (user_id == null) { return(RedirectToAction("LoginAndRegister", "LoginAndRegister")); } var gameProfileBundle = new GameProfileBundle(); gameProfileBundle.user = dbContext.Users.FirstOrDefault(user => user.user_id == user_id); if (dbContext.Games.FirstOrDefault(game => game.gameId == gameId) == null) { Game game = await GamesProcessor.ShowOneGame(gameId); SaveGame(game); } gameProfileBundle.game = dbContext.Games.Include(g => g.cover) .Include(g => g.game_Genres).ThenInclude(g => g.genre) .Include(g => g.game_Companies).ThenInclude(invc => invc.company) .Include(g => g.game_Platforms).ThenInclude(p => p.platform) .Include(g => g.screenshots) .Include(g => g.videos) .Include(g => g.expansions).ThenInclude(e => e.cover) .Include(g => g.Reviews).ThenInclude(r => r.reviewer) .Include(g => g.Reviews).ThenInclude(r => r.likeCounts) .Include(g => g.Reviews).ThenInclude(r => r.responses) .FirstOrDefault(g => g.gameId == gameId); gameProfileBundle.formReview = new Review(); gameProfileBundle.Comment = new ReviewResponse(); ViewBag.userName = HttpContext.Session.GetString("userName"); return(View("GameProfile", gameProfileBundle)); }
public IActionResult AddReview(GameProfileBundle bundle) { var user_id = HttpContext.Session.GetInt32("user_id"); if (user_id == null) { return(RedirectToAction("LoginAndRegister", "LoginAndRegister")); } var postedReview = bundle.formReview; if (ModelState.IsValid) { postedReview.user_id = (int)user_id; dbContext.Reviews.Add(postedReview); dbContext.SaveChanges(); return(RedirectToAction("ShowGame", new{ gameId = postedReview.gameId })); } var gameProfileBundle = new GameProfileBundle(); gameProfileBundle.game = dbContext.Games.Include(g => g.cover) .Include(g => g.game_Genres).ThenInclude(g => g.genre) .Include(g => g.game_Companies).ThenInclude(invc => invc.company) .Include(g => g.game_Platforms).ThenInclude(p => p.platform) .Include(g => g.screenshots) .Include(g => g.videos) .Include(g => g.expansions) .Include(g => g.Reviews).ThenInclude(r => r.likeCounts) // .Include(g=>g.Reviews).ThenInclude(r=>r.responses) .FirstOrDefault(g => g.gameId == postedReview.gameId); gameProfileBundle.formReview = new Review(); gameProfileBundle.Comment = new ReviewResponse(); return(View("GameProfile", gameProfileBundle)); }