diff --git a/src/sdk/PnP.Core/Model/Teams/Internal/TeamChannelCollection.cs b/src/sdk/PnP.Core/Model/Teams/Internal/TeamChannelCollection.cs
index 96a5a0cb45..98c51f146a 100644
--- a/src/sdk/PnP.Core/Model/Teams/Internal/TeamChannelCollection.cs
+++ b/src/sdk/PnP.Core/Model/Teams/Internal/TeamChannelCollection.cs
@@ -17,6 +17,18 @@ public TeamChannelCollection(PnPContext context, IDataModelParent parent, string
#region Add methods
+ ///
+ /// Adds a new channel
+ ///
+ /// Display name of the channel
+ /// Options for creating the channel
+ /// Newly added channel
+ public async Task AddAsync(string name, TeamChannelOptions options)
+ {
+ var newChannel = CreateNewAndAdd(name, options);
+ return await newChannel.AddAsync().ConfigureAwait(false) as TeamChannel;
+ }
+
///
/// Adds a new channel
///
@@ -25,20 +37,18 @@ public TeamChannelCollection(PnPContext context, IDataModelParent parent, string
/// Newly added channel
public async Task AddAsync(string name, string description = null)
{
- if (string.IsNullOrEmpty(name))
- {
- throw new ArgumentNullException(nameof(name));
- }
-
- // TODO: validate name restrictions
-
- var newChannel = CreateNewAndAdd() as TeamChannel;
-
- // Assign field values
- newChannel.DisplayName = name;
- newChannel.Description = description;
+ return await AddAsync(name, new TeamChannelOptions(description)).ConfigureAwait(false);
+ }
- return await newChannel.AddAsync().ConfigureAwait(false) as TeamChannel;
+ ///
+ /// Adds a new channel
+ ///
+ /// Display name of the channel
+ /// Options for creating the channel
+ /// Newly added channel
+ public ITeamChannel Add(string name, TeamChannelOptions options)
+ {
+ return AddAsync(name, options).GetAwaiter().GetResult();
}
///
@@ -52,6 +62,19 @@ public ITeamChannel Add(string name, string description = null)
return AddAsync(name, description).GetAwaiter().GetResult();
}
+ ///
+ /// Adds a new channel
+ ///
+ /// Batch to use
+ /// Display name of the channel
+ /// Options for creating the channel
+ /// Newly added channel
+ public async Task AddBatchAsync(Batch batch, string name, TeamChannelOptions options)
+ {
+ var newChannel = CreateNewAndAdd(name, options);
+ return await newChannel.AddBatchAsync(batch).ConfigureAwait(false) as TeamChannel;
+ }
+
///
/// Adds a new channel
///
@@ -61,18 +84,19 @@ public ITeamChannel Add(string name, string description = null)
/// Newly added channel
public async Task AddBatchAsync(Batch batch, string name, string description = null)
{
- if (string.IsNullOrEmpty(name))
- {
- throw new ArgumentNullException(nameof(name));
- }
-
- var newChannel = CreateNewAndAdd() as TeamChannel;
-
- // Assign field values
- newChannel.DisplayName = name;
- newChannel.Description = description;
+ return await AddBatchAsync(name, new TeamChannelOptions(description)).ConfigureAwait(false);
+ }
- return await newChannel.AddBatchAsync(batch).ConfigureAwait(false) as TeamChannel;
+ ///
+ /// Adds a new channel
+ ///
+ /// Batch to use
+ /// Display name of the channel
+ /// Options for creating the channel
+ /// Newly added channel
+ public ITeamChannel AddBatch(Batch batch, string name, TeamChannelOptions options)
+ {
+ return AddBatchAsync(batch, name, options).GetAwaiter().GetResult();
}
///
@@ -87,6 +111,17 @@ public ITeamChannel AddBatch(Batch batch, string name, string description = null
return AddBatchAsync(batch, name, description).GetAwaiter().GetResult();
}
+ ///
+ /// Adds a new channel
+ ///
+ /// Display name of the channel
+ /// Options for creating the channel
+ /// Newly added channel
+ public async Task AddBatchAsync(string name, TeamChannelOptions options)
+ {
+ return await AddBatchAsync(PnPContext.CurrentBatch, name, options).ConfigureAwait(false);
+ }
+
///
/// Adds a new channel
///
@@ -98,6 +133,17 @@ public async Task AddBatchAsync(string name, string description =
return await AddBatchAsync(PnPContext.CurrentBatch, name, description).ConfigureAwait(false);
}
+ ///
+ /// Adds a new channel
+ ///
+ /// Display name of the channel
+ /// Options for creating the channel
+ /// Newly added channel
+ public ITeamChannel AddBatch(string name, TeamChannelOptions options)
+ {
+ return AddBatchAsync(name, options).GetAwaiter().GetResult();
+ }
+
///
/// Adds a new channel
///
@@ -109,6 +155,32 @@ public ITeamChannel AddBatch(string name, string description = null)
return AddBatchAsync(name, description).GetAwaiter().GetResult();
}
+ ///
+ /// Creates a new `TeamChannel` instance,
+ /// adds it to the collection and configures it.
+ ///
+ /// Display name of the channel
+ /// Options for creating the channel
+ ///
+ /// Missing name argument
+ private TeamChannel CreateNewAndAdd(string name, TeamChannelOptions options)
+ {
+ if (string.IsNullOrEmpty(name))
+ {
+ throw new ArgumentNullException(nameof(name));
+ }
+
+ // TODO: validate name restrictions
+
+ var newChannel = CreateNewAndAdd() as TeamChannel;
+
+ newChannel.DisplayName = name;
+ newChannel.Description = options.Description;
+ if(options.MembershipType.HasValue) newChannel.MembershipType = options.MembershipType.Value;
+
+ return newChannel;
+ }
+
#endregion
#region GetByDisplayName methods
diff --git a/src/sdk/PnP.Core/Model/Teams/Public/ITeamChannelCollection.cs b/src/sdk/PnP.Core/Model/Teams/Public/ITeamChannelCollection.cs
index 56fe2f7e6b..e543621e0b 100644
--- a/src/sdk/PnP.Core/Model/Teams/Public/ITeamChannelCollection.cs
+++ b/src/sdk/PnP.Core/Model/Teams/Public/ITeamChannelCollection.cs
@@ -14,6 +14,14 @@ namespace PnP.Core.Model.Teams
public interface ITeamChannelCollection : IQueryable, IAsyncEnumerable, IDataModelCollection, IDataModelCollectionLoad, IDataModelCollectionDeleteByStringId, ISupportModules
{
#region Add methods
+
+ ///
+ /// Adds a new channel
+ ///
+ /// Display name of the channel
+ /// Options for creating the channel
+ /// Newly added channel
+ public Task AddAsync(string name, TeamChannelOptions options);
///
/// Adds a new channel
@@ -22,6 +30,14 @@ public interface ITeamChannelCollection : IQueryable, IAsyncEnumer
/// Optional description of the channel
/// Newly added channel
public Task AddAsync(string name, string description = null);
+
+ ///
+ /// Adds a new channel
+ ///
+ /// Display name of the channel
+ /// Options for creating the channel
+ /// Newly added channel
+ public ITeamChannel Add(string name, TeamChannelOptions options);
///
/// Adds a new channel
@@ -31,6 +47,15 @@ public interface ITeamChannelCollection : IQueryable, IAsyncEnumer
/// Newly added channel
public ITeamChannel Add(string name, string description = null);
+ ///
+ /// Adds a new channel
+ ///
+ /// Batch to use
+ /// Display name of the channel
+ /// Options for creating the channel
+ /// Newly added channel
+ public Task AddBatchAsync(Batch batch, string name, TeamChannelOptions options);
+
///
/// Adds a new channel
///
@@ -39,6 +64,15 @@ public interface ITeamChannelCollection : IQueryable, IAsyncEnumer
/// Optional description of the channel
/// Newly added channel
public Task AddBatchAsync(Batch batch, string name, string description = null);
+
+ ///
+ /// Adds a new channel
+ ///
+ /// Batch to use
+ /// Display name of the channel
+ /// Options for creating the channel
+ /// Newly added channel
+ public ITeamChannel AddBatch(Batch batch, string name, TeamChannelOptions options);
///
/// Adds a new channel
@@ -48,6 +82,14 @@ public interface ITeamChannelCollection : IQueryable, IAsyncEnumer
/// Optional description of the channel
/// Newly added channel
public ITeamChannel AddBatch(Batch batch, string name, string description = null);
+
+ ///
+ /// Adds a new channel
+ ///
+ /// Display name of the channel
+ /// Options for creating the channel
+ /// Newly added channel
+ public Task AddBatchAsync(string name, TeamChannelOptions options);
///
/// Adds a new channel
@@ -56,6 +98,14 @@ public interface ITeamChannelCollection : IQueryable, IAsyncEnumer
/// Optional description of the channel
/// Newly added channel
public Task AddBatchAsync(string name, string description = null);
+
+ ///
+ /// Adds a new channel
+ ///
+ /// Display name of the channel
+ /// Options for creating the channel
+ /// Newly added channel
+ public ITeamChannel AddBatch(string name, TeamChannelOptions options);
///
/// Adds a new channel
diff --git a/src/sdk/PnP.Core/Model/Teams/Public/Options/TeamChannelOptions.cs b/src/sdk/PnP.Core/Model/Teams/Public/Options/TeamChannelOptions.cs
new file mode 100644
index 0000000000..456f250d5e
--- /dev/null
+++ b/src/sdk/PnP.Core/Model/Teams/Public/Options/TeamChannelOptions.cs
@@ -0,0 +1,30 @@
+namespace PnP.Core.Model.Teams
+{
+ ///
+ /// Available options for Teams channel
+ ///
+ public class TeamChannelOptions
+ {
+ ///
+ /// Gets or sets the channel description.
+ ///
+ public string Description { get; set; }
+
+ ///
+ /// Gets or sets the channel membership type.
+ ///
+ /// The membership type cannot be changed for existing channels.
+ ///
+ public TeamChannelMembershipType? MembershipType { get; set; }
+
+ ///
+ /// Creates a new `TeamChannelOptions` instance
+ /// with the provided description.
+ ///
+ /// The channel description.
+ public TeamChannelOptions(string description = null)
+ {
+ Description = description;
+ }
+ }
+}
\ No newline at end of file