public async Task <int> AddPlayerPosition(PlayerPositionDto ppDto) { DBContext.PlayerPositions.Add(ppDto); await DBContext.SaveChangesAsync(); return(ppDto.id); }
public async Task <bool> UpdatePlayerPosition(PlayerPositionDto playerPositionDto) { //Map to the DB object var newRec = Mapper.Map <Position>(playerPositionDto); //Update the database return(await _db.UpdateAsync(newRec)); }
public async Task <int> CreatePlayerPosition(PlayerPositionDto playerPositionDto) { //Map to the Data Entity object var recDb = Mapper.Map <Position>(playerPositionDto); //Insert into Message table await _db.InsertAsync(recDb); return(recDb.Id); }
public async void CreatePlayerPosition() { var position = new PlayerPositionDto() { Abbreviation = "FWD", Name = "Forward", SportId = 1 }; var result = await _service.CreatePlayerPosition(position); Assert.NotEqual(0, result); }
public async void UpdatePosition() { var position = new PlayerPositionDto() { Abbreviation = "FWD", Name = "ForwardUPDATED", SportId = 1, Id = 1 }; var result = await _service.UpdatePlayerPosition(position); Assert.Equal(true, result); }
public async Task <IActionResult> CreatePlayerPosition([FromBody, Required] PlayerPositionDto playerPositionDto) { try { if (playerPositionDto == null) { return(BadRequest()); } var result = await _service.CreatePlayerPosition(playerPositionDto); return(CreatedAtRoute("default", result)); } catch (Exception ex) { Log.Error(ex, ex.Message); return(BadRequest(ex.Message)); } }
public async Task <IActionResult> UpdatePlayerPosition([FromBody, Required] PlayerPositionDto playerPositionDto) { try { if (playerPositionDto == null) { return(BadRequest()); } if (await _service.UpdatePlayerPosition(playerPositionDto)) { return(CreatedAtRoute("default", true)); } return(BadRequest("Failed to update the database")); } catch (Exception ex) { Log.Error(ex, ex.Message); return(BadRequest(ex.Message)); } }
public static PlayerPosition ToEntity(this PlayerPositionDto playerPositionDto) { return(playerPositionDto == null ? null : Mapper.Map <PlayerPosition>(playerPositionDto)); }
public async Task CreateService() { var options = new DbContextOptionsBuilder <LineupDbContext>() .UseInMemoryDatabase(databaseName: "LineupTestDb") .EnableSensitiveDataLogging() .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking) .Options; var dbContext = new LineupDbContext(options); if (await dbContext.Formations.CountAsync() <= 0) { //FORMATION 1 FormationDto formation1 = new FormationDto() { id = 1, Name = "Test-1", TeamId = 1 }; dbContext.Formations.Add(formation1); for (int i = 1; i < 11; i++) { PlayerPositionDto pp = new PlayerPositionDto() { FormationId = formation1.id, PlayerId = i, id = i, position = (Position)i }; dbContext.PlayerPositions.Add(pp); } //FORMATION 2 FormationDto formation2 = new FormationDto() { id = 2, Name = "Test-2", TeamId = 1 }; dbContext.Formations.Add(formation2); for (int i = 1; i < 11; i++) { PlayerPositionDto pp = new PlayerPositionDto() { FormationId = formation2.id, PlayerId = i, id = i + 11, position = (Position)i }; dbContext.PlayerPositions.Add(pp); } //FORMATION 3 FormationDto formation3 = new FormationDto() { id = 3, Name = "Test-3", TeamId = 1 }; dbContext.Formations.Add(formation3); for (int i = 1; i < 11; i++) { PlayerPositionDto pp = new PlayerPositionDto() { FormationId = formation3.id, PlayerId = i, id = i + 22, position = (Position)i }; dbContext.PlayerPositions.Add(pp); } await dbContext.SaveChangesAsync(); } var formationRepository = new FormationRepository(dbContext); _formationService = new FormationService(formationRepository); }
public async Task EditPlayerPosition(PlayerPositionDto ppDto) { DBContext.PlayerPositions.Update(ppDto); await DBContext.SaveChangesAsync(); }
public async Task <PlayerPosition> GetPlayerPosition(int playerPositionId) { PlayerPositionDto ppDto = await _formationRepository.GetPlayerPosition(playerPositionId); return(ppDto.ToEntity()); }