public void SwitchDayOnTrainingDay(string userId, int year, int weekOfYear, int dayOfWeek, int switchDayOfWeek)
        {
            var trainingDayScenario = new TrainingDayScenario()
            {
                ManageExercise = true
            };
            var userUnit = AppUtils.GetUserUnit(_userInfosService, userId);

            //Search current training day
            var trainingDayCriteria = new TrainingDayCriteria()
            {
                UserId = new StringCriteria()
                {
                    Equal = userId
                },
                Year = new IntegerCriteria()
                {
                    Equal = year
                },
                WeekOfYear = new IntegerCriteria()
                {
                    Equal = weekOfYear
                },
                DayOfWeek = new IntegerCriteria()
                {
                    Equal = dayOfWeek
                }
            };
            var currentTrainingDayList = FindTrainingDay(userUnit, trainingDayCriteria, trainingDayScenario);

            trainingDayCriteria.DayOfWeek.Equal = switchDayOfWeek;
            var switchTrainingDayList = FindTrainingDay(userUnit, trainingDayCriteria, trainingDayScenario);

            DeleteTrainingDays(currentTrainingDayList);
            DeleteTrainingDays(switchTrainingDayList);

            if (currentTrainingDayList != null)
            {
                foreach (var trainingDay in currentTrainingDayList)
                {
                    ChangeDayOnTrainingDay(trainingDay, switchDayOfWeek);
                    UpdateTrainingDay(trainingDay, trainingDayScenario);
                }
            }

            if (switchTrainingDayList != null)
            {
                foreach (var trainingDay in switchTrainingDayList)
                {
                    ChangeDayOnTrainingDay(trainingDay, dayOfWeek);
                    UpdateTrainingDay(trainingDay, trainingDayScenario);
                }
            }
        }
        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);
        }
        public static async Task <List <TrainingDay> > FindTrainingDaysAsync(TrainingDayCriteria trainingDayCriteria, TrainingDayScenario trainingDayScenario)
        {
            if (trainingDayCriteria == null)
            {
                return(null);
            }

            var trainingDayFinder = new TrainingDayFinder();

            trainingDayFinder.TrainingDayCriteria = trainingDayCriteria;
            trainingDayFinder.TrainingDayScenario = trainingDayScenario;
            return(await HttpConnector.Instance.PostAsync <TrainingDayFinder, List <TrainingDay> >("Api/TrainingDays/Find", trainingDayFinder));
        }
        internal List <TrainingDay> FindTrainingDay(TrainingDayCriteria trainingDayCriteria, TrainingDayScenario trainingDayScenario)
        {
            var trainingDays = _trainingDayModule.Find(trainingDayCriteria);

            if (trainingDayScenario != null && trainingDayScenario.ManageExercise && trainingDays != null)
            {
                foreach (var trainingDay in trainingDays)
                {
                    CompleteTrainingDayWithExercise(trainingDay);
                }
            }

            return(trainingDays);
        }
        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);
        }
