Example #1
0
        /// <summary>
        /// Find datas
        /// </summary>
        /// <returns></returns>
        public List<TrainingDay> Find(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 && rowList.Count() > 0)
            {
                resultList = new List<TrainingDay>();
                foreach (var trainingJournalDayRow in rowList)
                {
                    resultList.Add(TrainingDayTransformer.ToBean(trainingJournalDayRow));
                }
            }
            return resultList;
        }
Example #2
0
        public void SwitchDayOnTrainingDay(string userId, int year, int weekOfYear, int dayOfWeek, int switchDayOfWeek)
        {
            var trainingDayScenario = new TrainingDayScenario() { ManageExercise = true };

            //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(trainingDayCriteria, trainingDayScenario);

            trainingDayCriteria.DayOfWeek.Equal = switchDayOfWeek;
            var switchTrainingDayList = FindTrainingDay(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);
                }
            }
        }
 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(trainingDayCriteria, trainingDayScenario);
     }
 }
        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(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;
        }
Example #5
0
        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;
        }
Example #6
0
        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(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);
            SynchroManager.TrainingDayChange(DbContext, trainingDayResult);

            if (trainingDay.TrainingExercises != null)
            {
                trainingDayResult.TrainingExercises = new List<TrainingExercise>();
                foreach (var trainingExercise in trainingDay.TrainingExercises)
                {
                    trainingDayResult.TrainingExercises.Add(_trainingWeeksService.CreateTrainingExercise(trainingExercise));
                }
            }

            return trainingDayResult;
        }
        public IActionResult CreateTrainingDay(string userId, int year, int weekOfYear, int dayOfWeek)
        {
            if (string.IsNullOrWhiteSpace(userId) || year == 0 || weekOfYear == 0 || dayOfWeek < 0 || dayOfWeek > 6 || SessionUserId != userId)
                return RedirectToAction("Index");

            var userInfo = _userInfosService.GetUserInfo(new UserInfoKey() { UserId = SessionUserId });
            if (userInfo == null)
                return RedirectToAction("View", new { userId = userId, year = year, weekOfYear = weekOfYear, dayOfWeek = dayOfWeek });

            var trainingDayCriteria = new TrainingDayCriteria()
            {
                UserId = new StringCriteria() { Equal = userId },
                Year = new IntegerCriteria() { Equal = year },
                WeekOfYear = new IntegerCriteria() { Equal = weekOfYear }
            };
            var trainingDayScenario = new TrainingDayScenario()
            {
                ManageExercise = false
            };
            var trainingDayList = _trainingDaysService.FindTrainingDay(trainingDayCriteria, trainingDayScenario);

            int trainingDayId = 0;
            if (trainingDayList != null && trainingDayList.Count > 0)
                trainingDayId = trainingDayList.Max(td => td.TrainingDayId) + 1;

            var trainingDay = new TrainingDay()
            {
                UserId = userId,
                Year = year,
                WeekOfYear = weekOfYear,
                DayOfWeek = dayOfWeek,
                TrainingDayId = trainingDayId
            };

            ViewBag.UserUnit = userInfo.Unit;
            return View(TrainingViewModelTransformer.TrainingDayToViewModel(trainingDay, userInfo));
        }
 public List<TrainingDay> FindTrainingDay(TrainingDayCriteria trainingDayCriteria, TrainingDayScenario trainingDayScenario)
 {
     return GetTrainingDayManager().FindTrainingDay(trainingDayCriteria, trainingDayScenario);
 }