示例#1
0
        //FUNCTIONS
        private void IniForm()
        {
            new Thread(() =>
            {
                UtilsNotification.StartLoadingAnimation();

                //Load competitions
                var competitionList = competitionService.GetCompetitions();

                ObservableCollection <CompetitionComboModel> compsBox = new ObservableCollection <CompetitionComboModel>();
                compsBox.Add(new CompetitionComboModel()
                {
                    CompetitionId   = 0,
                    CompetitionName = "Selecionar competição"
                });

                foreach (var item in competitionList)
                {
                    compsBox.Add(new CompetitionComboModel()
                    {
                        CompetitionId   = item.CompetitionId,
                        CompetitionName = item.Name + " - " + competitionService.GetCompetitionSeasonName(item.CompetitionId)
                    });
                }

                ComboBoxCompetition.Dispatcher.BeginInvoke((Action)(() => ComboBoxCompetition.ItemsSource = compsBox));
                ComboBoxCompetition.Dispatcher.BeginInvoke((Action)(() => ComboBoxCompetition.SelectedValue = compsBox.FirstOrDefault()));

                comboBoxCompetionId = 0;
                numericBoxFixtureId = 0;
                ButtonLoadForm.Dispatcher.BeginInvoke((Action)(() => ButtonLoadForm.Visibility = Visibility.Hidden));

                UtilsNotification.StopLoadingAnimation();
            }).Start();
        }
        private void ButtonRemoveTeam_Click(object sender, RoutedEventArgs e)
        {
            TeamDataModel item = (sender as Button).DataContext as TeamDataModel;

            if (item != null)
            {
                ConfirmationWindow _popupConfirm = new ConfirmationWindow("Tens a certeza que pretendes remover a equipa '" + item.TeamName + "'?");
                if (_popupConfirm.ShowDialog() == true)
                {
                    new Thread(() =>
                    {
                        UtilsNotification.StartLoadingAnimation();

                        if (teamService.CanDeleteById(item.TeamId))
                        {
                            if (teamService.RemoveTeam(item.TeamId))
                            {
                                NotificationHelper.notifier.ShowCustomMessage("Equipa removida com sucesso!");
                                LoadTeamsGrid();
                            }
                            else
                            {
                                NotificationHelper.notifier.ShowCustomMessage("Erro ao remover equipa!");
                            }
                        }
                        else
                        {
                            NotificationHelper.notifier.ShowCustomMessage("Não é possivel eliminar esta equipa!\nContacte o Admin do sistema...");
                        }

                        UtilsNotification.StopLoadingAnimation();
                    }).Start();
                }
            }
        }
        private void LoadSeasonsGrid()
        {
            new Thread(() =>
            {
                UtilsNotification.StartLoadingAnimation();

                //Get seasons
                var seasonList = seasonService.GetSeasons();

                DataGridSeasons.Dispatcher.BeginInvoke((Action)(() => DataGridSeasons.ItemsSource = null));
                ObservableCollection <SeasonDataModel> seasonItems = new ObservableCollection <SeasonDataModel>();

                if (seasonList != null && seasonList.Count() > 0)
                {
                    foreach (var item in seasonList)
                    {
                        seasonItems.Add(new SeasonDataModel()
                        {
                            SeasonId   = item.SeasonId,
                            SeasonName = item.Name,
                            StartYear  = item.StartYear,
                            EndYear    = item.EndYear,
                            CreateDate = Utils.FormatDateTimeToGrid(item.CreateDate)
                        });
                    }

                    //BINDING
                    DataGridSeasons.Dispatcher.BeginInvoke((Action)(() => DataGridSeasons.ItemsSource = seasonItems));
                }

                UtilsNotification.StopLoadingAnimation();
            }).Start();
        }
        private void LoadFormTimeGoals()
        {
            new Thread(() =>
            {
                UtilsNotification.StartLoadingAnimation();

                //Load competition data
                var competitionList = competitionService.GetCompetitions();

                ObservableCollection <CompetitionComboModel> compsBox = new ObservableCollection <CompetitionComboModel>();
                compsBox.Add(new CompetitionComboModel()
                {
                    CompetitionId   = 0,
                    CompetitionName = "Selecionar competição"
                });

                foreach (var item in competitionList)
                {
                    compsBox.Add(new CompetitionComboModel()
                    {
                        CompetitionId   = item.CompetitionId,
                        CompetitionName = item.Name + " - " + competitionService.GetCompetitionSeasonName(item.CompetitionId)
                    });
                }

                ComboBoxFilterCompetition.Dispatcher.BeginInvoke((Action)(() => ComboBoxFilterCompetition.ItemsSource = compsBox));
                ComboBoxFilterCompetition.Dispatcher.BeginInvoke((Action)(() => ComboBoxFilterCompetition.SelectedValue = compsBox.FirstOrDefault()));

                ImageLogo.Dispatcher.BeginInvoke((Action)(() => ImageLogo.Visibility = Visibility.Visible));
                LabelInfo.Dispatcher.BeginInvoke((Action)(() => LabelInfo.Visibility = Visibility.Visible));
                LabelExtraInfo.Dispatcher.BeginInvoke((Action)(() => LabelExtraInfo.Visibility = Visibility.Visible));

                UtilsNotification.StopLoadingAnimation();
            }).Start();
        }
        public UserControl_HomeAwayTeams(UserControl_MainContent mainContent)
        {
            InitializeComponent();
            new Thread(() =>
            {
                UtilsNotification.StartLoadingAnimation();

                _mainContent       = mainContent;
                IsDrawableMenuOpen = false;

                IsMatchType = false;
                IsHomeTeam  = true;
                matchPeriod = MatchPeriodTypeValues.FullTime;
                ImageLogo.Dispatcher.BeginInvoke((Action)(() => ImageLogo.Visibility = Visibility.Visible));
                LabelInfo.Dispatcher.BeginInvoke((Action)(() => LabelInfo.Visibility = Visibility.Visible));
                LabelExtraInfo.Dispatcher.BeginInvoke((Action)(() => LabelExtraInfo.Visibility = Visibility.Visible));

                teamService  = new TeamService();
                matchService = new MatchService();

                DrawableMenuContainer.Dispatcher.BeginInvoke((Action)(() =>
                                                                      DrawableMenuContainer.Content = new UserControl_DrawableMenuTeams(_mainContent, this)));

                UtilsNotification.StopLoadingAnimation();
            }).Start();
        }
        private void ButtonFilterTeams_Click(object sender, RoutedEventArgs e)
        {
            //prepare data
            int?compId = ((CompetitionComboModel)ComboBoxFilterCompetition.SelectedValue).CompetitionId != 0 ?
                         (int?)((CompetitionComboModel)ComboBoxFilterCompetition.SelectedValue).CompetitionId : null;

            bool?isFav = CheckBoxFilterIsFavoriteYes.IsChecked;

            if (!CheckBoxFilterIsFavoriteYes.IsChecked.Value && !CheckBoxFilterIsFavoriteNo.IsChecked.Value)
            {
                isFav = null;
            }

            new Thread(() =>
            {
                UtilsNotification.StartLoadingAnimation();

                string txtFilter = String.Empty;
                TextBoxFilterValue.Dispatcher.Invoke((Action)(() => { txtFilter = TextBoxFilterValue.Text; }));

                //Get competitions
                var dados = teamService.GetFilteredTeams(txtFilter, compId, isFav);

                if (dados != null)
                {
                    LoadConfigurationForPagination(dados.Item2);

                    var teamList = dados.Item1.OrderBy(x => x.Name).Skip((pagNumber - 1) * IPP).Take(IPP);

                    DataGridTeams.Dispatcher.BeginInvoke((Action)(() => DataGridTeams.ItemsSource = null));
                    ObservableCollection <TeamDataModel> teamItems = new ObservableCollection <TeamDataModel>();

                    if (teamList != null && teamList.Count() > 0)
                    {
                        foreach (var item in teamList)
                        {
                            teamItems.Add(new TeamDataModel()
                            {
                                TeamId          = item.TeamId,
                                TeamName        = item.Name,
                                CompetitionName = competitionService.GetCompetitionName(item.CompetitionId),
                                SeasonName      = competitionService.GetCompetitionSeasonName(item.CompetitionId),
                                FavStarPath     = item.IsFavorite ? "pack://application:,,/Resources/ImageFiles/unnamed_star.png" :
                                                  "pack://application:,,/Resources/ImageFiles/black_tilde_arrow.png",
                                CreateDate = Utils.FormatDateTimeToGrid(item.CreateDate)
                            });
                        }

                        //BINDING
                        DataGridTeams.Dispatcher.BeginInvoke((Action)(() => DataGridTeams.ItemsSource = teamItems));
                    }

                    //PAGINATION TEXT
                    ShowPaginationText();

                    UtilsNotification.StopLoadingAnimation();
                }
            }).Start();
        }
        private void LoadFormTeams()
        {
            new Thread(() =>
            {
                UtilsNotification.StartLoadingAnimation();

                //Get competitions
                var teamList = teamService.GetTeams().OrderBy(x => x.Name).Skip((pagNumber - 1) * IPP).Take(IPP);

                DataGridTeams.Dispatcher.BeginInvoke((Action)(() => DataGridTeams.ItemsSource = null));
                ObservableCollection <TeamDataModel> teamItems = new ObservableCollection <TeamDataModel>();

                if (teamList != null && teamList.Count() > 0)
                {
                    foreach (var item in teamList)
                    {
                        teamItems.Add(new TeamDataModel()
                        {
                            TeamId          = item.TeamId,
                            TeamName        = item.Name,
                            CompetitionName = competitionService.GetCompetitionName(item.CompetitionId),
                            SeasonName      = competitionService.GetCompetitionSeasonName(item.CompetitionId),
                            FavStarPath     = item.IsFavorite? "pack://application:,,/Resources/ImageFiles/unnamed_star.png" :
                                              "pack://application:,,/Resources/ImageFiles/black_tilde_arrow.png",
                            CreateDate = Utils.FormatDateTimeToGrid(item.CreateDate)
                        });
                    }

                    //BINDING
                    DataGridTeams.Dispatcher.BeginInvoke((Action)(() => DataGridTeams.ItemsSource = teamItems));
                }

                //PAGINATION TEXT
                ShowPaginationText();


                //Load other data
                var competitionList = competitionService.GetCompetitions();

                ObservableCollection <CompetitionComboModel> compsBox = new ObservableCollection <CompetitionComboModel>();
                foreach (var item in competitionList)
                {
                    compsBox.Add(new CompetitionComboModel()
                    {
                        CompetitionId   = item.CompetitionId,
                        CompetitionName = item.Name + " - " + competitionService.GetCompetitionSeasonName(item.CompetitionId)
                    });
                }

                ComboBoxCompetition.Dispatcher.BeginInvoke((Action)(() => ComboBoxCompetition.ItemsSource = compsBox));
                ComboBoxCompetition.Dispatcher.BeginInvoke((Action)(() => ComboBoxCompetition.SelectedValue = compsBox.FirstOrDefault()));

                //Enable Ui
                ComboBoxCompetition.Dispatcher.BeginInvoke((Action)(() => ComboBoxCompetition.IsEnabled = true));

                UtilsNotification.StopLoadingAnimation();
            }).Start();
        }
