/// <summary> /// Displays the information for one user. /// </summary> /// <param name="id">ID of user needing to be displayed</param> /// <returns>Returns a result based on status</returns> public ActionResult UserDetails(int id) { ActionResult response; ReviewVM viewModel = new ReviewVM(); //check for permissions if (Session["UserID"] != null && (int)Session["UserID"] == id || Session["RoleID"] != null && (int)Session["RoleID"] == 6) { //if allowed, access the database try { //access database, map to presentation, add to view model //get user information UserDO user = _UserDataAccess.ViewUserByID(id); viewModel.User = _Mapper.MapDOtoPO(user); //get role information for role name RoleDO role = _RoleDataAccess.ViewRoleByID(user.RoleID); viewModel.User.RoleName = role.RoleName; //get user's most frequent category viewModel.UserFavCategory = _reviewMapper.MapDOtoPO(_ReviewDataAccess.UserFavoriteCategory(viewModel.User.UserID)); //check id if (viewModel.User.UserID > 0) { //if id is valid, access database List <ReviewDO> gameReviews = _ReviewDataAccess.ViewReviews(); //instantiate new lists List <ReviewPO> mappedReviews = new List <ReviewPO>(); viewModel.ReviewsList = new List <ReviewPO>(); //map to presenation, add to view model foreach (ReviewDO reviewDO in gameReviews) { //map review information ReviewPO reviewPO = _reviewMapper.MapDOtoPO(reviewDO); //get game information for title GameDO gameDO = _GameDataAccess.ViewGameByID(reviewPO.GameID); reviewPO.GameTitle = gameDO.Title; //get user information for username UserDO userDO = _UserDataAccess.ViewUserByID(reviewPO.UserID); reviewPO.Username = userDO.Username; mappedReviews.Add(reviewPO); } //filter list by user, add to view model viewModel.ReviewsList = mappedReviews.Where(n => n.UserID == viewModel.User.UserID).ToList(); response = View(viewModel); } else { //if model state is not valid, display error screen response = RedirectToAction("Error", "Home"); } } catch (Exception ex) { //log error _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); //display error page response = RedirectToAction("Error", "Home"); } finally { } } else { //if not logged in, redirect to login page response = RedirectToAction("Login", "Account"); } return(response); }