private void Save_Click(object sender, RoutedEventArgs e) { bool validated; string teamName; string managerName; string phoneName; string emailName; string filepath; string path; Team teamToSave; PlayerInTeam plInTeam; Dictionary<string, string> teamDict; Dictionary<string, string> plDict; Dictionary<string, string> plInTeamDict; teamName = team.Text; managerName = manager.Text; phoneName = phone.Text; emailName = email.Text; path = imageUrl.Text; validated = ValidateTeam(teamName, managerName, emailName, league, phoneName, imageUrl.Text); if (validated) { baseDirectoryPath = AppDomain.CurrentDomain.BaseDirectory; baseDirectoryToCombine = baseDirectoryPath.Remove(baseDirectoryPath.Length - 21, 21); string guidToDB = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(openFileDlg.FileName); filepath = baseDirectoryToCombine + "VolleyballMvc\\Content\\Images\\" + guidToDB; File.Copy(Path.GetFullPath(path), filepath); teamToSave = new Team(league, teamName, managerName, phoneName, emailName, guidToDB); teamDict = teamToSave.ConvertInstanceToDictionary(); client.Insert(teamDict, Middleware.VolleyballService.TablesNames.Teams); foreach (var player in playersList) { plInTeam = new PlayerInTeam(teamToSave, player, DateTime.Now.Year); plDict = player.ConvertInstanceToDictionary(); plInTeamDict = plInTeam.ConvertInstanceToDictionary(); client.Insert(plDict, Middleware.VolleyballService.TablesNames.Players); client.Insert(plInTeamDict, Middleware.VolleyballService.TablesNames.PlayerInTeams); } this.Visibility = Visibility.Hidden; } }
private void SaveButton_Click(object sender, RoutedEventArgs e) { bool succededHeightParse; bool succededNumberParse; string path; bool isCaptain; string name; string playerAmplua; int number; bool validated; string stringNumber; int selectedTeamIndex; bool isDuplicated; string filepath; int age; int height; Player player; path = imagePath.Text; name = playerName.Text.Trim().ToUpper(); playerAmplua = amplua.Text; stringNumber = playerNumber.Text.Trim(); isCaptain = captainSign.IsChecked.Value; selectedTeamIndex = teamsCombobox.SelectedIndex; succededHeightParse = Int32.TryParse(playerHeight.Text, out height); succededNumberParse = Int32.TryParse(stringNumber, out number); validated = ValidatePlayer(name, stringNumber, playerAmplua, league, path, playerHeight.Text, playerAge.SelectedValue); if (validated) { age = (int)playerAge.SelectedValue; Int32.TryParse(playerHeight.Text, out height); Int32.TryParse(stringNumber, out number); if (team == null) { isDuplicated = client.IsIdentifiedDuplicate(number, listOfTeams[selectedTeamIndex].Id, isCaptain); } else { if (isCaptain) { isDuplicated = playersList.Any(pl => pl.Number == number || pl.Captain == true); } else { isDuplicated = playersList.Any(pl => pl.Number == number); } } if (!isDuplicated) { try { baseDirectoryPath = AppDomain.CurrentDomain.BaseDirectory; baseDirectoryToCombine = baseDirectoryPath.Remove(baseDirectoryPath.Length - 21, 21); string guidToDB = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(openFileDlg.FileName); filepath = baseDirectoryToCombine + "VolleyballMvc\\Content\\Images\\" + guidToDB; File.Copy(System.IO.Path.GetFullPath(path), filepath); player = new Player(name, number, playerAmplua, isCaptain, league, guidToDB, age, height); if (team == null) { var plInTeam = new PlayerInTeam(listOfTeams[teamsCombobox.SelectedIndex], player, DateTime.Now.Year); var playerDict = player.ConvertInstanceToDictionary(); var plInTeamDict = plInTeam.ConvertInstanceToDictionary(); client.Insert(playerDict, Middleware.VolleyballService.TablesNames.Players); client.Insert(plInTeamDict, Middleware.VolleyballService.TablesNames.PlayerInTeams); } else { playersList.Add(player); } } catch (Exception exp) { MessageBox.Show("Unable to save file " + exp.Message); } ClearInputInfo(); this.Visibility = Visibility.Hidden; } else { MessageBox.Show("Please check inserted information."); } } }