示例#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 Delete([FromBody] TrainingDayKey trainingDayKey)
        {
            try
            {
                if (trainingDayKey == null || string.IsNullOrWhiteSpace(trainingDayKey.UserId) || trainingDayKey.Year == 0)
                {
                    return(BadRequest());
                }

                //Verify valid week of year
                if (trainingDayKey.WeekOfYear > 0 && trainingDayKey.WeekOfYear <= 52)
                {
                    _trainingDaysService.DeleteTrainingDay(trainingDayKey);
                    return(new OkObjectResult(true)); // Boolean
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception exception)
            {
                return(BadRequest(new WebApiException("Error", exception)));
            }
        }