示例#8
0
        private void ButtonSaveSingleMatch_Click(object sender, RoutedEventArgs e)
        {
            if (IsUiTeamsLocked)
            {
                return;
            }

            MatchesHFModel item = (sender as Button).DataContext as MatchesHFModel;

            if (item != null)
            {
                //VALIDATIONS
                if (item.HomeTeamId == 0)
                {
                    NotificationHelper.notifier.ShowCustomMessage("No jogo nº " + item.Order.ToString() +
                                                                  " falta selecionar a equipa de casa");
                    return;
                }
                else if (item.AwayTeamId == 0)
                {
                    NotificationHelper.notifier.ShowCustomMessage("No jogo nº " + item.Order.ToString() +
                                                                  " falta selecionar a equipa de fora");
                    return;
                }

                new Thread(() =>
                {
                    UtilsNotification.StartLoadingAnimation();
                    LockAddMatchesUI();

                    //save data
                    var resultado = matchService.UpdateMatchHalfTime(item.MatchId, item.HomeGoals, item.AwayGoals);

                    if (resultado != Commons.OperationTypeValues.Error)
                    {
                        //update model
                        item.ButtonSaveVisibility = Visibility.Collapsed;
                        item.ImageDoneVisibility  = Visibility.Visible;

                        string opType = resultado == Commons.OperationTypeValues.Create ? "registada" :
                                        resultado == Commons.OperationTypeValues.Edit ? "editada" : "inalterada (erro)";
                        NotificationHelper.notifier.ShowCustomMessage("2ª parte do jogo nº " + item.Order + " foi " + opType + " com sucesso!");
                    }
                    else
                    {
                        NotificationHelper.notifier.ShowCustomMessage("Ocorreu um erro ao registar a 2ª parte do jogo nº " + item.Order);
                    }

                    UnlockAddMatchesUI();
                    UtilsNotification.StopLoadingAnimation();
                }).Start();
            }
        }
