コード例 #1
0
        /// <summary>
        /// Displays the homepage. Homepage contains two sections to display top game and top category.
        /// </summary>
        /// <returns>Returns a result based on status</returns>
        public ActionResult Index()
        {
            ActionResult response;
            ReviewVM     viewModel = new ReviewVM();

            try
            {
                //instantiate lists
                viewModel.ReviewsList = new List <ReviewPO>();
                List <ReviewDO> reviewDOs = new List <ReviewDO>();

                //call DAO to get list of reviews
                reviewDOs = _ReviewDataAccess.ViewReviews();

                //call BLL for most recommended category
                viewModel.Review = _ReviewMapper.MapDOtoPO(_ReviewDataAccess.TopCategory());

                //call DAO and BLL for most recommended game
                int topGameID = _BusinessLogic.TopGame(reviewDOs);
                viewModel.Game = _GameMapper.MapDOtoPO(_GameDataAccess.ViewGameByID(topGameID));

                response = View(viewModel);
            }
            catch (Exception ex)
            {
                //log error
                _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex);
                response = RedirectToAction("Error", "Home");
            }
            finally { }

            return(response);
        }
コード例 #2
0
        /// <summary>
        /// Displays the information for a specific game
        /// </summary>
        /// <param name="id">ID of the game needing to be displayed</param>
        /// <returns>Returns a result based on status</returns>
        public ActionResult GameDetails(int id)
        {
            ActionResult response;
            ReviewVM     viewModel = new ReviewVM();

            //check id
            if (id > 0)
            {
                //if id is valid, access the database
                try
                {
                    //set game
                    GameDO gameDO = _GameDataAccess.ViewGameByID(id);
                    viewModel.Game = _GameMapper.MapDOtoPO(gameDO);

                    //instantiate lists
                    List <ReviewDO> gameReviews   = _ReviewDataAccess.ViewReviews();
                    List <ReviewPO> mappedReviews = new List <ReviewPO>();
                    viewModel.ReviewsList = new List <ReviewPO>();

                    //map reviews to a list of POs
                    foreach (ReviewDO reviewDO in gameReviews)
                    {
                        //get review information
                        ReviewPO reviewPO = _ReviewMapper.MapDOtoPO(reviewDO);

                        //get game information for title
                        GameDO reviewGame = _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 and map to view model
                    viewModel.ReviewsList = mappedReviews.Where(n => n.GameID == viewModel.Game.GameID).ToList();

                    response = View(viewModel);
                }
                catch (Exception ex)
                {
                    //log error
                    _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex);
                    response = RedirectToAction("Error", "Home");
                }
                finally { }
            }
            else
            {
                //if id is not valid, return to game list
                response = RedirectToAction("Index", "Game");
            }

            return(response);
        }
コード例 #3
0
        /// <summary>
        /// Shows a list of all reviews in the database.
        /// </summary>
        /// <returns>Returns a result based on status</returns>
        public ActionResult Index()
        {
            ActionResult response;
            ReviewVM     viewModel = new ReviewVM();

            try
            {
                //access database
                List <ReviewDO> allReviews = _ReviewDataAccess.ViewReviews();

                viewModel.ReviewsList = new List <ReviewPO>();

                //add to view model
                foreach (ReviewDO reviewDO in allReviews)
                {
                    //set review information
                    ReviewPO reviewPO = _ReviewMapper.MapDOtoPO(reviewDO);

                    //get game title
                    GameDO gameDO = _GameDataAccess.ViewGameByID(reviewPO.GameID);
                    reviewPO.GameTitle = gameDO.Title;

                    //get username
                    UserDO userDO = _UserDataAccess.ViewUserByID(reviewPO.UserID);
                    reviewPO.Username = userDO.Username;

                    viewModel.ReviewsList.Add(reviewPO);
                }

                response = View(viewModel);
            }
            catch (Exception ex)
            {
                //log errors
                _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex);
                response = RedirectToAction("Error", "Home");
            }
            finally { }

            return(response);
        }
コード例 #4
0
        /// <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);
        }