public DictionaryListViewModel(string tableName, IEnumerable <ColumnViewModel> columnView) { _columnView = columnView; using (var service = ServiceClientProvider.GetDictionary()) { _tableName = tableName; var response = service.GetDictionary(_tableName, columnView.Select(x => x.DbName)); var rows = new List <EntityViewModel>(); foreach (var iRow in response) { var cells = new List <CellViewModel>(); var name = string.Empty; foreach (var iColumn in columnView) { var value = iRow.Cells.First(x => x.Key == iColumn.DbName).Value; if (iColumn.DbName == "Name") { name = value; } var cell = new CellViewModel() { ColumnName = iColumn.DbName, Name = iColumn.Name, Value = value }; cells.Add(cell); } int id = int.Parse(iRow.Cells.First(x => x.Key == "Id").Value); var entity = new EntityViewModel(name, cells, id); rows.Add(entity); } Rows = new ObservableCollection <EntityViewModel>(rows); } }
public async void Queen() { // Arrange _board.A3.CurrentChessPiece = new Queen(false); _board.A4.CurrentChessPiece = new Queen(false); _board.A5.CurrentChessPiece = new Queen(false); _board.B6.CurrentChessPiece = new Queen(false); _board.G3.CurrentChessPiece = new Queen(true); _board.H4.CurrentChessPiece = new Queen(true); _board.H5.CurrentChessPiece = new Queen(true); _board.H6.CurrentChessPiece = new Queen(true); // Act await _board.CalculatePossibleSteps(); // Assert Assert.IsTrue(CellViewModel.MoveModel(_board.A3, _board.C5)); Assert.IsTrue(CellViewModel.MoveModel(_board.A5, _board.C3)); Assert.IsTrue(CellViewModel.MoveModel(_board.A4, _board.C4)); Assert.IsTrue(CellViewModel.MoveModel(_board.B6, _board.B3)); Assert.IsTrue(CellViewModel.MoveModel(_board.H4, _board.F6)); Assert.IsTrue(CellViewModel.MoveModel(_board.H6, _board.F4)); Assert.IsTrue(CellViewModel.MoveModel(_board.H5, _board.F5)); Assert.IsTrue(CellViewModel.MoveModel(_board.G3, _board.G6)); }
private async Task SelectCellViewModel(CellViewModel cellThatGotClicked) { // NextTurn, when the ViewModel moved to the newly selected ViewModel if (CellViewModel.MoveModel(SelectedCellViewModel, cellThatGotClicked)) { AddToHistory(SelectedCellViewModel, cellThatGotClicked); // Reset CheckedKingColor ResetColors(true); await NextTurn(); SelectedCellViewModel = null; } // Select ViewModel, if it's the players turn else if (cellThatGotClicked?.CurrentChessPiece != null && WhiteTurn == cellThatGotClicked.CurrentChessPiece.IsWhite()) { SelectedCellViewModel = cellThatGotClicked; SelectedCellViewModel.StartColorize(); MarkCheck(); } else { SelectedCellViewModel = null; } }
private CellViewModel CreateCell() { CellViewModel Cell = new CellViewModel(); Cell.ToggleEditMode(); return(Cell); }
public static CellViewModel CreateCellViewModel(Cell src) { var result = new CellViewModel { Value = src.Value, Index = src.Index, IsArea = src.IsArea, IsField = src.IsField, RealIndex = src.IsField ? null : src.IsArea ? src.Index : new CellIndex { I = src.Index.I.GetRealCellIndex(src.Parent.Index.I), J = src.Index.J.GetRealCellIndex(src.Parent.Index.J) } }; if (src.IsField || src.IsArea) { result.Children.Add(new CellViewModel[3]); result.Children.Add(new CellViewModel[3]); result.Children.Add(new CellViewModel[3]); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { result.Children[i][j] = CreateCellViewModel(src[i, j]); if (!result.Children[i][j].IsField) { result.Children[i][j].Parent = result; } } } } return(result); }
internal void OnMouseClickCrunch(WorldViewModel world, CoordServiceModel bigCellCoord, CoordServiceModel cellCoord) { BigCellViewModel bigcell = world.BigCells[bigCellCoord.X, bigCellCoord.Y]; CellViewModel cell = world.BigCells[bigCellCoord.X, bigCellCoord.Y].Cells[cellCoord.X, cellCoord.Y]; if (bigcell.IsFocus) { if (cell.State == State.None) { world.SetAllBigCellsToState(false); world.BigCells[cellCoord.X, cellCoord.Y].IsFocus = true; if (turn) { cell.State = State.Client; } else { cell.State = State.Enemy; } turn = !turn; if (bigcell.IsFilled()) { world.SetAllBigCellsToState(true); } } } }
public ActionResult Edit(CellViewModel cellViewModel, string submit) { if (ModelState.IsValid) { if (cellViewModel != null && submit == "Save") { cellViewModel.DateCreated = DateTime.UtcNow; cellViewModel.DateModified = DateTime.UtcNow; //var page = Mapper.Map<PageViewModel, Page>(pageViewModel); //_pageService.Edit(page); //AddMessage(this, "", "Record has Added Successfully", MessageType.Success); //return RedirectToAction("Index", "Page"); } //if (pageViewModel != null && submit == "SaveAndContinue") //{ // pageViewModel.DateCreated = DateTime.UtcNow; // pageViewModel.DateModified = DateTime.UtcNow; // var page = Mapper.Map<PageViewModel, Page>(pageViewModel); // _pageService.Edit(page); // var id = page.Id; // AddMessage(this, "", "Record has been modified successfully", MessageType.Success); // return RedirectToAction("Edit", new { id = id }); //} } return(View(cellViewModel)); }
public async void Knight() { // Arrange _board.A6.CurrentChessPiece = new Knight(false); _board.H6.CurrentChessPiece = new Knight(false); _board.A3.CurrentChessPiece = new Knight(true); _board.H3.CurrentChessPiece = new Knight(true); _board.E3.CurrentChessPiece = new Knight(true); _board.E6.CurrentChessPiece = new Knight(true); _board.D3.CurrentChessPiece = new Knight(true); _board.D6.CurrentChessPiece = new Knight(true); // Act await _board.CalculatePossibleSteps(); // Assert Assert.IsTrue(CellViewModel.MoveModel(_board.A6, _board.B4)); Assert.IsTrue(CellViewModel.MoveModel(_board.H6, _board.G4)); Assert.IsTrue(CellViewModel.MoveModel(_board.A3, _board.B5)); Assert.IsTrue(CellViewModel.MoveModel(_board.H3, _board.G5)); Assert.IsTrue(CellViewModel.MoveModel(_board.E3, _board.C4)); Assert.IsTrue(CellViewModel.MoveModel(_board.E6, _board.C5)); Assert.IsTrue(CellViewModel.MoveModel(_board.D3, _board.F4)); Assert.IsTrue(CellViewModel.MoveModel(_board.D6, _board.F5)); }
/// <summary> /// Add a new Element to the GraveYard /// </summary> /// <param name="cellViewModel">The Cell that will be added to the GraveYard</param> public void AddToGraveYard(CellViewModel cellViewModel) { if (cellViewModel?.CurrentChessPiece == null) { return; } GraveYard.Add(cellViewModel.CurrentChessPiece); }
/// <summary> /// Crea una celda del tablero /// </summary> private FrameworkElement CreateCell(CellViewModel cell) { Image image = CreateImage(GetImageFileName(cell), cell.Row, cell.Column); // Asigna el tag image.Tag = cell; // Devuelve el control return(image); }
public IActionResult Insert(CellViewModel viewModel) { if (ModelState.IsValid) { cellRepo.Insert(viewModel); return(RedirectToAction("Index")); } return(View(viewModel)); }
public IActionResult Edit(string id, CellViewModel cell) { if (ModelState.IsValid) { cellRepo.Update(cell); return(RedirectToAction("Index")); } return(View(cell)); }
public List <WordViewModel> GetWordsWordviewmodels(Dictionary <string, string> words) { ////var words = new List<string>(); //words.Add("Bamidele"); //words.Add("station"); //words.Add("india"); //words.Add("Adams"); //words.Add("fards"); //words.Add("novemb"); //words.Add("belt"); //words.Add("train"); //words.Add("adeola"); //words.Add("amoeba"); //words.Add("moscow"); var board = new Board(12); board.ProcessWords(words.Keys.ToArray()); List <InsertWordResult> result = board.InsertWordResults; IEnumerable <InsertWordResult> wordsInserted = result.Where(x => x.Inserted); var wordviewmodels = new List <WordViewModel>(); foreach (InsertWordResult word in wordsInserted) { Debug.WriteLine(word); int position = (word.StartCell.Item1 * 12) + word.StartCell.Item2; var wordViewModel = new WordViewModel { Cells = new ObservableCollection <EmptyCellViewModel>(), Direction = word.Direction, Word = word.Word, WordHint = words.First(x => x.Key == word.Word.ToString()).Value, WordLength = "(" + word.Word.Length + ")", Index = position }; int row = word.StartCell.Item1; int col = word.StartCell.Item2; foreach (char character in word.Word) { var cell = new CellViewModel(col, row, character.ToString(), wordViewModel, string.Empty); if (word.Direction == Direction.Across) { col += 1; } else { row += 1; } wordViewModel.Cells.Add(cell); } wordviewmodels.Add((wordViewModel)); } return(wordviewmodels); }
private CellViewModel GetCellViewModel([NotNull] CellViewModel cellViewModel, Movement.Direction direction) { string name; switch (direction) { case Movement.Direction.Top: name = string.Concat((cellViewModel.Name.First()), (char)(cellViewModel.Name.Last() + 1)); break; case Movement.Direction.TopRight: name = string.Concat((char)(cellViewModel.Name.First() + 1), (char)(cellViewModel.Name.Last() + 1)); break; case Movement.Direction.Right: name = string.Concat((char)(cellViewModel.Name.First() + 1), cellViewModel.Name.Last()); break; case Movement.Direction.BottomRight: name = string.Concat((char)(cellViewModel.Name.First() + 1), (char)(cellViewModel.Name.Last() - 1)); break; case Movement.Direction.Bottom: name = string.Concat(cellViewModel.Name.First(), (char)(cellViewModel.Name.Last() - 1)); break; case Movement.Direction.BottomLeft: name = string.Concat((char)(cellViewModel.Name.First() - 1), (char)(cellViewModel.Name.Last() - 1)); break; case Movement.Direction.Left: name = string.Concat((char)(cellViewModel.Name.First() - 1), (cellViewModel.Name.Last())); break; case Movement.Direction.TopLeft: name = string.Concat((char)(cellViewModel.Name.First() - 1), (char)(cellViewModel.Name.Last() + 1)); break; case Movement.Direction.Final: return(null); default: throw new ArgumentOutOfRangeException(nameof(direction), direction, null); } var letter = name.First(); var number = name.Last(); if (number > '8' || number < '1' || letter > 'H' || letter < 'A') { return(null); } return(_referenceCellList.First(c => Equals(c.Name, name)));; }
/// <summary> Изменить размер </summary> public void ReSize(uint countOfRows) { var newcolumn = new CellViewModel <T> [countOfRows]; for (int i = 0; i < Math.Min((_column.Length), countOfRows); i++) { newcolumn[i] = _column[i]; } _column = newcolumn; }
public IActionResult Check([FromBody] CellViewModel gameField) { var field = MapHelper.CreateCell(gameField); var res = _validateService.Execute(field); if (res) { return(Ok()); } return(BadRequest()); }
public IActionResult AddCell([FromBody] CellViewModel cellViewModel) { try { cellService.Add(cellViewModel); return(StatusCode(StatusCodes.Status201Created, cellViewModel)); } catch (Exception e) { Log.Error(e.ToString()); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
internal void Update(CellViewModel cell) { cell.previousVisibleState = cell.currentVisibleState; cell.previousMouseState = cell.currentMouseState; cell.currentMouseState = Mouse.GetState(); if (cell.rectangle.Contains(cell.currentMouseState.X, cell.currentMouseState.Y)) { if (cell.currentMouseState.LeftButton == ButtonState.Pressed) { if (cell.previousMouseState.LeftButton == ButtonState.Released) { cell.OnMouseDown(EventArgs.Empty); cell.currentVisibleState = VisibleState.Pressed; } else { if (cell.currentVisibleState != VisibleState.Pressed) { cell.currentVisibleState = VisibleState.Hover; } } } else { if (cell.previousVisibleState == VisibleState.Pressed) { cell.OnMouseClick(null); } cell.currentVisibleState = VisibleState.Hover; } } else { if (cell.previousVisibleState == VisibleState.Hover || cell.previousVisibleState == VisibleState.Pressed) { cell.OnMouseOut(EventArgs.Empty); } cell.currentVisibleState = VisibleState.Normal; } if (cell.currentMouseState.LeftButton == ButtonState.Released && cell.previousVisibleState == VisibleState.Pressed) { cell.OnMouseUp(EventArgs.Empty); } }
private void SetActiveCell(Cell cell) { if (_activeCell != null) { _activeCell.IsActive = false; _activeCell = null; } if (cell != null) { _activeCell = _cellViewModels.Single(x => x.Cell == cell); _activeCell.IsActive = true; SetSelection(_activeCell); } }
protected virtual CellViewModel MapCell(CellModel model) { var text = Regex.Replace(model.Value, $@"\{BoldSymbol}([^*]+)\{BoldSymbol}", match => $"{BoldTagOpen}{match.Groups[1].Value}{BoldTagClose}"); var(value, align) = EjectAlign(text); var result = new CellViewModel { Value = value, Align = align }; return(result); }
/// <summary> /// Add a new Element to the History /// </summary> /// <param name="startModel">The StartCell, which was selected first</param> /// <param name="endModel">The EndCell, which was moved / eaten to</param> private void AddToHistory(CellViewModel startModel, CellViewModel endModel) { if (startModel == null || endModel == null) { return; } var historyViewModel = new HistoryViewModel { FromCell = startModel, ToCell = endModel }; History.Add(historyViewModel); }
private async Task CreateEmptyChessBoard() { for (var number = 1; number <= 8; number++) { for (int character = 'A'; character <= 'H'; character++) { var propertyName = (char)character + number.ToString(); var property = new CellViewModel(null, this) { Name = propertyName }; AllCells.Add(property); } } await CreateLink(); }
public async void EatImpossible() { // Arrange var pathList = new List <Path> { PathFactory.Instance.AddToPath(Movement.Direction.Top).SetIsRecursive(false).Create(), PathFactory.Instance.AddToPath(Movement.Direction.Bottom).SetIsRecursive(true).Create(), PathFactory.Instance.AddToPath(Movement.Direction.Left).SetIsRecursive(true).Create() }; var chessPieceMock = new Mock <IChessPiece>(); chessPieceMock .Setup(mock => mock.IsWhite()) .Returns(true); chessPieceMock .Setup(mock => mock.PathList) .Returns(pathList); _board.D5.CurrentChessPiece = chessPieceMock.Object; _board.D4.CurrentChessPiece = _blackChessPieceMock.Object; _board.D3.CurrentChessPiece = _blackChessPieceMock.Object; _board.B5.CurrentChessPiece = _blackChessPieceMock.Object; _board.B3.CurrentChessPiece = _blackChessPieceMock.Object; var d5 = _board.D5.CurrentChessPiece; var d4 = _board.D4.CurrentChessPiece; var d3 = _board.D3.CurrentChessPiece; var b5 = _board.B5.CurrentChessPiece; var b3 = _board.B3.CurrentChessPiece; // Act await _board.CalculatePossibleSteps(); CellViewModel.MoveModel(_board.D5, _board.D3); CellViewModel.MoveModel(_board.D5, _board.D3); CellViewModel.MoveModel(_board.D5, _board.B5); // Assert Assert.IsNull(_board.D5.CurrentChessPiece, "There is still a ChessPiece on the CellViewModel D5, which should have moved away"); Assert.AreEqual(_board.D4.CurrentChessPiece, d4, "ChessPiece 'd4' shouldn't be removed"); Assert.AreEqual(_board.D3.CurrentChessPiece, d3, "ChessPiece 'd3' shouldn't be removed"); Assert.AreEqual(_board.B3.CurrentChessPiece, b3, "ChessPiece 'b3' did get eaten, but there was no valid Path"); Assert.AreEqual(_board.B5.CurrentChessPiece, d5, "ChessPiece 'd5' didn't move to the CellViewModel 'B5'"); Assert.AreEqual(_board.GraveYard.Count, 1, "There where more ChessPieces in the Graveyard than expected"); Assert.True(_board.GraveYard.Contains(b5), "ChessPiece 'b5' wasn't in the Graveyard, but should have been there"); }
public async void Rook() { // Arrange _board.C5.CurrentChessPiece = new Rook(false); _board.D5.CurrentChessPiece = new Rook(false); _board.A3.CurrentChessPiece = new Rook(true); _board.G6.CurrentChessPiece = new Rook(true); // Act await _board.CalculatePossibleSteps(); // Assert Assert.IsTrue(CellViewModel.MoveModel(_board.C5, _board.A5)); Assert.IsTrue(CellViewModel.MoveModel(_board.D5, _board.E5)); Assert.IsTrue(CellViewModel.MoveModel(_board.A3, _board.A4)); Assert.IsTrue(CellViewModel.MoveModel(_board.G6, _board.G3)); }
public async void Bishop() { // Arrange _board.A3.CurrentChessPiece = new Bishop(true); _board.D4.CurrentChessPiece = new Bishop(false); _board.G6.CurrentChessPiece = new Bishop(true); _board.A6.CurrentChessPiece = new Bishop(false); // Act await _board.CalculatePossibleSteps(); // Assert Assert.IsTrue(CellViewModel.MoveModel(_board.A3, _board.D6)); Assert.IsTrue(CellViewModel.MoveModel(_board.D4, _board.B6)); Assert.IsTrue(CellViewModel.MoveModel(_board.G6, _board.E4)); Assert.IsTrue(CellViewModel.MoveModel(_board.A6, _board.C4)); }
public async void MoveImpossible() { var pathList = new List <Path> { PathFactory.Instance.AddToPath(Movement.Direction.Bottom).SetIsRecursive(true).Create(), PathFactory.Instance.AddToPath(Movement.Direction.Left).SetIsRecursive(true).Create() }; var unitUnderTest = new Mock <IChessPiece>(); unitUnderTest .Setup(mock => mock.IsWhite()) .Returns(true); unitUnderTest .Setup(mock => mock.IsBlack()) .Returns(false); unitUnderTest .Setup(mock => mock.PathList) .Returns(pathList); // Arrange _board.D5.CurrentChessPiece = unitUnderTest.Object; _board.D4.CurrentChessPiece = unitUnderTest.Object; var d5 = _board.D5.CurrentChessPiece; var d4 = _board.D4.CurrentChessPiece; // Act await _board.CalculatePossibleSteps(); CellViewModel.MoveModel(_board.D5, _board.D3); CellViewModel.MoveModel(_board.D5, _board.B3); CellViewModel.MoveModel(_board.D5, _board.B5); // Assert Assert.IsNull(_board.D5.CurrentChessPiece, "There is still a ChessPiece on the CellViewModel D5, which should have moved away"); Assert.AreEqual(_board.D4.CurrentChessPiece, d4, "ChessPiece 'd4' shouldn't be removed"); Assert.IsNull(_board.D3.CurrentChessPiece, "ChessPiece 'd5' did move to the CellViewModel 'D3', but there was no valid Path"); Assert.IsNull(_board.B3.CurrentChessPiece, "ChessPiece 'd5' did move to the CellViewModel 'B3', but there was no valid Path"); Assert.AreEqual(_board.B5.CurrentChessPiece, d5, "ChessPiece 'd5' didn't move to the CellViewModel 'B5'"); Assert.AreEqual(_board.GraveYard.Count, 0, "There where more ChessPieces in the Graveyard than expected"); }
public ReturnPackageMainWindow(ReturnPackage returnPackage) { InitializeComponent(); var returnFilesViewModel = new ReturnFilesViewModel(returnPackage, this); _returnPackageFiles = new ReturnFiles(returnFilesViewModel); _cellViewModel = new CellViewModel(); var returnPackageMainWindowViewModel = new ReturnPackageMainWindowViewModel(returnFilesViewModel, _cellViewModel, this); DataContext = returnPackageMainWindowViewModel; if (returnPackageMainWindowViewModel.CloseAction == null) { returnPackageMainWindowViewModel.CloseAction = Close; } }
public IActionResult UpdateCell([FromBody] CellViewModel cellViewModel) { if (!ModelState.IsValid) { return(StatusCode(StatusCodes.Status500InternalServerError)); } try { cellService.Update(cellViewModel); return(StatusCode(StatusCodes.Status200OK)); } catch (Exception e) { Log.Error(e.ToString()); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) { var shouldShowLottie = false; var cell = tableView.DequeueReusableCell(cellIdentifier, indexPath) as NewCustomTableViewCell; CellViewModel item = tableItems[indexPath.Row]; cell.UserInteractionEnabled = false; if (item.ShouldShowDisclosureIndicator == true) { shouldShowLottie = true; cell.UserInteractionEnabled = true; } cell.UpdateCell(item.Title, item.Subtitle, shouldShowLottie); return(cell); }
public bool LinkCellViewModel([NotNull] CellViewModel cellViewModel, List <CellViewModel> referenceCellList) { _referenceCellList = referenceCellList; if (cellViewModel == null) { throw new NotImplementedException("CellViewModel can't be null!"); } var newMovements = new Dictionary <Movement.Direction, CellViewModel>(); foreach (Movement.Direction direction in Enum.GetValues(typeof(Movement.Direction))) { newMovements.Add(direction, GetCellViewModel(cellViewModel, direction)); } cellViewModel.CreateLink(newMovements); return(true); }