示例#9
0
        private void ButtonRemoveSingleMatch_Click(object sender, RoutedEventArgs e)
        {
            if (IsUiTeamsLocked)
            {
                return;
            }

            MatchesModel item = (sender as Button).DataContext as MatchesModel;

            if (item != null)
            {
                ConfirmationWindow _popupConfirmation = new ConfirmationWindow("Tens a certeza que pretendes remover o jogo nº "
                                                                               + item.Order.ToString());
                if (_popupConfirmation.ShowDialog() == true)
                {
                    int nRows = 0;
                    UtilsNotification.StartLoadingAnimation();

                    Thread thread = new System.Threading.Thread(() => {
                        nRows = DataGridTeams.ItemsSource.OfType <object>().Count();
                    });
                    thread.Start();
                    thread.Join();

                    new Thread(() =>
                    {
                        if (item.MatchId.HasValue)
                        {
                            if (!matchService.RemoveMatch(item.MatchId.Value))
                            {
                                NotificationHelper.notifier.ShowCustomMessage("Erro ao remover jogo nº " + item.Order.ToString() + "!");
                                UtilsNotification.StopLoadingAnimation();
                                return;
                            }
                        }

                        Application.Current.Dispatcher.BeginInvoke((Action)(() => {
                            matchItems.Remove(item);

                            for (int i = 0; i < (nRows - 1); i++)
                            {
                                matchItems[i].Order = i + 1;
                            }
                        }));

                        NotificationHelper.notifier.ShowCustomMessage("Jogo nº " + item.Order.ToString() + " removido com sucesso!");

                        UtilsNotification.StopLoadingAnimation();
                    }).Start();
                }
            }
        }
        private void LoadFormCompetitions()
        {
            new Thread(() =>
            {
                UtilsNotification.StartLoadingAnimation();

                //Get competitions
                var competitionList = competitionService.GetCompetitions();

                DataGridCompetitions.Dispatcher.BeginInvoke((Action)(() => DataGridCompetitions.ItemsSource = null));
                ObservableCollection <CompetitionDataModel> compItems = new ObservableCollection <CompetitionDataModel>();

                if (competitionList != null && competitionList.Count() > 0)
                {
                    foreach (var item in competitionList)
                    {
                        compItems.Add(new CompetitionDataModel()
                        {
                            CompetitionId   = item.CompetitionId,
                            CompetitionName = item.Name,
                            SeasonName      = seasonService.GetSeasonName(item.SeasonId),
                            CreateDate      = Utils.FormatDateTimeToGrid(item.CreateDate)
                        });
                    }

                    //BINDING
                    DataGridCompetitions.Dispatcher.BeginInvoke((Action)(() => DataGridCompetitions.ItemsSource = compItems));
                }


                //Load other data
                var seasonList = seasonService.GetSeasons();

                ObservableCollection <SeasonComboModel> seasonsBox = new ObservableCollection <SeasonComboModel>();
                foreach (var item in seasonList)
                {
                    seasonsBox.Add(new SeasonComboModel()
                    {
                        SeasonId   = item.SeasonId,
                        SeasonName = item.Name
                    });
                }

                ComboBoxSeason.Dispatcher.BeginInvoke((Action)(() => ComboBoxSeason.ItemsSource = seasonsBox));
                ComboBoxSeason.Dispatcher.BeginInvoke((Action)(() => ComboBoxSeason.SelectedValue = seasonsBox.FirstOrDefault()));

                //Enable Ui
                ComboBoxSeason.Dispatcher.BeginInvoke((Action)(() => ComboBoxSeason.IsEnabled = true));

                UtilsNotification.StopLoadingAnimation();
            }).Start();
        }
        public UserControl_AddMatches(UserControl_MainContent mainContent)
        {
            InitializeComponent();
            new Thread(() =>
            {
                UtilsNotification.StartLoadingAnimation();

                _mainContent = mainContent;

                MatchContainer.Dispatcher.BeginInvoke((Action)(() => MatchContainer.Content = new UserControl_AddMatch_StartTime(this)));
                ChangeSubTitle("(Ataque/ Defesa)");

                UtilsNotification.StopLoadingAnimation();
            }).Start();
        }
        //BUTTONS
        private void ButtonSaveTeam_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrEmpty(TextBoxTeamName.Text) || TextBoxTeamName.Text.Length < 3)
            {
                NotificationHelper.notifier.ShowCustomMessage("Nome da equipa inválido!");
                return;
            }

            if ((CompetitionComboModel)ComboBoxCompetition.SelectedValue == null)
            {
                NotificationHelper.notifier.ShowCustomMessage("Falta escolher a competição!");
                return;
            }

            if (teamService.AlreadyExistsTeam(TextBoxTeamName.Text, ((CompetitionComboModel)ComboBoxCompetition.SelectedValue).CompetitionId))
            {
                NotificationHelper.notifier.ShowCustomMessage("Já existe uma equipa idêntica!");
                return;
            }

            string teamName   = TextBoxTeamName.Text;
            int    compID     = ((CompetitionComboModel)ComboBoxCompetition.SelectedValue).CompetitionId;
            bool   checkedFav = CheckBoxIsFavorite.IsChecked.HasValue ? CheckBoxIsFavorite.IsChecked.Value : false;

            new Thread(() =>
            {
                UtilsNotification.StartLoadingAnimation();

                //Save new team
                if (teamService.CreateTeam(teamName, compID, checkedFav))
                {
                    NotificationHelper.notifier.ShowCustomMessage("Equipa criada com sucesso!");

                    //Reset UI
                    TextBoxTeamName.Dispatcher.BeginInvoke((Action)(() => TextBoxTeamName.Clear()));
                    CheckBoxIsFavorite.Dispatcher.BeginInvoke((Action)(() => CheckBoxIsFavorite.IsChecked = false));

                    LoadTeamsGrid();
                }
                else
                {
                    NotificationHelper.notifier.ShowCustomMessage("Ocorreu um erro ao criar a Equipa!");
                }

                UtilsNotification.StopLoadingAnimation();
            }).Start();
        }
        private void ButtonSaveSeason_Click(object sender, RoutedEventArgs e)
        {
            if ((int)ComboBoxStartYear.SelectedValue > (int)ComboBoxEndYear.SelectedValue)
            {
                NotificationHelper.notifier.ShowCustomMessage("Os anos da época são inválidos!");
                return;
            }

            if ((int)ComboBoxStartYear.SelectedValue == (int)ComboBoxEndYear.SelectedValue)
            {
                NotificationHelper.notifier.ShowCustomMessage("Os anos da época são inválidos!");
                return;
            }

            if (seasonService.AlreadyExistsSeason((int)ComboBoxStartYear.SelectedValue, (int)ComboBoxEndYear.SelectedValue))
            {
                NotificationHelper.notifier.ShowCustomMessage("Época já criada!");
                return;
            }

            int sYear = (int)ComboBoxStartYear.SelectedValue;
            int eYear = (int)ComboBoxEndYear.SelectedValue;

            new Thread(() =>
            {
                UtilsNotification.StartLoadingAnimation();

                //Save new season
                if (seasonService.CreateSeason(sYear, eYear))
                {
                    NotificationHelper.notifier.ShowCustomMessage("Época criada com sucesso!");

                    //Reset UI
                    ComboBoxStartYear.Dispatcher.BeginInvoke((Action)(() => ComboBoxStartYear.SelectedValue = DateTime.Now.Year));
                    ComboBoxEndYear.Dispatcher.BeginInvoke((Action)(() => ComboBoxEndYear.SelectedValue = DateTime.Now.Year));

                    LoadSeasonsGrid();
                }
                else
                {
                    NotificationHelper.notifier.ShowCustomMessage("Ocorreu um erro ao  criar a Época!");
                }

                UtilsNotification.StopLoadingAnimation();
            }).Start();
        }
        public UserControl_Seasons(UserControl_MainContent mainContent)
        {
            InitializeComponent();

            new Thread(() =>
            {
                UtilsNotification.StartLoadingAnimation();

                ComboBoxStartYear.Dispatcher.BeginInvoke((Action)(() => ComboBoxStartYear.IsEnabled = false));
                ComboBoxEndYear.Dispatcher.BeginInvoke((Action)(() => ComboBoxEndYear.IsEnabled = false));
                ButtonSaveSeason.Dispatcher.BeginInvoke((Action)(() => ButtonSaveSeason.IsEnabled = false));
                _mainContent = mainContent;

                seasonService = new SeasonService();
                LoadFormData();
            }).Start();
        }
        public UserControl_Competitions(UserControl_MainContent mainContent)
        {
            InitializeComponent();
            new Thread(() =>
            {
                UtilsNotification.StartLoadingAnimation();

                _mainContent = mainContent;

                ComboBoxSeason.Dispatcher.BeginInvoke((Action)(() => ComboBoxSeason.IsEnabled = false));

                competitionService = new CompetitionService();
                seasonService      = new SeasonService();

                LoadFormCompetitions();
            }).Start();
        }
        private void ButtonSaveCompetition_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrEmpty(TextBoxCompetitionName.Text) || TextBoxCompetitionName.Text.Length < 3)
            {
                NotificationHelper.notifier.ShowCustomMessage("Nome da competição inválido!");
                return;
            }

            if ((SeasonComboModel)ComboBoxSeason.SelectedValue == null)
            {
                NotificationHelper.notifier.ShowCustomMessage("Falta escolher a época!");
                return;
            }

            if (competitionService.AlreadyExistsCompetition(TextBoxCompetitionName.Text, ((SeasonComboModel)ComboBoxSeason.SelectedValue).SeasonId))
            {
                NotificationHelper.notifier.ShowCustomMessage("Já existe uma competição idêntica!");
                return;
            }

            string compName = TextBoxCompetitionName.Text;
            int    seasonID = ((SeasonComboModel)ComboBoxSeason.SelectedValue).SeasonId;

            new Thread(() =>
            {
                UtilsNotification.StartLoadingAnimation();

                //Save new competition
                if (competitionService.CreateCompetition(compName, seasonID))
                {
                    NotificationHelper.notifier.ShowCustomMessage("Competição criada com sucesso!");

                    //Reset UI
                    TextBoxCompetitionName.Dispatcher.BeginInvoke((Action)(() => TextBoxCompetitionName.Clear()));

                    LoadCompetitionsGrid();
                }
                else
                {
                    NotificationHelper.notifier.ShowCustomMessage("Ocorreu um erro ao criar a Competição!");
                }

                UtilsNotification.StopLoadingAnimation();
            }).Start();
        }
        public UserControl_Teams(UserControl_MainContent mainContent)
        {
            InitializeComponent();
            new Thread(() =>
            {
                UtilsNotification.StartLoadingAnimation();

                ComboBoxCompetition.Dispatcher.BeginInvoke((Action)(() => ComboBoxCompetition.IsEnabled = false));
                _mainContent = mainContent;

                teamService        = new TeamService();
                competitionService = new CompetitionService();

                LoadConfigurationForPagination();
                LoadFormTeams();
                IniSearchControls();
            }).Start();
        }
        private void ReCalculateDataFromDataGrid()
        {
            new Thread(() =>
            {
                UtilsNotification.StartLoadingAnimation();

                if (matchItems != null)
                {
                    bool flagShowForSave = false;
                    foreach (var timeGoal in matchItems)
                    {
                        timeGoal.TotalGoals = timeGoal.Goal15 + timeGoal.Goal30 + timeGoal.Goal45 + timeGoal.Goal60 +
                                              timeGoal.Goal75 + timeGoal.Goal90;
                        timeGoal.Goal15P = timeGoalsService.GetPercentageOfTimeGoalByValue(timeGoal.Goal15, timeGoal.TotalGoals);
                        timeGoal.Goal30P = timeGoalsService.GetPercentageOfTimeGoalByValue(timeGoal.Goal30, timeGoal.TotalGoals);
                        timeGoal.Goal45P = timeGoalsService.GetPercentageOfTimeGoalByValue(timeGoal.Goal45, timeGoal.TotalGoals);
                        timeGoal.Goal60P = timeGoalsService.GetPercentageOfTimeGoalByValue(timeGoal.Goal60, timeGoal.TotalGoals);
                        timeGoal.Goal75P = timeGoalsService.GetPercentageOfTimeGoalByValue(timeGoal.Goal75, timeGoal.TotalGoals);
                        timeGoal.Goal90P = timeGoalsService.GetPercentageOfTimeGoalByValue(timeGoal.Goal90, timeGoal.TotalGoals);

                        var itemInitialState = matchItemsInitialState[matchItems.IndexOf(timeGoal)];
                        if (itemInitialState != null)
                        {
                            if (itemInitialState.Goal15 != timeGoal.Goal15 || itemInitialState.Goal30 != timeGoal.Goal30 || itemInitialState.Goal45 != timeGoal.Goal45 ||
                                itemInitialState.Goal60 != timeGoal.Goal60 || itemInitialState.Goal75 != timeGoal.Goal75 || itemInitialState.Goal90 != timeGoal.Goal90)
                            {
                                flagShowForSave = true;
                            }
                        }
                    }

                    if (flagShowForSave)
                    {
                        LabelInfoForSave.Dispatcher.BeginInvoke((Action)(() => LabelInfoForSave.Visibility = Visibility.Visible));
                    }
                    else
                    {
                        LabelInfoForSave.Dispatcher.BeginInvoke((Action)(() => LabelInfoForSave.Visibility = Visibility.Collapsed));
                    }
                }

                UtilsNotification.StopLoadingAnimation();
            }).Start();
        }
        private void ButtonFav_MouseDown(object sender, MouseButtonEventArgs e)
        {
            TeamDataModel item = (sender as Image).DataContext as TeamDataModel;

            if (item != null)
            {
                string msg     = "";
                bool   flagFav = true;

                if (item.FavStarPath.Contains("unnamed_star"))
                {
                    msg     = "Tens a certeza que pretendes remover a equipa " + item.TeamName + " dos favoritos?";
                    flagFav = false;
                }
                else
                {
                    msg     = "Tens a certeza que pretendes adicionar a equipa " + item.TeamName + " aos favoritos?";
                    flagFav = true;
                }

                ConfirmationWindow _popupConfirm = new ConfirmationWindow(msg);
                if (_popupConfirm.ShowDialog() == true)
                {
                    new Thread(() =>
                    {
                        UtilsNotification.StartLoadingAnimation();

                        if (teamService.ChangeFavoriteValue(item.TeamId, flagFav))
                        {
                            NotificationHelper.notifier.ShowCustomMessage("Favoritismo do clube alterado com sucesso!");
                            LoadTeamsGrid();
                        }
                        else
                        {
                            NotificationHelper.notifier.ShowCustomMessage("Erro ao mudar o favoritismo do clube/nContacte o Admin do sistema...");
                        }

                        UtilsNotification.StopLoadingAnimation();
                    }).Start();
                }
            }
        }
        private void LoadTeamsGrid()
        {
            new Thread(() =>
            {
                UtilsNotification.StartLoadingAnimation();

                LoadConfigurationForPagination();

                //Get competitions
                var teamList = teamService.GetTeams().OrderBy(x => x.Name).Skip((pagNumber - 1) * IPP).Take(IPP);

                DataGridTeams.Dispatcher.BeginInvoke((Action)(() => DataGridTeams.ItemsSource = null));
                ObservableCollection <TeamDataModel> teamItems = new ObservableCollection <TeamDataModel>();

                if (teamList != null && teamList.Count() > 0)
                {
                    foreach (var item in teamList)
                    {
                        teamItems.Add(new TeamDataModel()
                        {
                            TeamId          = item.TeamId,
                            TeamName        = item.Name,
                            CompetitionName = competitionService.GetCompetitionName(item.CompetitionId),
                            SeasonName      = competitionService.GetCompetitionSeasonName(item.CompetitionId),
                            FavStarPath     = item.IsFavorite ? "pack://application:,,/Resources/ImageFiles/unnamed_star.png" :
                                              "pack://application:,,/Resources/ImageFiles/black_tilde_arrow.png",
                            CreateDate = Utils.FormatDateTimeToGrid(item.CreateDate)
                        });
                    }

                    //BINDING
                    DataGridTeams.Dispatcher.BeginInvoke((Action)(() => DataGridTeams.ItemsSource = teamItems));
                }

                //PAGINATION TEXT
                ShowPaginationText();

                UtilsNotification.StopLoadingAnimation();
            }).Start();
        }
        private void LoadModelListWithCompetitionTeams(int competitionId)
        {
            UtilsNotification.StartLoadingAnimation();

            var compTeams = teamService.GetCompetitionTeams(competitionId);

            if (compTeams != null && compTeams != null? compTeams.Count() > 0 : false)
            {
                matchItems = new ObservableCollection <TimeGoalsModel>();
                DataGridTimeGoals.Dispatcher.BeginInvoke((Action)(() => DataGridTimeGoals.ItemsSource = null));

                LoadTimeGoalsFromCompetitionTeams(competitionId, compTeams, matchItems);

                DataGridTimeGoals.Dispatcher.BeginInvoke((Action)(() => DataGridTimeGoals.ItemsSource = matchItems));

                ImageLogo.Dispatcher.BeginInvoke((Action)(() => ImageLogo.Visibility = Visibility.Collapsed));
                LabelInfo.Dispatcher.BeginInvoke((Action)(() => LabelInfo.Visibility = Visibility.Collapsed));
                LabelExtraInfo.Dispatcher.BeginInvoke((Action)(() => LabelExtraInfo.Visibility = Visibility.Collapsed));

                DataGridTimeGoals.Dispatcher.BeginInvoke((Action)(() => DataGridTimeGoals.CellEditEnding += DataGridTimeGoals_CellEditEnding));
                DataGridTimeGoals.Dispatcher.BeginInvoke((Action)(() => DataGridTimeGoals.Visibility = Visibility.Visible));
            }
            else
            {
                if (DataGridTimeGoals.Visibility != Visibility.Collapsed)
                {
                    DataGridTimeGoals.Dispatcher.BeginInvoke((Action)(() => DataGridTimeGoals.Visibility = Visibility.Collapsed));

                    LabelInfo.Dispatcher.BeginInvoke((Action)(() =>
                                                              LabelInfo.Content = "Para visualizar informações de golos é necessário inserir as equipas da competição primeiro"));

                    ImageLogo.Dispatcher.BeginInvoke((Action)(() => ImageLogo.Visibility = Visibility.Visible));
                    LabelInfo.Dispatcher.BeginInvoke((Action)(() => LabelInfo.Visibility = Visibility.Visible));
                    LabelExtraInfo.Dispatcher.BeginInvoke((Action)(() => LabelExtraInfo.Visibility = Visibility.Visible));
                }
            }

            UtilsNotification.StopLoadingAnimation();
        }
        private void ButtonSaveTimeGoals_Click(object sender, RoutedEventArgs e)
        {
            if (matchItems == null || matchItems != null ? matchItems.Count() < 1 : true || DataGridTimeGoals.Visibility != Visibility.Visible)
            {
                NotificationHelper.notifier.ShowCustomMessage("Dados em falta!");
                return;
            }

            //Reload - get competitionId
            if ((CompetitionComboModel)ComboBoxFilterCompetition.SelectedValue == null ||
                ((CompetitionComboModel)ComboBoxFilterCompetition.SelectedValue != null ?
                 ((CompetitionComboModel)ComboBoxFilterCompetition.SelectedValue).CompetitionId == 0 : true))
            {
                NotificationHelper.notifier.ShowCustomMessage("Falta escolher a competição!");
                return;
            }
            int auxComp = ((CompetitionComboModel)ComboBoxFilterCompetition.SelectedValue).CompetitionId;

            new Thread(() =>
            {
                UtilsNotification.StartLoadingAnimation();

                if (timeGoalsService.InsertOrUpdateTimeGoals(matchItems))
                {
                    LabelInfoForSave.Dispatcher.BeginInvoke((Action)(() => LabelInfoForSave.Visibility = Visibility.Collapsed));
                    NotificationHelper.notifier.ShowCustomMessage("Dados guardados com sucesso!");

                    //Reload list
                    LoadModelListWithCompetitionTeams(auxComp);
                }
                else
                {
                    NotificationHelper.notifier.ShowCustomMessage("Erro ao guardar os dados!");
                    UtilsNotification.StopLoadingAnimation();
                }
            }).Start();
        }
