Exemplo n.º 1
0
        public void DeleteDailyFeeling(DailyFeeling dailyFeeling)
        {
            //Todo test this well
            var diaryFeelingToDelete = _context.DailyFeelings.FirstOrDefault(d => d.DailyFeelingId == dailyFeeling.DailyFeelingId);

            if (diaryFeelingToDelete != null)
            {
                _context.DailyFeelings.Remove(diaryFeelingToDelete);
            }
        }
Exemplo n.º 2
0
        public void UpdateDailyFeeling(DailyFeeling dailyFeeling)
        {
            //Todo test this well
            var diaryFeelingToUpdate = _context.DailyFeelings.FirstOrDefault(d => d.DailyFeelingId == dailyFeeling.DailyFeelingId);

            if (diaryFeelingToUpdate != null)
            {
                _context.Entry(diaryFeelingToUpdate).CurrentValues.SetValues(dailyFeeling);
            }
        }
Exemplo n.º 3
0
 public static DailyFeelingVM DiaryFeelingToDiaryFeelingVM(DailyFeeling df)
 {
     var diaryFeeling = new DailyFeelingVM()
     {
         DailyFeelingId = df.DailyFeelingId,
         Date = df.Date,
         Fatigue = df.Fatigue,
         Notes = df.Notes,
         RestingHeartRate = df.RestingHeartRate,
         Sleep = df.Sleep,
         Soreness = df.Soreness,
         Stress = df.Stress,
         Weight = df.Weight,
         WorkoutsVM = WorkoutToWorkoutVM(df.Workouts)
     };
     return diaryFeeling;
 }
Exemplo n.º 4
0
 public void CreateDailyFeeling(DailyFeeling dailyFeeling)
 {
     _context.DailyFeelings.Add(dailyFeeling);
 }
Exemplo n.º 5
0
 public static DailyFeeling DiaryFeelingVMToDiaryFeeling(DailyFeelingVM df)
 {
     var diaryFeeling = new DailyFeeling()
                           {
                               DailyFeelingId = df.DailyFeelingId,
                               Date = df.Date,
                               Fatigue = df.Fatigue,
                               Notes = df.Notes,
                               RestingHeartRate = df.RestingHeartRate,
                               Sleep = df.Sleep,
                               Soreness = df.Soreness,
                               Stress = df.Stress,
                               Weight = df.Weight,
         Workouts = df.WorkoutsVM==null ? null: (from w in df.WorkoutsVM
                       select new Workout()
                       {
                           WorkoutId = w.WorkoutId,
                           Distance = w.Distance,
                           Notes = w.Notes,
                           TotalTime = w.TotalTime,
                           WorkoutTypeId = w.WorkoutTypeId
                       }).ToList()
     };
     return diaryFeeling;
 }
Exemplo n.º 6
0
        private void UpdateWorkouts(DailyFeeling dailyFeeling)
        {
            var dailyFeelingCurrent = _uow.DiaryFeelingRepository.GetDailyFeeling(dailyFeeling.DailyFeelingId);
            if (dailyFeelingCurrent.Workouts == null || !dailyFeelingCurrent.Workouts.Any())
            {
                AddWorkouts(dailyFeeling);
                return;
            }

            var isUpdate = false;
            foreach (var workoutCurrent in dailyFeelingCurrent.Workouts)
            {
                foreach (var workout in dailyFeeling.Workouts)
                {
                    if (workoutCurrent.WorkoutId == workout.WorkoutId)
                    {
                        //UpdateWorkout(workout);
                        isUpdate = true;
                    }
                }
                if (!isUpdate)
                {
                    //DeleteWorkout(workoutCurrent);
                }
                isUpdate = false;
            }
            var isCreate = true;
            foreach (var workout in dailyFeeling.Workouts)
            {
                foreach (var workoutCurrent in dailyFeelingCurrent.Workouts)
                {
                    if (workoutCurrent.WorkoutId == workout.WorkoutId)
                    {
                        isCreate = false;
                    }
                }
                if (isCreate)
                {
                    //AddWorkout(workout);
                }
            }
        }
Exemplo n.º 7
0
 private void AddWorkouts(DailyFeeling dailyFeeling)
 {
     if (dailyFeeling.Workouts != null && dailyFeeling.Workouts.Count > 0)
     {
         foreach (var workout in dailyFeeling.Workouts)
         {
             workout.DiaryFeelingId = dailyFeeling.DailyFeelingId;
             _uow.WorkoutRepository.CreateWorkout(workout);
         }
     }
 }