示例#1
0
        public Set UpdateSet(Set set, Guid userId)
        {
            if (string.Equals(set.Name, _deleteKeyWord, StringComparison.InvariantCultureIgnoreCase))
            {
                return(DeleteSet(set, userId));
            }
            using (var db = new WorkoutDb())
            {
                var previousSet = db.Sets.Find(set.SetId);
                if (previousSet.Order != set.Order)
                {
                    if (previousSet.Order - set.Order + 1 > 0)
                    {
                        var orderUpdates = db.Sets.Where(x => x.Order >= set.Order && x.Order < previousSet.Order && x.SetId != set.SetId && x.ExerciseId == set.ExerciseId).ToList();
                        orderUpdates.ForEach(x => x.Order++);
                    }
                    else
                    {
                        var orderUpdates = db.Sets.Where(x => x.Order > previousSet.Order && x.Order <= set.Order + 1 && x.SetId != set.SetId && x.ExerciseId == set.ExerciseId).ToList();
                        orderUpdates.ForEach(x => x.Order--);
                    }
                    db.SaveChanges();
                }

                db.Entry(previousSet).State = EntityState.Detached;

                db.Update(set);
                db.SaveChanges();
                return(set);
            }
        }
示例#2
0
        public Exercise UpdateExercise(Exercise exercise, Guid userId)
        {
            if (string.Equals(exercise.Name, _deleteKeyWord, StringComparison.InvariantCultureIgnoreCase))
            {
                return(DeleteExercise(exercise, userId));
            }
            using (var db = new WorkoutDb())
            {
                var previousExercise = db.Exercises.Find(exercise.ExerciseId);
                if (previousExercise.Order != exercise.Order)
                {
                    if (previousExercise.Order - exercise.Order + 1 > 0)
                    {
                        var orderUpdates = db.Exercises.Where(x => x.Order >= exercise.Order && x.Order < previousExercise.Order && x.ExerciseId != exercise.ExerciseId && x.DayId == exercise.DayId).ToList();
                        orderUpdates.ForEach(x => x.Order++);
                    }
                    else
                    {
                        var orderUpdates = db.Exercises.Where(x => x.Order > previousExercise.Order && x.Order <= exercise.Order + 1 && x.ExerciseId != exercise.ExerciseId && x.DayId == exercise.DayId).ToList();
                        orderUpdates.ForEach(x => x.Order--);
                    }
                    db.SaveChanges();
                }

                db.Entry(previousExercise).State = EntityState.Detached;

                db.Update(exercise);
                db.SaveChanges();
                return(exercise);
            }
        }
示例#3
0
        public Day UpdateDay(Day day, Guid userId)
        {
            if (string.Equals(day.Name, _deleteKeyWord, StringComparison.InvariantCultureIgnoreCase))
            {
                return(DeleteDay(day, userId));
            }
            using (var db = new WorkoutDb())
            {
                var previousDay = db.Days.Find(day.DayId);
                if (previousDay.Order != day.Order)
                {
                    if (previousDay.Order - day.Order + 1 > 0)
                    {
                        var orderUpdates = db.Days.Where(x => x.Order >= day.Order && x.Order < previousDay.Order && x.DayId != day.DayId && x.WorkoutId == day.WorkoutId).ToList();
                        orderUpdates.ForEach(x => x.Order++);
                    }
                    else
                    {
                        var orderUpdates = db.Days.Where(x => x.Order > previousDay.Order && x.Order <= day.Order + 1 && x.DayId != day.DayId && x.WorkoutId == day.WorkoutId).ToList();
                        orderUpdates.ForEach(x => x.Order--);
                    }
                    db.SaveChanges();
                }

                db.Entry(previousDay).State = EntityState.Detached;

                db.Update(day);
                db.SaveChanges();
                return(day);
            }
        }
示例#4
0
 public void UpdateExercise(Exercise exercise)
 {
     using (var context = new WorkoutDb())
     {
         context.Exercises.Attach(exercise);
         context.Entry(exercise).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
示例#5
0
 public void UpdateDay(Day day)
 {
     using (var context = new WorkoutDb())
     {
         context.Days.Attach(day);
         context.Entry(day).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
示例#6
0
 public void UpdateSet(Set set)
 {
     using (var context = new WorkoutDb())
     {
         context.Sets.Attach(set);
         context.Entry(set).State = EntityState.Modified;
         context.SaveChanges();
     }
 }