/*----------------------------------------------------------------------------------------------------------------------------------------*/ // // Command Actions // /*----------------------------------------------------------------------------------------------------------------------------------------*/ #region Command Actions /// <summary> /// トレーニング保存アクション /// </summary> /// <returns></returns> private async Task CommandSaveAction() { try { if (!ValidationInputData(TrainingName)) { ViewModelCommonUtil.SendMessage(ViewModelConst.MessagingTrainingSelfScroll); return; } IsLoading = true; var partStructureList = new List <PartStructure>(); PartStack.Children.ForEach(child => { var stack = (StackLayout)child; var partModel = ((PartModel)((Picker)stack.Children[0]).SelectedItem); var subPartModel = ((SubPartModel)((Picker)stack.Children[1]).SelectedItem); if (!partStructureList.Any( data => data.Part.Id == partModel.Id && data.SubPart.Id == subPartModel.Id)) { partStructureList.Add(new PartStructure { Part = partModel, SubPart = subPartModel }); } }); var loadList = new List <LoadModel>(); LoadStack.Children.ForEach(child => { var stack = (StackLayout)child; var loadModel = ((LoadModel)((Picker)stack.Children[0]).SelectedItem); if (loadList.All(data => data.Id != loadModel.Id)) { loadList.Add(loadModel); } }); var loadStructure = new LoadStructure { LoadList = loadList }; if (_targetTrainingMasterModel != null) { TrainingMasterService.UpdateTrainingMaster( _targetTrainingMasterModel.Id, TrainingName, JsonConvert.SerializeObject(loadStructure), JsonConvert.SerializeObject(partStructureList)); } else { TrainingMasterService.RegistTrainingMaster( TrainingName, JsonConvert.SerializeObject(loadStructure), JsonConvert.SerializeObject(partStructureList)); } IsLoading = false; await Application.Current.MainPage.DisplayAlert(LanguageUtils.Get(LanguageKeys.Complete), LanguageUtils.Get(LanguageKeys.SaveComplete), LanguageUtils.Get(LanguageKeys.OK)); // ホーム画面をリロードする ViewModelCommonUtil.SendMessage(ViewModelConst.MessagingTrainingPrevPageReload); ViewModelCommonUtil.TrainingBackPage(); } catch (Exception e) { Debug.WriteLine(e); } }
private async Task CommandSaveAction() { try { if (!Validate()) { ViewModelCommonUtil.SendMessage(ViewModelConst.MessagingTrainingSelfScroll); return; } IsLoading = true; var trainingContentList = new List <TrainingListStructure>(); if (!Off) { // トレーニング一覧 var trainingStack = TrainingStack.Children; foreach (var training in trainingStack) { var insert = new TrainingListStructure(); var trainingId = ((TrainingMasterModel)((Picker)((StackLayout)training).Children[1]).SelectedItem).Id; var trainingseCount = ((Entry)((StackLayout)training).Children[3]).Text; var loadContentList = new List <LoadContentStructure>(); var loadStack = ((StackLayout)((StackLayout)training).Children[4]).Children; foreach (var load in loadStack) { var insertload = new LoadContentStructure(); var subLoad = ((StackLayout)load).Children[1]; var loadId = ((LoadUnitModel)((Picker)((StackLayout)subLoad).Children[1]).SelectedItem) .LoadId; var nums = ((Entry)((StackLayout)subLoad).Children[0]).Text; var loadUnitId = ((LoadUnitModel)((Picker)((StackLayout)subLoad).Children[1]).SelectedItem).Id; insertload.LoadId = loadId; insertload.LoadUnitId = loadUnitId; insertload.Nums = float.Parse(nums); loadContentList.Add(insertload); } insert.LoadContentList = loadContentList; insert.TrainingId = trainingId; insert.TrainingSetCount = int.Parse(trainingseCount); trainingContentList.Add(insert); } } var trainingScheduleStructure = new TrainingScheduleStructure { TrainingContentList = trainingContentList, Off = Off, Week = _week }; var trainingScheduleStructureJson = JsonConvert.SerializeObject(trainingScheduleStructure); if (_isUpdate) { TrainingScheduleService.UpdateTrainingSchedule(_id, trainingScheduleStructureJson, _week); } else { TrainingScheduleService.RegistTrainingSchedule(trainingScheduleStructureJson, _week); } IsLoading = false; await Application.Current.MainPage.DisplayAlert(LanguageUtils.Get(LanguageKeys.Complete), LanguageUtils.Get(LanguageKeys.SaveComplete), LanguageUtils.Get(LanguageKeys.OK)); // ホーム画面をリロードする ViewModelCommonUtil.SendMessage(ViewModelConst.MessagingTrainingPrevPageReload); ViewModelCommonUtil.TrainingBackPage(); } catch (Exception e) { Debug.WriteLine(e); } }