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 })); }
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)); }
private void GenerateBoard() { _boardGenerator = GetComponent <BoardGenerator>(); _board = _boardGenerator.GenerateBoard(_boardBlueprint); _boardMapper = new BoardMapper(); _boardMapper.MapNeighbours(_board); }
public ActionResult <BoardDTO> SetBoard([FromBody] BoardDTO boardDTO) { telemetry.TrackEvent("Custom HTTP Post Method in /SetBoard URL"); Logger.LogInformation("Call to HTTP Post Method in /SetBoard URL"); if (boardDTO == null || !ModelState.IsValid) { return(BadRequest("Board is null")); } var board = BoardMapper.DTOtoBoard(boardDTO); var ResultBoardDTO = ConserveBoardInMemory.Set(board).ToDTO(); return(Ok(ResultBoardDTO)); }
private void btnOK_Click(object sender, EventArgs e) { try { BoardSettings = BoardMapper.GetBoardFromOtomataUrl(txtUrl.Text); DialogResult = System.Windows.Forms.DialogResult.OK; this.Close(); } catch (Exception) { MessageBox.Show("Unable to parse otomata url"); } }
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)); }
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)); }
/// <summary> /// Generate notes from the board /// </summary> /// <returns></returns> private List <Note> GenerateNotes() { pbProgress.Visible = true; lblStatus.Text = "Generating..."; // determine ending value and condition int nrOfStepsToProcess = (int)nudNumberOfSteps.Value; int nrOfNotesToPlay = (int)nudNumberOfNotes.Value; int nrOfMsToPass = (int)nudTimeElapsed.Value * 1000; ExportConditionEnum condition = ExportConditionEnum.TimeLimit; if (rdbNumberOfNotes.Checked) { condition = ExportConditionEnum.NoteLimit; } else if (rdbNumberOfSteps.Checked) { condition = ExportConditionEnum.StepLimit; } else if (rdbTimeElapsed.Checked) { condition = ExportConditionEnum.TimeLimit; } // keep track of steps since last note to prevent infinite loop int stepsSinceLastNote = 0; int curStep = 0; int curNoteCount = 0; int curMsPassed = 0; DateTime startTime = DateTime.Now; // take a deep copy of the board settings (don't want to alter the current board) BoardSettings boardsettings; if (!BoardMapper.TryGetBoardSettingsFromString(BoardMapper.GetStringFromBoardSettings(boardSettings), out boardsettings)) { MessageBox.Show("Could not create a copy of the current board", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(null); } List <Note> notes = new List <Note>(); double progress; // continue advancing to next state until either cancelled or condition is met while (!cancelGenerating && !ExportConditionMet(condition, curStep, curNoteCount, curMsPassed, nrOfStepsToProcess, nrOfNotesToPlay, nrOfMsToPass, out progress)) { // advance board boardsettings.Board.NextState(); // get the active notes of the board var activeNotes = GetNotesForActiveCells(boardsettings); // and update the correct time played foreach (var n in activeNotes) { n.TimeDown = startTime.AddMilliseconds(curMsPassed); } // and add them to the notes list notes.AddRange(activeNotes); curStep++; curNoteCount += activeNotes.Count; curMsPassed += boardsettings.Speed; // check steps since last note if (activeNotes.Count == 0) { stepsSinceLastNote++; } else { stepsSinceLastNote = 0; } // prevent infinite loop when no notes are played anymore, ask user to continue if (stepsSinceLastNote > 10000) { DialogResult result = MessageBox.Show("There have been no notes for 10000 steps now, do you want to continue generating?", "No notes for a long time", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == System.Windows.Forms.DialogResult.No) { break; } else { stepsSinceLastNote = 0; // reset steps since last note } } // update gui each 100 steps if (curStep % 100 == 0) { pbProgress.Value = (int)(progress * 100); lblStatus.Text = "Generating... | Current iteration " + curStep; Application.DoEvents(); } } pbProgress.Visible = false; if (notes.Count <= 0) { lblStatus.Text = "No midi generated, there weren't any notes to record"; } else { lblStatus.Text = "Midi generated"; } return(notes); }