Beispiel #1
0
        internal TrainingWeek UpdateTrainingWeek(TrainingWeek trainingWeek, TrainingWeekScenario trainingWeekScenario)
        {
            TrainingWeek trainingWeekResult = null;

            trainingWeekResult = _trainingWeekModule.Update(trainingWeek);

            if (trainingWeekScenario != null && trainingWeekScenario.ManageTrainingDay)
            {
                var trainingDayScenario = new TrainingDayScenario()
                {
                    ManageExercise = true
                };

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

                if (trainingWeek.TrainingDays != null)
                {
                    trainingWeekResult.TrainingDays = new List <TrainingDay>();
                    foreach (var trainingDay in trainingWeek.TrainingDays)
                    {
                        trainingWeekResult.TrainingDays.Add(_trainingDaysService.UpdateTrainingDay(trainingDay, trainingWeekScenario.TrainingDayScenario));
                    }
                }
            }
            return(trainingWeekResult);
        }
        public IActionResult Find([FromBody] TrainingDayFinder trainingDayFinder)
        {
            try
            {
                if (trainingDayFinder == null)
                {
                    return(BadRequest());
                }

                var trainingDayCriteria = trainingDayFinder.TrainingDayCriteria;
                var trainingDayScenario = trainingDayFinder.TrainingDayScenario;

                if (trainingDayCriteria == null || trainingDayCriteria.UserId == null)
                {
                    return(BadRequest());
                }

                var result = _trainingDaysService.FindTrainingDay(AppUtils.GetUserUnit(_userInfosService, SessionUserId), trainingDayCriteria, trainingDayScenario);
                return(new OkObjectResult(result)); // List<TrainingDay>
            }
            catch (Exception exception)
            {
                return(BadRequest(new WebApiException("Error", exception)));
            }
        }