/// <summary> /// Description: This method maps Model object to database obect /// </summary> /// <param name="iBoardComment">Object to be mapped</param> /// <returns>BoardCommentDBO object</returns> public BoardCommentDBO MapBoardCommentToBoardCommentDBO(BoardAndCommentsViewModel iBoardComment) { // Instantiate BoardCommentDBO object BoardCommentDBO lBoardCommentDBO = new BoardCommentDBO(); // set values lBoardCommentDBO.BoardIDFK = iBoardComment.BoardComment.BoardIDFK; lBoardCommentDBO.UserIDFK = iBoardComment.BoardComment.UserIDFK; lBoardCommentDBO.Content = iBoardComment.BoardComment.Content; return(lBoardCommentDBO); }
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 })); }
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)); }