Beispiel #1
0
        public ActionResult BoardUpdate(int id)
        {
            // Instantiate BoardBLL object
            BoardBLL lBoardBLL = new BoardBLL();

            // check if the user requesting to edit the view is same user by boardID and UserID
            bool lIsSameUser = lBoardBLL.FindBoolSameUserByUserIDAndBoardID(id, Convert.ToInt32(Session["AUTHUserIDPK"]));

            // if it is different user who is requesting to edit the post, redirect to the view with error message
            if (!lIsSameUser)
            {
                int lBoardID = id;
                TempData["msg"] = "<script>alert('You are not authorized to edit.');</script>";
                return(RedirectToAction("BoardView", "Board", new { id = lBoardID }));
            }

            // Find the board with id as primary key
            BoardDBO lBoardDBO = lBoardBLL.FindBoardByBoardID(id);

            // Instantiate Model.Board object
            BoardMapper lBoardMapper = new BoardMapper();

            // Map to Model.Board
            Board lBoard = lBoardMapper.MapBoardDBOToBoard(lBoardDBO);

            return(View(lBoard));
        }
Beispiel #2
0
        public ActionResult BoardView(int id)
        {
            // Instantiate BCViewModel to pass three models
            BoardAndCommentsViewModel lBCViewModel = new BoardAndCommentsViewModel();

            // Instantiate Mapper Objects
            BoardCommentMapper lBCMapper    = new BoardCommentMapper();
            BoardMapper        lBoardMapper = new BoardMapper();

            // Instantiate BLL Objects
            BoardBLL        lBoardBLL        = new BoardBLL();
            BoardCommentBLL lBoardCommentBLL = new BoardCommentBLL();


            // Retreive data for post from database based on BoardIDPK
            BoardDBO lBoardDBO = lBoardBLL.FindBoardByBoardID(id);

            // if there is no post with the id, redirect to board list with error message
            if (lBoardDBO == null)
            {
                TempData["msg"] = "<script>alert('Error occured while processing your request.')</script>";
                return(RedirectToAction("BoardList", "Board"));
            }

            // Retreive data for comments from database based on BoardIDPK
            List <BoardCommentDBO> lBoardCommentDBOList = lBoardCommentBLL.GetAllCommentsByBoardID(id);

            // Map DB objects to Model.BoardComment
            lBCViewModel.BoardCommentList = lBCMapper.MapBoardCommentDBOToBoardComment(lBoardCommentDBOList);
            lBCViewModel.Board            = lBoardMapper.MapBoardDBOToBoard(lBoardDBO);

            // set values for board comment
            lBCViewModel.BoardComment           = new BoardComment();
            lBCViewModel.BoardComment.BoardIDFK = lBCViewModel.Board.BoardIDPK;
            lBCViewModel.BoardComment.UserIDFK  = Convert.ToInt32(Session["AUTHUserIDPK"]);

            return(View(lBCViewModel));
        }