/*----------------------------------------------------------------------------------------------------------------------------------------*/
        //
        // ViewModel Logic
        //
        /*----------------------------------------------------------------------------------------------------------------------------------------*/

        #region ViewModel Logic

        public void ReloadList()
        {
            Items.Clear();
            var items = TrainingMasterService.GetTrainingMasterDataList();

            items?.ForEach(data => Items.Add(data));
        }
        /*----------------------------------------------------------------------------------------------------------------------------------------*/
        //
        // Constractor
        //
        /*----------------------------------------------------------------------------------------------------------------------------------------*/

        #region Constractor

        public TrainingListViewModel()
        {
            InitMessageSubscribe();
            InitCommands();
            var items = TrainingMasterService.GetTrainingMasterDataList();

            items?.ForEach(data => Items.Add(data));
        }
        /// <summary>
        ///     トレーニングスケジュール画面遷移
        /// </summary>
        private static void CommandEditTrainingScheduleAction()
        {
            var check = TrainingMasterService.GetTrainingMasterDataList();

            if (check == null || check.Count == 0)
            {
                Application.Current.MainPage.DisplayAlert(LanguageUtils.Get(LanguageKeys.Confirm),
                                                          LanguageUtils.Get(LanguageKeys.NotExistTraining), LanguageUtils.Get(LanguageKeys.OK));
                return;
            }

            ViewModelConst.TrainingPageNavigation.PushAsync(new TrainingScheduleListView());
        }
        /*----------------------------------------------------------------------------------------------------------------------------------------*/
        //
        // Command Actions
        //
        /*----------------------------------------------------------------------------------------------------------------------------------------*/
        #region Command Actions

        /// <summary>
        ///     トレーニング一覧画面遷移
        /// </summary>
        private static void CommandEditTrainingAction()
        {
            var check = TrainingMasterService.GetTrainingMasterDataList();

            if (check == null || check.Count == 0)
            {
                ViewModelConst.TrainingPageNavigation.PushAsync(new TrainingMasterView());
            }
            else
            {
                ViewModelConst.TrainingPageNavigation.PushAsync(new TrainingListView());
            }
        }
        public void CommandAddTrainingAction(TrainingListStructure training)
        {
            var mainStack     = new StackLayout();
            var trainingLabel = new Label
            {
                Text           = LanguageUtils.Get(LanguageKeys.TrainingName),
                FontAttributes = FontAttributes.Bold,
                Margin         = new Thickness(0, 20, 0, 0)
            };

            mainStack.Children.Add(trainingLabel);
            var trainingPicker = new Picker
            {
                ItemsSource        = TrainingMasterService.GetTrainingMasterDataList(),
                ItemDisplayBinding = new Binding("TrainingName"),
                SelectedIndex      = 0
            };

            mainStack.Children.Add(trainingPicker);

            var trainingSetCountLabel = new Label
            {
                Text           = LanguageUtils.Get(LanguageKeys.SetCount),
                FontAttributes = FontAttributes.Bold,
                Margin         = new Thickness(0, 0, 0, 0)
            };

            mainStack.Children.Add(trainingSetCountLabel);

            var trainingSetCountEntry =
                new Entry {
                Text = training.TrainingSetCount.ToString(), Keyboard = Keyboard.Numeric
            };

            mainStack.Children.Add(trainingSetCountEntry);

            var trainingLoadStack = new StackLayout();


            trainingPicker.SelectedItem =
                ((List <TrainingMasterModel>)trainingPicker.ItemsSource).First(data => data.Id == training.TrainingId);

            foreach (var load in training.LoadContentList)
            {
                var loadModdel = LoadService.GetLoad(load.LoadId);

                var loadStack = new StackLayout();
                loadStack.Children.Add(new Label
                {
                    Text           = loadModdel.LoadName,
                    FontAttributes = FontAttributes.Bold,
                    Margin         = new Thickness(0, 0, 0, 0)
                });

                var subLoadStack = new StackLayout {
                    Orientation = StackOrientation.Horizontal
                };
                subLoadStack.Children.Add(new Entry
                {
                    Text         = load.Nums.ToString(),
                    Keyboard     = Keyboard.Numeric,
                    WidthRequest = 145
                });
                var loadUnitPick = new Picker
                {
                    ItemsSource        = LoadUnitService.GetLoadUnitList(load.LoadId),
                    ItemDisplayBinding = new Binding("UnitName"),
                    SelectedIndex      = 0,
                    WidthRequest       = 145
                };
                loadUnitPick.SelectedItem =
                    ((List <LoadUnitModel>)loadUnitPick.ItemsSource).First(data => data.Id == load.LoadUnitId);

                subLoadStack.Children.Add(loadUnitPick);

                loadStack.Children.Add(subLoadStack);
                trainingLoadStack.Children.Add(loadStack);
            }

            trainingPicker.SelectedIndexChanged += (sender, args) =>
            {
                trainingLoadStack.Children.Clear();
                var loadList =
                    JsonConvert.DeserializeObject <LoadStructure>(((TrainingMasterModel)trainingPicker.SelectedItem)
                                                                  .Load);
                foreach (var load in loadList.LoadList)
                {
                    var loadStack = new StackLayout();
                    loadStack.Children.Add(new Label
                    {
                        Text           = load.LoadName,
                        FontAttributes = FontAttributes.Bold,
                        Margin         = new Thickness(0, 0, 0, 0)
                    });

                    var subLoadStack = new StackLayout {
                        Orientation = StackOrientation.Horizontal
                    };
                    subLoadStack.Children.Add(new Entry {
                        Keyboard = Keyboard.Numeric, WidthRequest = 145
                    });
                    subLoadStack.Children.Add(new Picker
                    {
                        ItemsSource        = LoadUnitService.GetLoadUnitList(load.Id),
                        ItemDisplayBinding = new Binding("UnitName"),
                        SelectedIndex      = 0,
                        WidthRequest       = 145
                    });
                    loadStack.Children.Add(subLoadStack);
                    trainingLoadStack.Children.Add(loadStack);
                }
            };

            mainStack.Children.Add(trainingLoadStack);
            TrainingStack.Children.Add(mainStack);
        }