/// <summary> /// Basicly transformthe board view model to the Board entity object. /// </summary> /// <param name="boardViewModel">The <see cref="BoardViewModel"/> object we will transform to a domain object.</param> /// <returns>The transformed <see cref="Board"/> object.</returns> public static Board BoardViewModelToBoard(BoardViewModel boardViewModel) { var board = new Board() { Id = boardViewModel.Id, BoardName = boardViewModel.BoardName, }; return board; }
/// <summary> /// Transforms the Board entity object to a Board View Model object /// </summary> /// <param name="board">The entity <see cref="Board"/> object we will transform to a view model.</param> /// <returns><see cref="BoardViewModel"/> object.</returns> public static BoardViewModel BoardToBoardViewModel(Board board) { var boardViewModel = new BoardViewModel() { BoardName = board.BoardName, Id = board.Id, UserId = board.Owner == null? Guid.Empty : board.Owner.Id }; return boardViewModel; }
public ActionResult SaveBoard(BoardViewModel boardViewModel) { var result = new JsonResultViewModel(); // Get the id of the currently logged in user var userId = GetUserId(); var board = BoardMapper.BoardViewModelToBoard(boardViewModel); // Try and save the board using the note service. var savedBoard = _noteService.SaveOrUpdateBoard(board, userId); // If the board was saved successfuly if (savedBoard != null) { // Set the propper values for the Json result object result.Success = true; result.Message = " Board saved successfully"; // Set the data to the saved/updated board, transformed to a BoardViewModel object result.Data = BoardMapper.BoardToBoardViewModel(savedBoard); // Return the json result object in JSON format to the client side code. // It contains the saved/updated board in the Data attribute return Json(result); } else { // Something went wrong while saving/upadting the board. // Set the propper values in the json result object result.Success = false; result.Message = "Failed to save the board"; result.Data = null; return Json(result); } }