public async Task <IActionResult> Cancel(int traineeId) { var trainee = await _shiftRepository.GetTrainee(traineeId); if (trainee.TraineeUserId == this.User.UserId()) { await _shiftRepository.DeleteTrainee(trainee); //send notification to trainer var assignment = await _shiftRepository.GetScheduledShiftAssignment(trainee.ScheduledShiftAssignmentId); var shift = await _shiftRepository.GetScheduledShift(assignment.ScheduledShiftId); //this shouldn't really happen since we don't let people sign up to train on empty assignments, but just in case if (assignment.AssignedUserId.HasValue) { var trainer = await _userRepository.GetUser(assignment.AssignedUserId.Value); var patrol = await _patrolRepository.GetPatrol(shift.PatrolId); var traineeUser = await _userRepository.GetUser(trainee.TraineeUserId); await _emailService.SendTraineeCancel(trainer, traineeUser, patrol, shift); } return(Ok()); } else { return(Forbid()); } }