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); }
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); }