public async Task <IActionResult> Update(Guid workoutId, [Bind("WorkoutOptionId,key,value,CreatedAt")] WorkoutOption option) { User user = _userService.GetByEmail(User.Identity.Name); _workoutService.UpdateWorkoutOption(user, workoutId, option); return(Ok(option)); }
public async Task <IActionResult> Add(Guid workoutId, [Bind("Key,Value")] WorkoutOption option) { User user = _userService.GetByEmail(User.Identity.Name); _workoutService.AddWorkoutOption(user, workoutId, option); return(Ok(option)); }
public void UpdateWorkoutOption(User user, Guid workoutId, WorkoutOption option) { var workoutDB = _context.Workouts.FirstOrDefault(o => o.WorkoutId == workoutId); if (workoutDB == null) { throw new KeyNotFoundException(); } if (workoutDB.UserId != user.UserId) { throw new AuthenticationException(); } option.WorkoutId = (Guid)workoutId; _context.WorkoutsOptions.Add(option); _context.SaveChanges(); }