예제 #1
0
        internal TrainingDay CreateTrainingDay(TrainingDay trainingDay)
        {
            var trainingDayCriteria = new TrainingDayCriteria()
            {
                UserId = new StringCriteria()
                {
                    Equal = trainingDay.UserId
                },
                Year = new IntegerCriteria()
                {
                    Equal = trainingDay.Year
                },
                WeekOfYear = new IntegerCriteria()
                {
                    Equal = trainingDay.WeekOfYear
                },
                DayOfWeek = new IntegerCriteria()
                {
                    Equal = trainingDay.DayOfWeek
                },
            };
            var trainingDayScenario = new TrainingDayScenario()
            {
                ManageExercise = false
            };
            var trainingDayList = FindTrainingDay(AppUtils.GetUserUnit(_userInfosService, trainingDay.UserId), trainingDayCriteria, trainingDayScenario);
            int trainingDayId   = 1;

            if (trainingDayList != null && trainingDayList.Count > 0)
            {
                trainingDayId = trainingDayList.Max(td => td.TrainingDayId) + 1;
            }

            trainingDay.TrainingDayId = trainingDayId;
            // no need transaction, only header

            TrainingDay trainingDayResult = null;

            trainingDayResult = _trainingDayModule.Create(trainingDay, AppUtils.GetUserUnit(_userInfosService, trainingDay.UserId));
            SynchroManager.TrainingDayChange(DbContext, trainingDayResult);

            if (trainingDay.TrainingExercises != null)
            {
                trainingDayResult.TrainingExercises = new List <TrainingExercise>();
                foreach (var trainingExercise in trainingDay.TrainingExercises)
                {
                    trainingDayResult.TrainingExercises.Add(_trainingExercisesService.CreateTrainingExercise(trainingExercise));
                }
            }

            return(trainingDayResult);
        }
        internal TrainingDay CreateTrainingDay(TrainingDay trainingDay)
        {
            TrainingDay trainingDayResult = null;

            trainingDayResult = _trainingDayModule.Create(trainingDay);

            if (trainingDay.TrainingExercises != null)
            {
                var trainingExerciseService = new TrainingExerciseService(DbContext);
                trainingDayResult.TrainingExercises = new List <TrainingExercise>();
                foreach (var trainingExercise in trainingDay.TrainingExercises)
                {
                    trainingDayResult.TrainingExercises.Add(trainingExerciseService.CreateTrainingExercise(trainingExercise));
                }
            }

            return(trainingDayResult);
        }