コード例 #1
0
        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();
        }