Beispiel #1
0
        public ActionResult BoardUpdate(Board iBoard)
        {
            if (ModelState.IsValid)
            {
                // Instantiate BoardMapper object
                BoardMapper lBoardMapper = new BoardMapper();
                BoardDBO    lBoardDBO    = lBoardMapper.MapBoardTOBoardDBO(iBoard);

                // Instantiate BoardBLL object
                BoardBLL lBoardBLL = new BoardBLL();

                // Update the board in database
                bool lResult = lBoardBLL.UpdateBoardByBoardID(lBoardDBO);

                if (lResult)
                {
                    // success
                    iBoard.type    = 1;
                    iBoard.message = "Successfully Updated!";
                }
                else
                {
                    // fail
                    iBoard.type    = -1;
                    iBoard.message = "Failed to Update!";
                }
            }
            else
            {
                iBoard.type    = -1;
                iBoard.message = "Please Fill all required fields.";
            }

            return(RedirectToAction("BoardView", "Board", new { @id = iBoard.BoardIDPK }));
        }
Beispiel #2
0
        public ActionResult BoardCreate(Board iBoard)
        {
            // check if every input is valid
            if (ModelState.IsValid)
            {
                //get value from executing query
                int lResult = 0;

                // Instantiate Mapper object
                BoardMapper lBoardMapper = new BoardMapper();

                // Map Model.Board to BoardDBO
                BoardDBO lBoardDBO = lBoardMapper.MapBoardTOBoardDBO(iBoard);

                // Instantiate DAL object
                BoardBLL lBoardBLL = new BoardBLL();

                // Change the UserIDFK to Session["AUTHUserIDPK"]
                lBoardDBO.UserIDFK = Convert.ToInt32(Session["AUTHUserIDPK"]);

                // insert into the database
                lResult = lBoardBLL.CreateBoard(lBoardDBO);

                // Success
                if (lResult > 0)
                {
                    // message on success
                    TempData["msg"] = "<script>alert('Successfully Written!');</script>";
                    return(RedirectToAction("BoardList", "Board"));
                }

                // Failed to insert
                else
                {
                    // message on failure
                    iBoard.type    = -1;
                    iBoard.message = "Failed. Please try again.";
                }
            }
            // ModelState is not valid
            else
            {
                iBoard.type    = -1;
                iBoard.message = "Please Fill all Required Information.";
            }

            return(View(iBoard));
        }