コード例 #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);
            }
        }
コード例 #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);
            }
        }
コード例 #3
0
ファイル: MapMVM.cs プロジェクト: jjcv2304/DailyEntry
 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;
 }
コード例 #4
0
 public void CreateDailyFeeling(DailyFeeling dailyFeeling)
 {
     _context.DailyFeelings.Add(dailyFeeling);
 }
コード例 #5
0
ファイル: MapMVM.cs プロジェクト: jjcv2304/DailyEntry
 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;
 }
コード例 #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);
                }
            }
        }
コード例 #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);
         }
     }
 }