Пример #1
0
        public ActionResult BoardCommentUpdate(int iBoardCommentID)
        {
            // Instantiate objects
            BoardCommentBLL    lBoardCommentBLL    = new BoardCommentBLL();
            BoardCommentMapper lBoardCommentMapper = new BoardCommentMapper();

            // Find the BoardComment by boardCommentIDPK
            BoardCommentDBO lBoardCommentDBO = lBoardCommentBLL.FindBoardCommentByBoardCommentID(iBoardCommentID);

            BoardComment lBoardComment = new BoardComment();

            if (lBoardCommentDBO != null)
            {
                // Map DB object to Model and pre-populate the comment
                lBoardComment = lBoardCommentMapper.MapBoardCommentDBOToBoardComment(lBoardCommentDBO);
            }
            else
            {
                // redirect to the post with error message
                TempData["msg"] = "<script> alert('Error occured while processing your request.') </script>";
                return(RedirectToAction("BoardView", "Board", new { @id = iBoardCommentID }));
            }

            return(PartialView("BoardCommentUpdate", lBoardComment));
        }
Пример #2
0
        public ActionResult BoardCommentCreate(BoardAndCommentsViewModel iBoardComment)
        {
            // check if all inputs are valid
            if (ModelState.IsValid)
            {
                // Increate Mapper object
                BoardCommentMapper lBoardCommentMapper = new BoardCommentMapper();

                // Map Model.BoardComment to BoardCommentDBO
                BoardCommentDBO lBoardCommentDBO = lBoardCommentMapper.MapBoardCommentToBoardCommentDBO(iBoardComment);

                // Instantiate BoardCommentBLL object
                BoardCommentBLL lBoardCommentBLL = new BoardCommentBLL();

                // Insert into Database and get BoardComment ID PK as return value
                int lResult = lBoardCommentBLL.CreateBoardComment(lBoardCommentDBO);

                // If successfully inserted, redirect to the post
                if (lResult > 0)
                {
                    // message on success
                    TempData["msg"] = "<script>alert('Successfully Written!');</script>";
                    return(RedirectToAction("BoardView", "Board", new { id = lBoardCommentDBO.BoardIDFK }));
                }
                else
                {
                    // error message
                    TempData["msg"] = "<script> alert('Error occured while processing your requset. Please try later.') </script>";
                }
            }
            else
            {
                // error message
                TempData["msg"] = "<script> alert('Please all Required Fields.') </script>";
            }

            // redirect to post with error message
            return(RedirectToAction("BoardView", "Board", new { id = iBoardComment.BoardComment.BoardIDFK }));
        }
Пример #3
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));
        }
Пример #4
0
        public ActionResult BoardCommentUpdate(BoardComment iBoardComment)
        {
            // instantiate objects
            BoardCommentBLL    lBoardCommentBLL    = new BoardCommentBLL();
            BoardCommentMapper lBoardCommentMapper = new BoardCommentMapper();

            // Map Model to DB objects
            BoardCommentDBO lBoardCommentDBO = lBoardCommentMapper.MapBoardCommentToBoardCommentDBO(iBoardComment);

            // Get bool result for updating comment
            bool lResult = lBoardCommentBLL.UpdateBoardCommentByBoardCommentID(lBoardCommentDBO);

            if (lResult)
            {
                TempData["msg"] = "<script> alert('Successfully Updated!') </script>";
                // redirect to the board view
                return(RedirectToAction("BoardView", "Board", new { id = iBoardComment.BoardIDFK }));
            }
            else
            {
                return(Json(new { success = false }));
            }
        }