Example #1
0
        public ActionResult UpdateComment(ViewCommentPO view)
        {
            ActionResult response = null;

            //Only users can update their comments.
            if (ModelState.IsValid && Session["UserID"] != null && (int)Session["UserRole"] <= 3)
            {
                try
                {
                    //Sets comment time to updated time.
                    view.Comment.CommentTime = DateTime.Now;
                    //Sets new comment information to the specific comment via SQL
                    CommentDO commentObject = Mapper.CommentPOtoDO(view.Comment);
                    _dataAccess.UpdateComment(commentObject);
                    response = RedirectToAction("ViewGameComments", "Comments", new { specificGame = view.Comment.GameID });
                }
                catch (Exception ex)
                {
                    Logger.Log(ex);
                    //Redirects to that game's page if a problem occurs
                    response = RedirectToAction("GameDetails", "Game", new { specificGame = view.Comment.GameID });
                }
                finally { }
            }
            else
            {
                response = RedirectToAction("GameDetails", "Game", new { specificGame = view.Comment.GameID });
            }
            return(response);
        }
Example #2
0
        public ActionResult ViewGameComments(int specificGame = default(int))
        {
            ActionResult response = null;

            try
            {
                //Access the comments if a GameID is given
                if (specificGame != 0)
                {
                    //Store the game's information, proceed if the game at given ID exists.
                    GameDO game = _gameDataAccess.GameDetails(specificGame);
                    if (game != null)
                    {
                        //Get game comments from the database, map them to presentation,
                        //pass them to the ViewModel.
                        List <CommentDO> commentList     = _dataAccess.ViewGameComments(specificGame);
                        List <CommentPO> displayComments = Mapper.ListCommentDOtoPO(commentList);
                        ViewCommentPO    viewComment     = new ViewCommentPO(displayComments);

                        //Get and set game name.
                        TempData["GameName"] = game.GameName;

                        //Attach user information.
                        if (Session["UserID"] == null)
                        {
                            viewComment.Comment.GameID = specificGame;
                        }
                        else
                        {
                            viewComment.Comment.GameID = specificGame;
                            viewComment.Comment.UserID = (int)Session["UserID"];
                        }
                        response = View(viewComment);
                    }
                    //No game found, redirect to game index.
                    else
                    {
                        response = RedirectToAction("Index", "Games");
                    }
                }
                else
                {
                    response = RedirectToAction("Index", "Games");
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
                response = RedirectToAction("Index", "Games");
            }
            finally { }
            return(response);
        }
Example #3
0
        public ActionResult AddComment(ViewCommentPO view, string ratingDropdown)
        {
            ActionResult response = null;

            //Only registered users can submit comments.
            if (ModelState.IsValid && Session["UserID"] != null && (int)Session["UserRole"] <= 3)
            {
                try
                {
                    //Parse the rating given to a byte, and set the date/time of submit.
                    view.Comment.Rating      = byte.Parse(ratingDropdown);
                    view.Comment.CommentTime = DateTime.Now;
                    //Add the comment to the database and refresh the page.
                    CommentDO commentObject = Mapper.CommentPOtoDO(view.Comment);
                    _dataAccess.AddComment(commentObject);
                    response = RedirectToAction("ViewGameComments", "Comments", new { specificGame = view.Comment.GameID });
                }
                catch (Exception ex)
                {
                    Logger.Log(ex);
                    response = RedirectToAction("Index", "Games");
                }
                finally { }
            }
            //If adding the comment failed, give them back their comment at that game.
            else
            {
                view.CommentList = ObtainGameComments(view.Comment.GameID);
                FillTempData(view.Comment.GameID);
                if (Session["UserID"] != null)
                {
                    view.Comment.UserID = (int)Session["UserID"];
                }
                response = View("ViewGameComments", view);
            }
            return(response);
        }