示例#23
0
        public UserControl_Begin(UserControl_MainContent mainContent)
        {
            InitializeComponent();

            new Thread(() =>
            {
                UtilsNotification.StartLoadingAnimation();

                _mainContent       = mainContent;
                seasonService      = new SeasonService();
                competitionService = new CompetitionService();
                teamService        = new TeamService();
                matchService       = new MatchService();

                Thread.Sleep(1000);

                TextBoxNSeasons.Dispatcher.BeginInvoke((Action)(() => TextBoxNSeasons.Text = seasonService.GetSeasonsNumber().ToString()));
                TextBoxNCompetitions.Dispatcher.BeginInvoke((Action)(() => TextBoxNCompetitions.Text = competitionService.GetCompetitionsNumber().ToString()));
                TextBoxNTeams.Dispatcher.BeginInvoke((Action)(() => TextBoxNTeams.Text = teamService.GetTeamsNumber().ToString()));
                TextBoxNMatches.Dispatcher.BeginInvoke((Action)(() => TextBoxNMatches.Text = matchService.GetMatchesNumber().ToString()));

                UtilsNotification.StopLoadingAnimation();
            }).Start();
        }
        public UserControl_Matches(UserControl_MainContent mainContent)
        {
            InitializeComponent();
            new Thread(() =>
            {
                UtilsNotification.StartLoadingAnimation();

                _mainContent  = mainContent;
                typeMatchView = MatchViewTypeValues.AttackDefense;

                ImageLogo.Dispatcher.BeginInvoke((Action)(() => ImageLogo.Visibility = Visibility.Visible));
                LabelInfo.Dispatcher.BeginInvoke((Action)(() => LabelInfo.Visibility = Visibility.Visible));
                LabelExtraInfo.Dispatcher.BeginInvoke((Action)(() => LabelExtraInfo.Visibility = Visibility.Visible));

                teamService  = new TeamService();
                matchService = new MatchService();

                IsDrawableMenuOpen = false;
                DrawableMenuContainer.Dispatcher.BeginInvoke((Action)(() =>
                                                                      DrawableMenuContainer.Content = new UserControl_DrawableMenuMatches(_mainContent, this)));

                UtilsNotification.StopLoadingAnimation();
            }).Start();
        }
        private void IniSearchControls()
        {
            new Thread(() =>
            {
                UtilsNotification.StartLoadingAnimation();

                TextBoxFilterValue.Dispatcher.BeginInvoke((Action)(() => TextBoxFilterValue.Clear()));

                //Load data
                var competitionList = competitionService.GetCompetitions();

                ObservableCollection <CompetitionComboModel> compsBox = new ObservableCollection <CompetitionComboModel>();
                compsBox.Add(new CompetitionComboModel()
                {
                    CompetitionId   = 0,
                    CompetitionName = ""
                });

                foreach (var item in competitionList)
                {
                    compsBox.Add(new CompetitionComboModel()
                    {
                        CompetitionId   = item.CompetitionId,
                        CompetitionName = item.Name + " - " + competitionService.GetCompetitionSeasonName(item.CompetitionId)
                    });
                }

                ComboBoxFilterCompetition.Dispatcher.BeginInvoke((Action)(() => ComboBoxFilterCompetition.ItemsSource = compsBox));
                ComboBoxFilterCompetition.Dispatcher.BeginInvoke((Action)(() => ComboBoxFilterCompetition.SelectedValue = compsBox.FirstOrDefault()));

                CheckBoxFilterIsFavoriteYes.Dispatcher.BeginInvoke((Action)(() => CheckBoxFilterIsFavoriteYes.IsChecked = false));
                CheckBoxFilterIsFavoriteNo.Dispatcher.BeginInvoke((Action)(() => CheckBoxFilterIsFavoriteNo.IsChecked = false));

                UtilsNotification.StopLoadingAnimation();
            }).Start();
        }
        private void LoadFormData()
        {
            new Thread(() =>
            {
                UtilsNotification.StartLoadingAnimation();

                //Get seasons
                var seasonList = seasonService.GetSeasons();

                DataGridSeasons.Dispatcher.BeginInvoke((Action)(() => DataGridSeasons.ItemsSource = null));
                ObservableCollection <SeasonDataModel> seasonItems = new ObservableCollection <SeasonDataModel>();

                if (seasonList != null && seasonList.Count() > 0)
                {
                    foreach (var item in seasonList)
                    {
                        seasonItems.Add(new SeasonDataModel()
                        {
                            SeasonId   = item.SeasonId,
                            SeasonName = item.Name,
                            StartYear  = item.StartYear,
                            EndYear    = item.EndYear,
                            CreateDate = Utils.FormatDateTimeToGrid(item.CreateDate)
                        });
                    }

                    //BINDING
                    DataGridSeasons.Dispatcher.BeginInvoke((Action)(() => DataGridSeasons.ItemsSource = seasonItems));
                }


                //Load other data
                ObservableCollection <int> yearsList = new ObservableCollection <int>();
                int currentYear = DateTime.Now.Year;

                //10 years before
                for (int i = currentYear - 10; i < currentYear; i++)
                {
                    yearsList.Add(i);
                }

                yearsList.Add(currentYear);

                //10 years after
                for (int i = currentYear + 1; i < currentYear + 10; i++)
                {
                    yearsList.Add(i);
                }

                ComboBoxStartYear.Dispatcher.BeginInvoke((Action)(() => ComboBoxStartYear.ItemsSource = yearsList));
                ComboBoxStartYear.Dispatcher.BeginInvoke((Action)(() => ComboBoxStartYear.SelectedValue = currentYear));
                ComboBoxEndYear.Dispatcher.BeginInvoke((Action)(() => ComboBoxEndYear.ItemsSource = yearsList));
                ComboBoxEndYear.Dispatcher.BeginInvoke((Action)(() => ComboBoxEndYear.SelectedValue = currentYear));

                //Enable Ui
                ComboBoxStartYear.Dispatcher.BeginInvoke((Action)(() => ComboBoxStartYear.IsEnabled = true));
                ComboBoxEndYear.Dispatcher.BeginInvoke((Action)(() => ComboBoxEndYear.IsEnabled = true));
                ButtonSaveSeason.Dispatcher.BeginInvoke((Action)(() => ButtonSaveSeason.IsEnabled = true));

                UtilsNotification.StopLoadingAnimation();
            }).Start();
        }
        //PUBLIC
        public void LoadGridWithCalculatedMatchesData(int?compId, List <int> teamIds)
        {
            if (!compId.HasValue || compId.Value == 0)
            {
                NotificationHelper.notifier.ShowCustomMessage("Selecione uma competição primeiro!");
                return;
            }

            //CloseMenu
            CloseDrawableMenu();

            new Thread(() =>
            {
                UtilsNotification.StartLoadingAnimation();

                //get team(s)
                List <Team> tList = new List <Team>();
                if (teamIds != null && teamIds != null? teamIds.Count() > 0 : false)
                {
                    foreach (int tId in teamIds)
                    {
                        tList.Add(new Team()
                        {
                            TeamId = tId
                        });
                    }
                }
                else
                {
                    tList = teamService.GetCompetitionTeams(compId.Value).ToList();
                }

                if (tList != null && tList.Count() > 0)
                {
                    ObservableCollection <HomeAwayTeamViewModel> matchItems = new ObservableCollection <HomeAwayTeamViewModel>();
                    DataGridTeams.Dispatcher.BeginInvoke((Action)(() => DataGridTeams.ItemsSource = null));

                    LoadObservableCollection(compId.Value, matchItems, tList);

                    DataGridTeams.Dispatcher.BeginInvoke((Action)(() => DataGridTeams.ItemsSource = matchItems));

                    ImageLogo.Dispatcher.BeginInvoke((Action)(() => ImageLogo.Visibility = Visibility.Collapsed));
                    LabelInfo.Dispatcher.BeginInvoke((Action)(() => LabelInfo.Visibility = Visibility.Collapsed));
                    LabelExtraInfo.Dispatcher.BeginInvoke((Action)(() => LabelExtraInfo.Visibility = Visibility.Collapsed));

                    DataGridTeams.Dispatcher.BeginInvoke((Action)(() => DataGridTeams.Visibility = Visibility.Visible));

                    //VISIBILITY
                    ArrangeColumnsGridVisibility();

                    //Check values and change color dynamically
                    DataGridTeams.Dispatcher.BeginInvoke((Action)(() => { CheckValuesInGrid(matchItems.Count()); }));
                }
                else
                {
                    if (DataGridTeams.Visibility != Visibility.Collapsed)
                    {
                        DataGridTeams.Dispatcher.BeginInvoke((Action)(() => DataGridTeams.Visibility = Visibility.Collapsed));

                        ImageLogo.Dispatcher.BeginInvoke((Action)(() => ImageLogo.Visibility = Visibility.Visible));
                        LabelInfo.Dispatcher.BeginInvoke((Action)(() => LabelInfo.Visibility = Visibility.Visible));
                        LabelExtraInfo.Dispatcher.BeginInvoke((Action)(() => LabelExtraInfo.Visibility = Visibility.Visible));
                    }
                }

                UtilsNotification.StopLoadingAnimation();
            }).Start();
        }
