Example #1
0
 private async Task CreateTrainingDayActionAsync()
 {
     try
     {
         if (_trainingDays != null)
         {
             var newTrainingDay = new TrainingDay()
             {
                 Year          = Year,
                 WeekOfYear    = WeekOfYear,
                 DayOfWeek     = DayOfWeek,
                 TrainingDayId = 0,
                 UserId        = UserId
             };
             if (await CreateTrainingDayViewModel.ShowAsync(newTrainingDay, TEditMode.Create, this))
             {
                 _trainingDays.Add(newTrainingDay);
                 //Binding trainingDay for refresh view
                 CreateOrReplaceBindingTrainingDay(newTrainingDay);
             }
         }
     }
     catch (Exception except)
     {
         ILogger.Instance.Error("Unable to create training day", except);
     }
 }
Example #2
0
        private async Task ViewTrainingDayActionAsync(DayOfWeek dayOfWeek)
        {
            try
            {
                if (TrainingWeek.TrainingDays == null)
                {
                    TrainingWeek.TrainingDays = new List <TrainingDay>();
                }

                //Check training day exist. if not exist, create new training day
                var trainingDays = TrainingWeek.TrainingDays.Where(td => td.DayOfWeek == (int)dayOfWeek).ToList();
                if (trainingDays == null)
                {
                    trainingDays = new List <TrainingDay>();
                }
                if (trainingDays.Count == 0)
                {
                    var newTrainingDay = new TrainingDay()
                    {
                        Year          = TrainingWeek.Year,
                        WeekOfYear    = TrainingWeek.WeekOfYear,
                        DayOfWeek     = (int)dayOfWeek,
                        TrainingDayId = 0,
                        UserId        = UserData.Instance.UserInfo.UserId,
                        Unit          = UserData.Instance.UserInfo.Unit
                    };
                    if (await CreateTrainingDayViewModel.ShowAsync(newTrainingDay, TEditMode.Create, this))
                    {
                        TrainingWeek.TrainingDays.Add(newTrainingDay);
                        trainingDays.Add(newTrainingDay);
                        FillWeekDays(TrainingWeek);
                    }
                }

                if (trainingDays.Count > 0)
                { //view training day
                    var trainingDayViewModelResut = await TrainingDayViewModel.ShowAsync(trainingDays, this);

                    //reload local data necessary
                    if (trainingDayViewModelResut.Result)
                    {
                        TrainingWeek.TrainingDays.RemoveAll(td => td.DayOfWeek == (int)dayOfWeek);
                        if (trainingDayViewModelResut.TrainingDays != null && trainingDayViewModelResut.TrainingDays.Count > 0)
                        {
                            TrainingWeek.TrainingDays.AddRange(trainingDayViewModelResut.TrainingDays);
                        }
                        FillWeekDays(TrainingWeek);
                    }
                }
            }
            catch
            {
            }
        }
Example #3
0
 private async Task EditTrainingDayActionAsync(TrainingDay trainingDay)
 {
     if (trainingDay == null)
     {
         return;
     }
     try
     {
         if (await CreateTrainingDayViewModel.ShowAsync(trainingDay, TEditMode.Edit, this))
         {
             //Binding trainingDay for refresh view
             CreateOrReplaceBindingTrainingDay(trainingDay);
         }
     }
     catch (Exception except)
     {
         ILogger.Instance.Error("Unable to edite training day", except);
         await _userDialog.AlertAsync(except.Message, Translation.Get(TRS.ERROR), Translation.Get(TRS.OK));
     }
 }