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); }
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); } }
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); } }
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); } } }
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); } } }
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); }
public void CreateDailyFeeling(DailyFeeling dailyFeeling) { _context.DailyFeelings.Add(dailyFeeling); }