public async Task <IActionResult> AddParticipant(int shiftId, string memberId) { // Shift exists? // Member exists? if (!(await _shiftService.Exists(shiftId)) || !(await _memberService.Exists(memberId))) { return(BadRequest()); } Shift shift = await _shiftService.GetShift(shiftId); Member member = await _memberService.GetMember(memberId); // User has access to shift? string userId = _userManager.GetUserId(User); if (!(await _userService.HasShiftAccess(userId, shiftId))) { return(BadRequest()); } // Can member participate in shift? if (!(await _userService.HasShiftAccess(member.UserId, shiftId))) { return(BadRequest()); } // If member is not self, is there permission to add? if (member.UserId != userId && !member.Group.UsersCanScheduleOthers) { return(BadRequest()); } // Can shift accept another participant? if (!shift.AcceptingParticipants) { return(BadRequest()); } // Check if member is already a participant if (await _shiftService.HasParticipant(shiftId, memberId)) { return(BadRequest()); } await _shiftService.AddParticipant(shiftId, memberId); return(Ok()); }