Beispiel #1
0
        public async Task <IActionResult> DeleteDepartment(int key)
        {
            try
            {
                await _webApiService.DeleteAsync <Department>(key);

                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(e));
            }
        }
Beispiel #2
0
        public async Task <IActionResult> Delete(int id)
        {
            try
            {
                await _webApiService.DeleteAsync <Seller>(id);

                return(RedirectToAction(nameof(Index)));
            }
            catch (IntegrityException e)
            {
                return(RedirectToAction(nameof(Error), new { message = e.Message }));
            }
        }
        public async void Test_if_a_team_can_be_added_to_a_player()
        {
            Player player1 = new Player() {Name = "TestPlayer1"};
            Player player2 = new Player() {Name = "Testplayer2"};
            WebApiService apiService = new WebApiService();
            await playerController.Create(player1);
            await playerController.Create(player2);
            var players = await apiService.GetAsync<List<Player>>("api/player/");
            var player1WithOutTeam = players.FirstOrDefault(a => a.Name == player1.Name);
            var player2WithOutTeam = players.FirstOrDefault(a => a.Name == player2.Name);
            List<Player> testList1 = new List<Player>() { player1WithOutTeam };
            List<Player> testList2 = new List<Player>() { player2WithOutTeam };
            Team teamOne = new Team() { Name = "TestTeam1", Draw = 0, Loss = 0, Win = 0, Players = testList1 };
            Team teamTwo = new Team() { Name = "TestTeam2", Draw = 0, Loss = 0, Win = 0, Players = testList2 };
            await apiService.PostAsync("api/team/", teamOne);
            await apiService.PostAsync("api/team/", teamTwo);
            var playerlist = await apiService.GetAsync<List<Player>>("api/player/");
            var createdePlayer1 = playerlist.FirstOrDefault(a => a.Name == player1.Name);
            var createdePlayer2 = playerlist.FirstOrDefault(a => a.Name == player2.Name);

            Assert.IsNotNull(createdePlayer1);
            Assert.IsNotNull(createdePlayer2);
            int teamSizeBefore = createdePlayer1.Teams.Count;
            int teamId1ToRemove = createdePlayer1.Teams[0].Id;
            int teamId2ToRemove = createdePlayer2.Teams[0].Id;
            Team teamToAdd = await apiService.GetAsync<Team>("api/team/" + createdePlayer2.Teams[0].Id);

            await playerController.Add(teamToAdd.Id, createdePlayer1.Id);
            Player playerAfter = await apiService.GetAsync<Player>("api/player/" + createdePlayer1.Id);
            int teamSizeAfter = playerAfter.Teams.Count;
            Assert.AreNotEqual(teamSizeAfter, teamSizeBefore);
            await apiService.DeleteAsync<Team>("api/team/" + teamId1ToRemove);
            await apiService.DeleteAsync<Team>("api/team/" + teamId2ToRemove);
            await playerController.DeleteConfirmed(createdePlayer1.Id);
            await playerController.DeleteConfirmed(createdePlayer2.Id);
        }
 public async void Test_if_a_team_can_be_removed_from_a_player()
 {
     WebApiService apiService = new WebApiService();
     await playerController.Create(player);
     var players = await apiService.GetAsync<List<Player>>("api/player/");
     var playerWithOutTeam = players.FirstOrDefault(a => a.Name == player.Name);
     List<Player> testList = new List<Player>() { playerWithOutTeam };
     Team team = new Team() { Name = "TestTeam", Draw = 0, Loss = 0, Win = 0, Players = testList };
     await apiService.PostAsync("api/team/", team);
     Assert.IsNotNull(player);
     Assert.IsNotNull(players);
     var playerlist = await apiService.GetAsync<List<Player>>("api/player/");
     var createdePlayer = playerlist.FirstOrDefault(a => a.Name == player.Name);
     Assert.IsNotNull(createdePlayer);
     int teamSizeBefore = createdePlayer.Teams.Count;
     int teamIdToRemove = createdePlayer.Teams[0].Id;
     await playerController.Remove(createdePlayer.Teams[0].Id, createdePlayer.Id);
     Player playerAfter = await apiService.GetAsync<Player>("api/player/" + createdePlayer.Id);
     int teamSizeAfter = playerAfter.Teams.Count;
     Assert.AreNotEqual(teamSizeAfter, teamSizeBefore);
     await apiService.DeleteAsync<Team>("api/team/" + teamIdToRemove);
     await playerController.DeleteConfirmed(createdePlayer.Id);
 }