protected static StringBuilder BuildMovementOutput(string value, CellDTO cellDTO, bool?hasMoved) { var output = new StringBuilder(); switch (hasMoved) { case true: { output.Append(string.Format(StaticText.GoIntent_Traveled, value)); break; } case false: { output.Append(string.Format(StaticText.GoIntent_CantGoThatWay, value)); break; } case null: default: { output.Append(StaticText.GoIntent_DontKnowHow); break; } } return(output); }
private static bool?MoveDirection(Directions enumValue, PlayerDTO playerDTO, CellDTO cellDTO) { if (enumValue == Directions.None) { return(null); } var canGoNorth = enumValue == Directions.North && cellDTO.Directions.HasFlag(Directions.North); playerDTO.LocationY = canGoNorth ? --playerDTO.LocationY : playerDTO.LocationY; var canGoEast = enumValue == Directions.East && cellDTO.Directions.HasFlag(Directions.East); playerDTO.LocationX = canGoEast ? ++playerDTO.LocationX : playerDTO.LocationX; var canGoSouth = enumValue == Directions.South && cellDTO.Directions.HasFlag(Directions.South); playerDTO.LocationY = canGoSouth ? ++playerDTO.LocationY : playerDTO.LocationY; var canGoWest = enumValue == Directions.West && cellDTO.Directions.HasFlag(Directions.West); playerDTO.LocationX = canGoWest ? --playerDTO.LocationX : playerDTO.LocationX; return(canGoNorth || canGoEast || canGoSouth || canGoWest); }
public Result <bool> UpdateRecord(string schemaName, string tableName, CellDTO cellNew, List <CellDTO> recordPrevious, ConnectionParams connParams) { if (!recordPrevious.Any()) { return(Result <bool> .Fail(new List <string>() { "Unable to identify record" })); } var columnValuesWhere = recordPrevious.Select(x => x.Value.ToLower().Equals("null") ? $"[{x.ColumnName}] IS NULL" : $"[{x.ColumnName}] = {_msSqlQueryBuilder.ToQuery(x.ColumnType, x.Value)}" ); var whereExpr = string.Join(" and ", columnValuesWhere); var setExpr = $"[{cellNew.ColumnName}] = {_msSqlQueryBuilder.ToQuery(cellNew.ColumnType, cellNew.Value)}"; var sqlCommand = $"UPDATE [{schemaName}].[{tableName}] SET {setExpr} WHERE {whereExpr}"; var sqlResult = ExecuteSQL(sqlCommand, connParams); if (sqlResult.RowsAffected != 1) { sqlResult.Messages.Add($"Total of {sqlResult.RowsAffected} rows updated"); } if (sqlResult.Messages.Any()) { return(Result <bool> .Fail(sqlResult.Messages)); } return(Result <bool> .Success(true)); }
public static int GetPlanetIdByLocation(IStarWars3DB context, CellDTO cell) { int id = context.Planets.FirstOrDefault(p => p.PlanetTemplate.Locations.Any(l => (l.row == cell.row) && (l.col == cell.col))).Id; return(id); }
public void IsCellAdded() { var options = new DbContextOptionsBuilder <AppDbContext>() .UseInMemoryDatabase(databaseName: "database_to_add_cell") .Options; var appDbContext = new AppDbContext(options); var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, "abcd"), })); appDbContext.UserPermissions.Add(new UserPermission { Id = 1, UserName = "******", IdPrison = 1, Prison = new Prison { Id = 1, PrisonName = "prison_test" } }); appDbContext.SaveChanges(); var loggerRepository = new LoggerRepository(appDbContext); var loggerService = new LoggerService(loggerRepository); var cellRepository = new CellRepository(appDbContext); var cellService = new CellService(cellRepository); var cellController = new PCellsController( cellService, _mapper, loggerService) { ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = user } } }; var cell1 = new CellDTO { Beds = 1, IdCellType = 1, }; Assert.IsFalse(appDbContext.Cells.Any(), "Cell was added before it should be"); cellController.AddCell(cell1); Assert.AreEqual(1, appDbContext.Cells.Count(), "amount of cells is wrong"); }
public static void ChangeUnitLocation(IStarWars3DB context, CellDTO selectedCell, CellDTO previousCell) { Unit unit = GetUnitByLocation(context, previousCell.row, previousCell.col); Cell newLocation = new Cell { row = selectedCell.row, col = selectedCell.col }; context.Cells.Add(newLocation); unit.Location = newLocation; context.SaveChanges(); }
public Game(IStarWars3DB data) { this.data = data; if (selectedCell == null) { selectedCell = new CellDTO(); } if (previousCell == null) { previousCell = new CellDTO(); } }
public void UpdateCellUnitTests() { // Arrange var pCellsController = this.CreatePCellsController(); int id = 0; CellDTO cellDto = new CellDTO(); // Act var result = pCellsController.UpdateCell( id, cellDto); // Assert Assert.IsInstanceOf <ActionResult>(result); }
private void GenerateBasicSchema(ref SudokuSchemaDTO sudoku) { ColumnsLogic columns = new ColumnsLogic(); LinesLogic lines = new LinesLogic(); while (sudoku.Solution.Count < 9) { string row = lines.GenerateNew(); if (sudoku.Solution.Contains(row)) { continue; } if (columns.IsValid(sudoku.Solution, row)) { var chars = row.ToCharArray(); for (int i = 0; i < chars.Length; i++) { var cell = new CellDTO(sudoku.Solution.Count, i) { Value = chars[i].ToString(), IsVisible = false, }; foreach (var item in sudoku.CellsToShow) { if (item.Row != sudoku.Solution.Count) { continue; } if (item.Column != i) { continue; } cell.IsVisible = true; } sudoku.SolutionMatrix.Add(cell); } sudoku.Lines.Add(new LineDTO(sudoku.Solution.Count, row)); sudoku.Solution.Add(row); } } }
public ActionResult <CellVM> AddCell(CellDTO cellDTO) { string userName = User.Identity.Name; var cellModel = _mapper.Map <Cell>(cellDTO); cellModel.IdPrison = _cellService.PrisonID(userName); if (cellModel.Id == null) { return(NotFound()); } _cellService.CreateCell(cellModel); _cellService.SaveChanges(); _loggerService.AddLog(controller, "Dodano nową cele", userName); return(Ok()); }
static string RenderCell(CellDTO cell) { switch (cell) { case CellDTO c when !c.isOccupied: return("."); case CellDTO c when c.color == "black" && c.rank == "pawn": return("p"); case CellDTO c when c.color == "black" && c.rank == "rook": return("r"); case CellDTO c when c.color == "black" && c.rank == "knight": return("n"); case CellDTO c when c.color == "black" && c.rank == "bishop": return("b"); case CellDTO c when c.color == "black" && c.rank == "queen": return("q"); case CellDTO c when c.color == "black" && c.rank == "king": return("k"); case CellDTO c when c.color == "white" && c.rank == "pawn": return("P"); case CellDTO c when c.color == "white" && c.rank == "rook": return("R"); case CellDTO c when c.color == "white" && c.rank == "knight": return("N"); case CellDTO c when c.color == "white" && c.rank == "bishop": return("B"); case CellDTO c when c.color == "white" && c.rank == "queen": return("Q"); case CellDTO c when c.color == "white" && c.rank == "king": return("K"); default: throw new Exception("Invalid piece."); } }
static string RenderCell(CellDTO cell) { switch (cell) { case CellDTO c when !c.IsOccupied: return("."); case CellDTO c when c.Color == "black" && c.Rank == "pawn": return(glyphForPiece(c.Rank, c.Color)); case CellDTO c when c.Color == "black" && c.Rank == "rook": return(glyphForPiece(c.Rank, c.Color)); case CellDTO c when c.Color == "black" && c.Rank == "knight": return(glyphForPiece(c.Rank, c.Color)); case CellDTO c when c.Color == "black" && c.Rank == "bishop": return(glyphForPiece(c.Rank, c.Color)); case CellDTO c when c.Color == "black" && c.Rank == "queen": return(glyphForPiece(c.Rank, c.Color)); case CellDTO c when c.Color == "black" && c.Rank == "king": return(glyphForPiece(c.Rank, c.Color)); case CellDTO c when c.Color == "white" && c.Rank == "pawn": return(glyphForPiece(c.Rank, c.Color)); case CellDTO c when c.Color == "white" && c.Rank == "rook": return(glyphForPiece(c.Rank, c.Color)); case CellDTO c when c.Color == "white" && c.Rank == "knight": return(glyphForPiece(c.Rank, c.Color)); case CellDTO c when c.Color == "white" && c.Rank == "bishop": return(glyphForPiece(c.Rank, c.Color)); case CellDTO c when c.Color == "white" && c.Rank == "queen": return(glyphForPiece(c.Rank, c.Color)); case CellDTO c when c.Color == "white" && c.Rank == "king": return(glyphForPiece(c.Rank, c.Color)); default: throw new Exception("Invalid piece."); } }
private static bool?EnteredPortal(Directions enumValue, PlayerDTO playerDTO, CellDTO cellDTO) { if (cellDTO.GotoMapRefId.HasValue && cellDTO.GotoX.HasValue && cellDTO.GotoY.HasValue && cellDTO.PortalDirections.HasValue && cellDTO.PortalDirections.Value.HasFlag(enumValue)) { playerDTO.MapRefId = (Guid)cellDTO.GotoMapRefId; playerDTO.LocationX = (int)cellDTO.GotoX; playerDTO.LocationY = (int)cellDTO.GotoY; return(true); } return(false); }
public ActionResult UpdateCell(int id, [FromBody] CellDTO cellDTO) { string userName = User.Identity.Name; var cell = _cellService.SelectedCell(id); if (cell == null) { return(NotFound()); } _mapper.Map(cellDTO, cell); _cellService.UpdateCell(cell); _cellService.SaveChanges(); _loggerService.AddLog(controller, "Edytowano cele o ID " + cell.Id, userName); return(Ok()); }
public Collection <SheetDTO> extractExcelToCellDtos(string path) { Collection <SheetDTO> rtnCollection = new Collection <SheetDTO>(); var filePath = path; var document = SpreadsheetDocument.Open(filePath, false); var workbookPart = document.WorkbookPart; var workbook = workbookPart.Workbook; var sheets = workbook.Descendants <Sheet>(); foreach (var sheet in sheets) { SheetDTO sheetDTO = new SheetDTO(); sheetDTO.Cells = new Collection <CellDTO>(); sheetDTO.SheetId = sheet.Id; sheetDTO.SheetName = sheet.Name; var worksheetPart = (WorksheetPart)workbookPart.GetPartById(sheet.Id); var sharedStringPart = workbookPart.SharedStringTablePart; var values = sharedStringPart; var lastCell = worksheetPart.Worksheet.Descendants <Cell>().LastOrDefault(); //var values2 = sharedStringPart.SharedStringTable; //var values3 = sharedStringPart.SharedStringTable.Elements<SharedStringItem>(); //var values4 = sharedStringPart.SharedStringTable.Elements<SharedStringItem>().ToArray(); var cells = worksheetPart.Worksheet.Descendants <Cell>(); foreach (var cell in cells) { CellDTO cellDTO = new CellDTO(); cellDTO.CellAddress = cell.CellReference; cellDTO.Value = cell.CellValue != null ? cell.CellValue.Text : null; cellDTO.Formula = cell.CellFormula != null ? cell.CellFormula.Text : null; sheetDTO.Cells.Add(cellDTO); } rtnCollection.Add(sheetDTO); } return(rtnCollection); }
public static void buildUnit(IStarWars3DB context, int playerId, UnitType unitType, CellDTO location) { Cell cell = FreeCell(context, location.row, location.col); //UnitLevel uLevel = GetUnitLevel(context, unitType, 0); if (cell != null) { UnitTemplate unitTemplate = context.UnitTemplates.FirstOrDefault(t => t.UnitType == unitType); if (unitTemplate == null) { throw new NullReferenceException("BuildFighter: unitTemplate not found!"); } Unit unit = new Unit() { UnitTemplateId = unitTemplate.Id, PlayerId = playerId, Location = cell, Armor = unitTemplate.Armor, Damage = unitTemplate.Damage, Shield = unitTemplate.Shield, Range = unitTemplate.Range, Speed = unitTemplate.Speed, Health = unitTemplate.Health, FuelConsumption = unitTemplate.FuelConsumption }; context.Units.Add(unit); context.SaveChanges(); } }
public static void BuildFactory(IStarWars3DB context, FactoryType factoryType, int playerId, CellDTO location) { FactoryTemplate factoryTemplate = context.FactoryTemplates.FirstOrDefault(t => t.FactoryType == factoryType); if (factoryTemplate == null) { throw new NullReferenceException("BuildFactory: Factory type not found!"); } Factory factory = new Factory() { FactoryTemplateId = factoryTemplate.Id, Level = factoryTemplate.Level, PlayerId = playerId, Health = factoryTemplate.Health, Shield = factoryTemplate.Shield, Location = new Cell { row = location.row, col = location.col } }; context.Factories.Add(factory); context.SaveChanges(); }
public static Cell DTOtoCell(CellDTO cellDTO) { int[] coordinates = new int[] { cellDTO.PositionX, cellDTO.PositionY }; return(new Cell(coordinates, cellDTO.IsAlive)); }
public void IsUpdatingSelectedCell() { var options = new DbContextOptionsBuilder <AppDbContext>() .UseInMemoryDatabase(databaseName: "Add_writes_to_Update_Cell_database") .Options; var appDbContext = new AppDbContext(options); var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, "abcd"), })); appDbContext.UserPermissions.Add(new UserPermission { Id = 1, UserName = "******", IdPrison = 1, Prison = new Prison { Id = 1, PrisonName = "prison_test" } }); appDbContext.SaveChanges(); var loggerRepository = new LoggerRepository(appDbContext); var loggerService = new LoggerService(loggerRepository); var cellRepository = new CellRepository(appDbContext); var cellService = new CellService(cellRepository); var cellController = new PCellsController( cellService, _mapper, loggerService) { ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = user } } }; appDbContext.CellTypes.Add(new CellType { Id = 1, CellName = "abcd" }); cellController.AddCell(new CellDTO { Beds = 1, IdCellType = 1, }); var cellToUpdate = new CellDTO { Beds = 5, IdCellType = 1 }; Assert.AreEqual(appDbContext.Cells.Count(), 1); cellController.UpdateCell(1, cellToUpdate); Assert.AreEqual(appDbContext.Cells.Count(), 1, "Cell has not deleted or added, instead of updating"); Assert.AreEqual(appDbContext.Cells.FirstOrDefault(x => x.Id == 1).Beds, 5, "The cell updated wrong value"); }