internal TrainingWeek UpdateTrainingWeek(TrainingWeek trainingWeek, TrainingWeekScenario trainingWeekScenario)
        {
            DbContext.ChangeTracker.AutoDetectChangesEnabled = false;
            TrainingWeek trainingWeekResult = null;

            trainingWeekResult = _trainingWeekModule.Update(trainingWeek);

            if (trainingWeekScenario != null && trainingWeekScenario.ManageTrainingDay)
            {
                var trainingDayCriteria = new TrainingDayCriteria()
                {
                    UserId = new StringCriteria()
                    {
                        Equal = trainingWeek.UserId
                    },
                    Year = new IntegerCriteria()
                    {
                        Equal = trainingWeek.Year
                    },
                    WeekOfYear = new IntegerCriteria()
                    {
                        Equal = trainingWeek.WeekOfYear
                    }
                };
                var userUnit       = AppUtils.GetUserUnit(_userInfosService, trainingWeek.UserId);
                var trainingDaysDb = _trainingDayService.FindTrainingDay(userUnit, trainingDayCriteria, trainingWeekScenario.TrainingDayScenario);
                if (trainingDaysDb != null && trainingDaysDb.Count > 0)
                {
                    foreach (var trainingDayDb in trainingDaysDb)
                    {
                        _trainingDayService.DeleteTrainingDay(trainingDayDb);
                    }
                }

                if (trainingWeek.TrainingDays != null)
                {
                    trainingWeekResult.TrainingDays = new List <TrainingDay>();
                    foreach (var trainingDay in trainingWeek.TrainingDays)
                    {
                        trainingWeekResult.TrainingDays.Add(_trainingDayService.UpdateTrainingDay(trainingDay, trainingWeekScenario.TrainingDayScenario));
                    }
                }
            }
            DbContext.ChangeTracker.DetectChanges();
            DbContext.SaveChanges();
            DbContext.ChangeTracker.AutoDetectChangesEnabled = true;
            return(trainingWeekResult);
        }
Пример #2
0
 private async Task DeleteTrainingDayActionAsync(TrainingDay trainingDay)
 {
     if (trainingDay == null)
     {
         return;
     }
     try
     {
         if (await _userDialog.ConfirmAsync(string.Format(Translation.Get(TRS.ARE_YOU_SURE_YOU_WANNA_DELETE_THIS_ELEMENT_PI), Translation.Get(TRS.TRAINING_DAY)),
                                            Translation.Get(TRS.QUESTION), Translation.Get(TRS.YES), Translation.Get(TRS.NO)))
         {
             //Delete on server
             if (await TrainingDayWebService.DeleteTrainingDayAsync(trainingDay))
             {
                 //Delete on local
                 _trainingDayService.DeleteTrainingDay(trainingDay);
                 //Binding trainingDay for refresh view
                 _trainingDays.Remove(trainingDay);
                 var collection = GroupedTrainingExercises.Where(lgte => TrainingDayKey.IsEqualByKey((TrainingDay)lgte.ReferenceObject, trainingDay)).FirstOrDefault();
                 if (collection != null)
                 {
                     GroupedTrainingExercises.Remove(collection);
                 }
             }
         }
     }
     catch (Exception except)
     {
         ILogger.Instance.Error("Unable to delete training day", except);
         await _userDialog.AlertAsync(except.Message, Translation.Get(TRS.ERROR), Translation.Get(TRS.OK));
     }
 }
Пример #3
0
        //public TrainingPlan GetWorkoutPlan(Token token, Guid planId, RetrievingInfo retrievingInfo)
        //{
        //    var securityInfo = SecurityManager.EnsureAuthentication(token);
        //    WorkoutPlanService service = new WorkoutPlanService(Session,securityInfo,Configuration);
        //    return service.GetWorkoutPlan(planId, retrievingInfo);
        //}

        public void DeleteTrainingDay(Token token, DeleteTrainingDayParam param)
        {
            var securityInfo           = SecurityManager.EnsureAuthentication(token);
            TrainingDayService service = new TrainingDayService(Session, securityInfo, Configuration, PushNotificationService, EMailService);

            service.DeleteTrainingDay(param);
        }
        internal TrainingWeek UpdateTrainingWeek(TrainingWeek trainingWeek, TrainingWeekScenario trainingWeekScenario)
        {
            TrainingWeek trainingWeekResult = null;

            trainingWeekResult = _trainingWeekModule.Update(trainingWeek);

            if (trainingWeekScenario != null && trainingWeekScenario.ManageTrainingDay)
            {
                var trainingDayCriteria = new TrainingDayCriteria()
                {
                    UserId = new StringCriteria()
                    {
                        Equal = trainingWeek.UserId
                    },
                    Year = new IntegerCriteria()
                    {
                        Equal = trainingWeek.Year
                    },
                    WeekOfYear = new IntegerCriteria()
                    {
                        Equal = trainingWeek.WeekOfYear
                    }
                };
                var trainingDaysDb = _trainingDayService.FindTrainingDay(trainingDayCriteria, trainingWeekScenario.TrainingDayScenario);
                if (trainingDaysDb != null && trainingDaysDb.Count > 0)
                {
                    foreach (var trainingDayDb in trainingDaysDb)
                    {
                        _trainingDayService.DeleteTrainingDay(trainingDayDb);
                    }
                }

                if (trainingWeek.TrainingDays != null)
                {
                    trainingWeekResult.TrainingDays = new List <TrainingDay>();
                    foreach (var trainingDay in trainingWeek.TrainingDays)
                    {
                        trainingWeekResult.TrainingDays.Add(_trainingDayService.UpdateTrainingDay(trainingDay, trainingWeekScenario.TrainingDayScenario));
                    }
                }
            }
            return(trainingWeekResult);
        }