private async Task <bool> SaveDataAsync() { TrainingWeek trainingWeek = null; if (EditMode == TEditMode.Create) { trainingWeek = await TrainingWeekWebService.CreateTrainingWeekAsync(TrainingWeek); if (trainingWeek != null) { var trainingWeekScenario = new TrainingWeekScenario() { ManageTrainingDay = true }; _trainingWeekService.UpdateTrainingWeek(trainingWeek, trainingWeekScenario); } } else { var trainingWeekScenario = new TrainingWeekScenario() { ManageTrainingDay = false }; trainingWeek = await TrainingWeekWebService.UpdateTrainingWeekAsync(TrainingWeek, trainingWeekScenario); if (trainingWeek != null) { _trainingWeekService.UpdateTrainingWeek(trainingWeek, trainingWeekScenario); } } return(trainingWeek != null); }
public async Task CopyTrainingDayActionAsync(DayOfWeek dayOfWeek) { if (TrainingWeek == null) { return; } try { var trainingDayKey = new TrainingDayKey() { UserId = TrainingWeek.UserId, Year = TrainingWeek.Year, WeekOfYear = TrainingWeek.WeekOfYear, DayOfWeek = (int)dayOfWeek }; List <GenericData> datas = new List <GenericData>(); foreach (DayOfWeek dayOfWeekTmp in Enum.GetValues(typeof(DayOfWeek))) { if (dayOfWeekTmp != dayOfWeek) { datas.Add(new GenericData() { Tag = (int)dayOfWeekTmp, Name = Translation.Get(dayOfWeekTmp.ToString().ToUpper()) }); } } var result = await ListViewModel.ShowGenericListAsync(Translation.Get(TRS.DAY_OF_WEEK), datas, null, this); if (result.Validated && result.SelectedData != null) { int dayOfWeekSelected = (int)result.SelectedData.Tag; //Copy day on server await TrainingDayWebService.CopyDayOfTrainingDay(trainingDayKey, dayOfWeekSelected); //Reload updated TrainingWeek on server var updatedTrainingWeek = await TrainingWeekWebService.GetTrainingWeekAsync(TrainingWeek, true); if (updatedTrainingWeek != null) { var trainingWeekService = new TrainingWeekService(DbContext); var trainingWeekScenario = new TrainingWeekScenario() { ManageTrainingDay = true }; trainingWeekService.UpdateTrainingWeek(updatedTrainingWeek, trainingWeekScenario); //Update UI TrainingWeek = updatedTrainingWeek; await SynchronizeDataAsync(); } } } catch (Exception except) { await _userDialog.AlertAsync(except.Message, Translation.Get(TRS.ERROR), Translation.Get(TRS.OK)); } }
private async Task <bool> SaveDataAsync() { bool result = false; TrainingWeek trainingWeek = await TrainingWeekWebService.CopyTrainingWeekAsync(CopyTrainingWeek); if (trainingWeek != null) { var trainingWeekScenario = new TrainingWeekScenario() { ManageTrainingDay = true }; _trainingWeekService.UpdateTrainingWeek(trainingWeek, trainingWeekScenario); result = true; } return(result); }
private async Task ViewTrainingWeekActionAsync(BindingTrainingWeek bindingTrainingWeek) { try { if (bindingTrainingWeek != null && bindingTrainingWeek.TrainingWeek != null) { TrainingWeek trainingWeek = null; var trainingWeekScenario = new TrainingWeekScenario() { ManageTrainingDay = true }; try { //load server data (only header) trainingWeek = await TrainingWeekWebService.GetTrainingWeekAsync(bindingTrainingWeek.TrainingWeek, false); if (trainingWeek != null) { if (trainingWeek.ModificationDate != bindingTrainingWeek.TrainingWeek.ModificationDate) { //load server data (full) trainingWeek = await TrainingWeekWebService.GetTrainingWeekAsync(bindingTrainingWeek.TrainingWeek, true); if (trainingWeek != null) { //Save data on local database _trainingWeekService.UpdateTrainingWeek(trainingWeek, trainingWeekScenario); } } else { trainingWeek = null; // force reload local data } } } catch { // Unable to retreive local data ILogger.Instance.Info("Unable to retreive TrainingWeek on server"); trainingWeek = null; } if (trainingWeek == null) { //load local data trainingWeek = _trainingWeekService.GetTrainingWeek(bindingTrainingWeek.TrainingWeek, trainingWeekScenario); } if (trainingWeek != null) { //Display view model if (await TrainingWeekViewModel.ShowAsync(trainingWeek, this)) { //Refresh data RetreiveLocalData(); SynchronizeData(); } } } } catch (Exception except) { await _userDialog.AlertAsync(except.Message, Translation.Get(TRS.ERROR), Translation.Get(TRS.OK)); } }