Exemplo n.º 1
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
            {
            }
        }
Exemplo n.º 2
0
        public static async Task <TrainingDayViewModelResut> ShowAsync(List <TrainingDay> trainingDayList, BaseViewModel parent = null)
        {
            TrainingDayViewModelResut trainingDayViewModelResut = new TrainingDayViewModelResut();

            if (trainingDayList != null && trainingDayList.Count > 0)
            {
                var viewModel = new TrainingDayViewModel();
                viewModel._trainingDays = trainingDayList;
                await ShowModalViewModelAsync(viewModel, parent);

                //Here always return true because it's an interactive page, user doesn't validate page
                trainingDayViewModelResut.Result = true;
                trainingDayViewModelResut.TrainingDays.AddRange(viewModel._trainingDays);
            }

            return(trainingDayViewModelResut);
        }