Ejemplo n.º 1
0
 public List <TrainingWeek> FindTrainingWeek(TrainingWeekCriteria trainingWeekCriteria, TrainingWeekScenario trainingWeekScenario)
 {
     return(FindTrainingWeek(new CriteriaList <TrainingWeekCriteria>()
     {
         trainingWeekCriteria
     }, trainingWeekScenario));
 }
        public List <TrainingWeek> FindTrainingWeek(TrainingWeekCriteria trainingWeekCriteria, TrainingWeekScenario trainingWeekScenario)
        {
            List <TrainingWeek> trainingWeeks = _trainingWeekModule.Find(trainingWeekCriteria);

            if (trainingWeeks != null && trainingWeekScenario != null && trainingWeekScenario.TrainingDayScenario != null)
            {
                foreach (TrainingWeek trainingJournal in trainingWeeks)
                {
                    CompleteTrainingWeekWithTrainingDay(trainingJournal, trainingWeekScenario.TrainingDayScenario);
                }
            }

            return(trainingWeeks);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Find datas
        /// </summary>
        /// <returns></returns>
        public List <TrainingWeek> Find(TrainingWeekCriteria trainingWeekCriteria = null)
        {
            List <TrainingWeek>          resultList = null;
            TableQuery <TrainingWeekRow> rowList    = _dbContext.Table <TrainingWeekRow>();

            CriteriaTransformer.CompleteQuery(ref rowList, trainingWeekCriteria);
            rowList = rowList.OrderBy(t => t.UserId).OrderByDescending(t => t.Year).ThenByDescending(t => t.WeekOfYear);

            if (rowList != null && rowList.Count() > 0)
            {
                resultList = new List <TrainingWeek>();
                foreach (var trainingJournalRow in rowList)
                {
                    resultList.Add(TrainingWeekTransformer.ToBean(trainingJournalRow));
                }
            }
            return(resultList);
        }
Ejemplo n.º 4
0
 public List<TrainingWeek> FindTrainingWeek(TrainingWeekCriteria trainingWeekCriteria, TrainingWeekScenario trainingWeekScenario)
 {
     return FindTrainingWeek(new CriteriaList<TrainingWeekCriteria>() { trainingWeekCriteria }, trainingWeekScenario);
 }
Ejemplo n.º 5
0
 public List <TrainingWeek> FindTrainingWeek(TrainingWeekCriteria trainingWeekCriteria, TrainingWeekScenario trainingWeekScenario)
 {
     return(GetTrainingWeekManager().FindTrainingWeek(trainingWeekCriteria, trainingWeekScenario));
 }
        public IActionResult Index(string userId, int year, int weekOfYear, int? dayOfWeekSelected)
        {
            var viewModel = new List<TrainingWeekViewModel>();

            var searchCriteria = new TrainingWeekCriteria() { UserId = new StringCriteria() { Equal = SessionUserId } };
            var scenario = new TrainingWeekScenario() { ManageTrainingDay = false };
            var trainingWeekList = _trainingWeeksService.FindTrainingWeek(searchCriteria, scenario);

            if (trainingWeekList != null)
            {
                foreach (var trainingWeek in trainingWeekList)
                {
                    viewModel.Add(TrainingViewModelTransformer.TrainingWeekToViewModel(trainingWeek, _usersService));
                }
            }

            return View(viewModel);
        }
Ejemplo n.º 7
0
 public List<TrainingWeek> FindTrainingWeek(TrainingWeekCriteria trainingWeekCriteria, TrainingWeekScenario trainingWeekScenario)
 {
     return GetTrainingWeekManager().FindTrainingWeek(trainingWeekCriteria, trainingWeekScenario);
 }
Ejemplo n.º 8
0
        public static async Task <bool> SynchronizeTrainingWeeksAsync(SQLiteConnection dbContext)
        {
            bool result = false;

            try
            {
                //Synchronize TrainingWeek with server (with trainingday and exercise)
                var criteria = new TrainingWeekCriteria();
                criteria.UserId = new StringCriteria()
                {
                    Equal = UserData.Instance.UserInfo.UserId
                };
                TrainingWeekScenario trainingWeekScenario = new TrainingWeekScenario()
                {
                    ManageTrainingDay = false
                };
                var trainingWeekService = new TrainingWeekService(dbContext);
                //retreive local data
                var localTrainingWeekList = trainingWeekService.FindTrainingWeek(criteria, trainingWeekScenario);
                //retreive online data
                var criteriaList = new CriteriaList <TrainingWeekCriteria>()
                {
                    criteria
                };
                var onlineTrainingWeekList = await TrainingWeekWebService.FindTrainingWeeksAsync(criteriaList, trainingWeekScenario);

                bool found;
                //Delete local data if not found on server
                if (localTrainingWeekList != null)
                {
                    var deletedTrainingWeekList = new List <TrainingWeek>();
                    foreach (var localTrainingWeek in localTrainingWeekList)
                    {
                        found = false;
                        if (onlineTrainingWeekList != null)
                        {
                            foreach (var onlineTrainingWeek in onlineTrainingWeekList)
                            {
                                if (TrainingWeekKey.IsEqualByKey(onlineTrainingWeek, localTrainingWeek))
                                {
                                    found = true;
                                    break;
                                }
                            }
                        }
                        if (!found)
                        {
                            deletedTrainingWeekList.Add(localTrainingWeek);
                        }
                    }
                    if (deletedTrainingWeekList.Count > 0)
                    {
                        var deletedTrainingWeekKeyList = new List <TrainingWeekKey>();
                        foreach (var key in deletedTrainingWeekList)
                        {
                            deletedTrainingWeekKeyList.Add(key);
                        }
                        //Delete in local database
                        trainingWeekService.DeleteTrainingWeekList(deletedTrainingWeekKeyList);
                        foreach (var deleteTrainingWeek in deletedTrainingWeekList)
                        {
                            localTrainingWeekList.Remove(deleteTrainingWeek);
                        }
                    }
                }
                //if modification date online != local, get full trainingWeek online data and save them on local database
                var synchronizeTrainingWeekList = new List <TrainingWeek>();
                if (onlineTrainingWeekList != null)
                {
                    foreach (var onlineTrainingWeek in onlineTrainingWeekList)
                    {
                        found = false;
                        if (localTrainingWeekList != null)
                        {
                            foreach (var localTrainingWeek in localTrainingWeekList)
                            {
                                //Same trainingWeek
                                if (TrainingWeekKey.IsEqualByKey(onlineTrainingWeek, localTrainingWeek))
                                {
                                    if (onlineTrainingWeek.ModificationDate.ToUniversalTime() != localTrainingWeek.ModificationDate.ToUniversalTime()) //ToUniversalTime for security...
                                    {
                                        synchronizeTrainingWeekList.Add(onlineTrainingWeek);
                                    }
                                    found = true;
                                    break;
                                }
                            }
                        }
                        if (!found)
                        {
                            synchronizeTrainingWeekList.Add(onlineTrainingWeek);
                        }
                    }
                }

                //Synchronize all trainingWeek data
                trainingWeekScenario = new TrainingWeekScenario()
                {
                    ManageTrainingDay   = true,
                    TrainingDayScenario = new TrainingDayScenario()
                    {
                        ManageExercise = true
                    }
                };
                if (synchronizeTrainingWeekList.Count > 0)
                {
                    criteriaList.Clear();
                    foreach (var trainingWeek in synchronizeTrainingWeekList)
                    {
                        criteria        = new TrainingWeekCriteria();
                        criteria.UserId = new StringCriteria()
                        {
                            Equal = trainingWeek.UserId
                        };
                        criteria.Year = new IntegerCriteria()
                        {
                            Equal = trainingWeek.Year
                        };
                        criteria.WeekOfYear = new IntegerCriteria()
                        {
                            Equal = trainingWeek.WeekOfYear
                        };
                        criteriaList.Add(criteria);
                    }
                    onlineTrainingWeekList = await TrainingWeekWebService.FindTrainingWeeksAsync(criteriaList, trainingWeekScenario);

                    if (onlineTrainingWeekList != null && onlineTrainingWeekList.Count > 0)
                    {
                        trainingWeekService.UpdateTrainingWeekList(onlineTrainingWeekList, trainingWeekScenario);
                    }
                }
                result = true;
            }
            catch (Exception except)
            {
                ILogger.Instance.Error("Unable to synchronize training weeks", except);
            }
            return(result);
        }