示例#28
0
        //BUTTONS
        private void ButtonLoadForm_Click(object sender, RoutedEventArgs e)
        {
            //Verificações
            if (((CompetitionComboModel)ComboBoxCompetition.SelectedItem).CompetitionId == 0)
            {
                NotificationHelper.notifier.ShowCustomMessage("Selecione uma competição!");
                return;
            }

            int auxFixture = 0;

            try{
                if (Int32.TryParse(TextBoxFixture.Text, out auxFixture))
                {
                    if (auxFixture < 1)
                    {
                        NotificationHelper.notifier.ShowCustomMessage("Selecione uma jornada!");
                        return;
                    }
                }
                else
                {
                    NotificationHelper.notifier.ShowCustomMessage("Ocorreu um erro com a jornada!");
                    return;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                NotificationHelper.notifier.ShowCustomMessage("Ocorreu um erro com a jornada!");
                return;
            }

            Visibility auxGridVisibility = DataGridTeams.Visibility;
            int        compId            = ((CompetitionComboModel)ComboBoxCompetition.SelectedItem).CompetitionId;

            comboBoxCompetionId = compId;
            numericBoxFixtureId = Convert.ToInt16(TextBoxFixture.Text);

            new Thread(() =>
            {
                UtilsNotification.StartLoadingAnimation();

                //GRID
                DataGridTeams.Dispatcher.BeginInvoke((Action)(() => DataGridTeams.ItemsSource = null));
                matchItems = new ObservableCollection <MatchesModel>();

                if (matchService.HasInitialMatchesForCompetitionFixture(comboBoxCompetionId, numericBoxFixtureId))
                {
                    //fill data grid with registered matches
                    LoadMatchesToGrid();
                }
                else
                {
                    //Logic to fill data grid (pre load)
                    LoadCompetitionDataToGrid();
                }

                if (matchItems.Count() > 0)
                {
                    if (auxGridVisibility != Visibility.Visible)
                    {
                        //HIDE INITIAL INFO
                        ImageLogo.Dispatcher.BeginInvoke((Action)(() => ImageLogo.Visibility = Visibility.Collapsed));
                        LabelInfo.Dispatcher.BeginInvoke((Action)(() => LabelInfo.Visibility = Visibility.Collapsed));
                        LabelExtraInfo.Dispatcher.BeginInvoke((Action)(() => LabelExtraInfo.Visibility = Visibility.Collapsed));
                    }

                    //BINDING
                    DataGridTeams.Dispatcher.BeginInvoke((Action)(() => DataGridTeams.ItemsSource = matchItems));

                    if (auxGridVisibility != Visibility.Visible)
                    {
                        //SHOW GRID
                        DataGridTeams.Dispatcher.BeginInvoke((Action)(() => DataGridTeams.Visibility = Visibility.Visible));
                        ButtonSaveAllMatches.Dispatcher.BeginInvoke((Action)(() => ButtonSaveAllMatches.Visibility = Visibility.Visible));
                        ButtonAddNewGame.Dispatcher.BeginInvoke((Action)(() => ButtonAddNewGame.Visibility = Visibility.Visible));
                    }

                    ButtonLoadForm.Dispatcher.BeginInvoke((Action)(() => ButtonLoadForm.Visibility = Visibility.Hidden));
                }
                else
                {
                    //HIDE GRID
                    DataGridTeams.Dispatcher.BeginInvoke((Action)(() => DataGridTeams.Visibility = Visibility.Collapsed));
                    ButtonSaveAllMatches.Dispatcher.BeginInvoke((Action)(() => ButtonSaveAllMatches.Visibility = Visibility.Hidden));
                    ButtonAddNewGame.Dispatcher.BeginInvoke((Action)(() => ButtonAddNewGame.Visibility = Visibility.Hidden));

                    //SHOW INITIAL INFO
                    ImageLogo.Dispatcher.BeginInvoke((Action)(() => ImageLogo.Visibility = Visibility.Visible));
                    LabelInfo.Dispatcher.BeginInvoke((Action)(() => LabelInfo.Visibility = Visibility.Visible));
                    LabelExtraInfo.Dispatcher.BeginInvoke((Action)(() => LabelExtraInfo.Visibility = Visibility.Visible));

                    NotificationHelper.notifier.ShowCustomMessage("Não existem equipas participantes na competição selecionada!");
                }

                UtilsNotification.StopLoadingAnimation();
            }).Start();
        }
示例#29
0
        private void ButtonSaveAllMatches_Click(object sender, RoutedEventArgs e)
        {
            //hold temp values
            int  nRows      = 0;
            int  order      = 0;
            int  teamSide   = 0;
            bool teamsValid = true;

            UtilsNotification.StartLoadingAnimation();

            //Has to be calculated this way
            Thread thread = new System.Threading.Thread(() => {
                nRows = DataGridTeams.ItemsSource.OfType <object>().Count();

                foreach (var item in DataGridTeams.ItemsSource)
                {
                    if (((MatchesModel)item).HomeTeamId == 0)
                    {
                        order      = ((MatchesModel)item).Order;
                        teamSide   = 0;
                        teamsValid = false;
                        break;
                    }
                    else if (((MatchesModel)item).AwayTeamId == 0)
                    {
                        order      = ((MatchesModel)item).Order;
                        teamSide   = 1;
                        teamsValid = false;
                        break;
                    }
                }
            });

            thread.Start();
            thread.Join();

            new Thread(() =>
            {
                if (IsMatchesListValid(nRows, teamsValid, teamSide, order))
                {
                    LockAddMatchesUI();
                    UIRestartProcess();

                    //Save
                    foreach (var item in matchItems)
                    {
                        //Load necessary data
                        item.CompetitionId = comboBoxCompetionId;
                        item.FixtureId     = numericBoxFixtureId;
                        int homeTeamIdAux  = item.HomeTeamId;
                        int awayTeamIdAux  = item.AwayTeamId;
                        item.HomeTeamId    = item.TeamsList[item.HomeTeamId].TeamId;
                        item.AwayTeamId    = item.TeamsList[item.AwayTeamId].TeamId;

                        //save data
                        var resultado = matchService.CreateOrUpdateMatch(item);

                        if (resultado != null)
                        {
                            //update model
                            item.MatchId = resultado.Item1;
                            item.ButtonSaveVisibility   = Visibility.Collapsed;
                            item.ButtonRemoveVisibility = Visibility.Collapsed;
                            item.ImageDoneVisibility    = Visibility.Visible;
                            item.HomeTeamId             = homeTeamIdAux;
                            item.AwayTeamId             = awayTeamIdAux;

                            string opType = resultado.Item2 == Commons.OperationTypeValues.Create ? "registado" :
                                            resultado.Item2 == Commons.OperationTypeValues.Edit ? "editado" : "inalterado (erro)";
                            NotificationHelper.notifier.ShowCustomMessage("O jogo nº " + item.Order + " foi " + opType + " com sucesso!");
                        }
                        else
                        {
                            NotificationHelper.notifier.ShowCustomMessage("Ocorreu um erro ao registar o jogo nº " + item.Order);
                        }

                        Thread.Sleep(300);
                    }

                    NotificationHelper.notifier.ShowCustomMessage("Operação concluída!");
                    UnlockAddMatchesUI();
                }

                UtilsNotification.StopLoadingAnimation();
            }).Start();
        }
示例#30
0
        private void ButtonSaveSingleMatch_Click(object sender, RoutedEventArgs e)
        {
            if (IsUiTeamsLocked)
            {
                return;
            }

            MatchesModel item = (sender as Button).DataContext as MatchesModel;

            if (item != null)
            {
                //VALIDATIONS
                if (item.HomeTeamId == 0)
                {
                    NotificationHelper.notifier.ShowCustomMessage("No jogo nº " + item.Order.ToString() +
                                                                  " falta selecionar a equipa de casa");
                    return;
                }
                else if (item.AwayTeamId == 0)
                {
                    NotificationHelper.notifier.ShowCustomMessage("No jogo nº " + item.Order.ToString() +
                                                                  " falta selecionar a equipa de fora");
                    return;
                }
                else if (comboBoxCompetionId < 1)
                {
                    NotificationHelper.notifier.ShowCustomMessage("A competição está em falta!");
                    return;
                }
                else if (numericBoxFixtureId < 1)
                {
                    NotificationHelper.notifier.ShowCustomMessage("A jornada está em falta!");
                    return;
                }

                //Load necessary data
                item.CompetitionId = comboBoxCompetionId;
                item.FixtureId     = numericBoxFixtureId;
                int homeTeamIdAux = item.HomeTeamId;
                int awayTeamIdAux = item.AwayTeamId;
                item.HomeTeamId = item.TeamsList[item.HomeTeamId].TeamId;
                item.AwayTeamId = item.TeamsList[item.AwayTeamId].TeamId;

                new Thread(() =>
                {
                    UtilsNotification.StartLoadingAnimation();
                    LockAddMatchesUI();

                    //save data
                    var resultado = matchService.CreateOrUpdateMatch(item);

                    if (resultado != null)
                    {
                        //update model
                        item.MatchId = resultado.Item1;
                        item.ButtonSaveVisibility   = Visibility.Collapsed;
                        item.ButtonRemoveVisibility = Visibility.Collapsed;
                        item.ImageDoneVisibility    = Visibility.Visible;
                        item.HomeTeamId             = homeTeamIdAux;
                        item.AwayTeamId             = awayTeamIdAux;

                        string opType = resultado.Item2 == Commons.OperationTypeValues.Create ? "registado" :
                                        resultado.Item2 == Commons.OperationTypeValues.Edit ? "editado" : "inalterado (erro)";
                        NotificationHelper.notifier.ShowCustomMessage("O jogo nº " + item.Order + " foi " + opType + " com sucesso!");
                    }
                    else
                    {
                        NotificationHelper.notifier.ShowCustomMessage("Ocorreu um erro ao registar o jogo nº " + item.Order);
                    }

                    UnlockAddMatchesUI();
                    UtilsNotification.StopLoadingAnimation();
                }).Start();
            }
        }