public static async Task <string> CreateNewGroupPlaylistAsync( GroupPlaylistUploadModel groupPlaylistUploadModel, Guid userId, IRepositoryManager repositoryManager, IMapper mapper, SpotifyAPICredentials spotifyAPICredentials) { var groupIdentifier = groupPlaylistUploadModel.GroupIdentifier.ToUpperInvariant(); try { var group = await repositoryManager.GroupRepository.GetByIdentifierAsync(groupIdentifier); if (group != null) { var isUserMemberOfGroup = await GroupMemberModel.CheckGroupMemberExistsAsync( groupPlaylistUploadModel.GroupIdentifier, userId, repositoryManager); if (isUserMemberOfGroup) { var newGroupPlaylistIdentifier = await GenerateNewGroupPlaylistIdentifierAsync( group.Id, repositoryManager.GroupPlaylistRepository).ConfigureAwait(false); var newGroupPlaylist = new GroupPlaylist { GroupId = group.Id, Identifier = newGroupPlaylistIdentifier, CreatedOn = DateTime.Now, CreatedBy = userId, LastUpdatedOn = DateTime.Now, LastUpdatedBy = userId }; var existingPlaylist = await repositoryManager.PlaylistRepository.CheckExistsBySpotifyIdAsync( groupPlaylistUploadModel.PlaylistIdentifier); if (existingPlaylist != null) { newGroupPlaylist.PlaylistId = existingPlaylist.Id; } else { var newPlaylist = await PlaylistModel.IndexNewPlaylistAsync( groupPlaylistUploadModel.PlaylistIdentifier, userId, repositoryManager, mapper, spotifyAPICredentials); newGroupPlaylist.PlaylistId = newPlaylist.Id; } await repositoryManager.GroupPlaylistRepository.AddAsync(newGroupPlaylist); return(newGroupPlaylistIdentifier); } else { throw new UserNotGroupMemberException( "You are not able to perform this action", "You are not able to perform this action"); } } else { throw new InvalidTokenException(InvalidTokenType.TokenNotFound, "The requested Group was not found"); } } catch (Exception) { throw; } }