public async Task <IActionResult> RegisterInterested(int id) { try { var meeting = await _meetingsRepository.Select.ById(id); if (meeting == null) { return(StatusCode(StatusCodes.Status404NotFound, $"There is no meeting for id = {id}")); } if (meeting.Participants.Count == meeting.MaxNumberOfParticipants) { return(StatusCode(StatusCodes.Status405MethodNotAllowed, $"Maximum number of participants has been reached")); } var username = User.Identity.Name; var account = await _accountsRepository.SelectByUsername(username); if (meeting.Participants.Contains(account)) { return(StatusCode(StatusCodes.Status405MethodNotAllowed, $"User already participates")); } await _meetingsRepository.RegisterAttendance(meeting, account); } catch (DbUpdateConcurrencyException) { return(NotFound()); } return(Ok("Participation saved")); }