Exemple #6
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);
        }
        /// <summary>
        /// Find datas
        /// </summary>
        /// <returns></returns>
        public List <TrainingDay> Find(TrainingDayCriteria trainingDayCriteria = null)
        {
            List <TrainingDay>          resultList = null;
            TableQuery <TrainingDayRow> rowList    = _dbContext.Table <TrainingDayRow>();

            CriteriaTransformer.CompleteQuery(ref rowList, trainingDayCriteria);
            rowList = rowList.OrderBy(t => t.DayOfWeek).OrderBy(t => t.BeginHour);

            if (rowList != null && rowList.Count() > 0)
            {
                resultList = new List <TrainingDay>();
                foreach (var trainingJournalDayRow in rowList)
                {
                    resultList.Add(TrainingDayTransformer.ToBean(trainingJournalDayRow));
                }
            }
            return(resultList);
        }
        internal List <TrainingDay> FindTrainingDay(TUnitType userUnit, TrainingDayCriteria trainingDayCriteria, TrainingDayScenario trainingDayScenario)
        {
            var trainingDays = _trainingDayModule.Find(userUnit, trainingDayCriteria);

            if (trainingDayScenario != null && trainingDayScenario.ManageExercise && trainingDays != null && trainingDays.Count > 0)
            {
                var    criteriaList = new CriteriaList <TrainingExerciseCriteria>();
                string userId       = null;
                foreach (var trainingDay in trainingDays)
                {
                    criteriaList.Add(CreateTrainingExerciseCriteria(trainingDay));
                    if (userId == null)
                    {
                        userId = trainingDay.UserId;
                    }
                }
                var trainingExerciseList = _trainingExercisesService.FindTrainingExercise(criteriaList);
                if (trainingExerciseList != null)
                {
                    foreach (var trainingDay in trainingDays)
                    {
                        foreach (var trainingExercise in trainingExerciseList)
                        {
                            if (trainingExercise != null &&
                                (trainingDay.UserId != null && trainingDay.UserId == trainingExercise.UserId) &&
                                (trainingDay.Year == trainingExercise.Year) &&
                                (trainingDay.WeekOfYear == trainingExercise.WeekOfYear) &&
                                (trainingDay.DayOfWeek == trainingExercise.DayOfWeek) &&
                                (trainingDay.TrainingDayId == trainingExercise.TrainingDayId))
                            {
                                if (trainingDay.TrainingExercises == null)
                                {
                                    trainingDay.TrainingExercises = new List <TrainingExercise>();
                                }
                                trainingDay.TrainingExercises.Add(trainingExercise);
                            }
                        }
                    }
                }
            }

            return(trainingDays);
        }
Exemple #9
0
        public List <TrainingDay> FindTrainingDay(TUnitType userUnit, TrainingDayCriteria trainingDayCriteria, TrainingDayScenario trainingDayScenario)
        {
            List <TrainingDay> result;

            BeginTransaction();
            try
            {
                result = GetTrainingDayManager().FindTrainingDay(userUnit, trainingDayCriteria, trainingDayScenario);
                CommitTransaction();
            }
            catch
            {
                RollbackTransaction();
                throw;
            }
            finally
            {
                EndTransaction();
            }
            return(result);
        }
        /// <summary>
        /// Find datas
        /// </summary>
        /// <returns></returns>
        public List <TrainingDay> Find(TUnitType userUnit, TrainingDayCriteria trainingDayCriteria = null)
        {
            List <TrainingDay>          resultList = null;
            IQueryable <TrainingDayRow> rowList    = _dbContext.TrainingDay;

            CriteriaTransformer.CompleteQuery(ref rowList, trainingDayCriteria);
            rowList = rowList.OrderBy(t => t.DayOfWeek).OrderBy(t => t.BeginHour);

            if (rowList != null)
            {
                foreach (var trainingJournalDayRow in rowList)
                {
                    if (resultList == null)
                    {
                        resultList = new List <TrainingDay>();
                    }
                    resultList.Add(TrainingDayTransformer.ToBean(trainingJournalDayRow, userUnit));
                }
            }
            return(resultList);
        }
Exemple #11
0
 private void CompleteTrainingWeekWithTrainingDay(TrainingWeek trainingWeek, TrainingDayScenario trainingDayScenario)
 {
     if (trainingWeek != null)
     {
         var trainingDayCriteria = new TrainingDayCriteria()
         {
             UserId = new StringCriteria()
             {
                 Equal = trainingWeek.UserId
             },
             Year = new IntegerCriteria()
             {
                 Equal = trainingWeek.Year
             },
             WeekOfYear = new IntegerCriteria()
             {
                 Equal = trainingWeek.WeekOfYear
             },
         };
         trainingWeek.TrainingDays = _trainingDaysService.FindTrainingDay(AppUtils.GetUserUnit(_userInfosService, trainingWeek.UserId), trainingDayCriteria, trainingDayScenario);
     }
 }
 public List <TrainingDay> FindTrainingDay(TUnitType userUnit, TrainingDayCriteria trainingDayCriteria, TrainingDayScenario trainingDayScenario)
 {
     return(GetTrainingDayManager().FindTrainingDay(userUnit, trainingDayCriteria, trainingDayScenario));
 }