예제 #1
0
        public async Task <CreateGroupOutputData> Execute(CreateGroupInputData request)
        {
            CreateGroupOutputData response = null;

            try
            {
                var group = new Microsoft.Graph.Group
                {
                    DisplayName = request.Group.GroupName,
                    MailEnabled = true,
                    GroupTypes  = new List <string>
                    {
                        "Unified"
                    },
                    SecurityEnabled = false,
                    MailNickname    = TranslitHelper.Execute(request.Group.GroupName.ToLower())
                };

                var result = await Graph.Groups
                             .Request()
                             .AddAsync(group);

                response = new CreateGroupOutputData
                {
                    Group = new GroupModel(result)
                };

                logger.Information(
                    $"Type: CreateGroupActivity; Method: Execute; Info: Create group with name: {request.Group.GroupName} successfully");
            }
            catch (Exception e)
            {
                logger.Error($"Type: CreateGroupActivity; Method: Execute; Error: {e.Message}");
                throw;
            }

            return(await Task.FromResult(response));
        }
        public async Task <CreateOrAddTeamOutputData> Execute(CreateOrAddTeamInputData request)
        {
            CreateOrAddTeamOutputData response = null;

            try
            {
                foreach (var item in request.List)
                {
                    var group = new Microsoft.Graph.Group
                    {
                        DisplayName = item.Name,
                        MailEnabled = true,
                        GroupTypes  = new List <string>
                        {
                            "Unified"
                        },
                        SecurityEnabled = false,
                        MailNickname    = TranslitHelper.Execute(item.Name.Replace(" ", "").Replace(".", "").ToLower())
                    };

                    var result = await Graph.Groups
                                 .Request()
                                 .AddAsync(group);

                    var owner = new DirectoryObject
                    {
                        Id = item.OwnerGUID
                    };

                    await Graph.Groups[result.Id].Owners.References
                    .Request()
                    .AddAsync(owner);

                    var teamSettings = new Microsoft.Graph.Team
                    {
                        MemberSettings = new TeamMemberSettings
                        {
                            AllowCreatePrivateChannels = true,
                            AllowCreateUpdateChannels  = true,
                            ODataType = null
                        },
                        MessagingSettings = new TeamMessagingSettings
                        {
                            AllowUserEditMessages   = true,
                            AllowUserDeleteMessages = true,
                            ODataType = null
                        },
                        FunSettings = new TeamFunSettings
                        {
                            AllowGiphy         = true,
                            GiphyContentRating = GiphyRatingType.Strict,
                            ODataType          = null
                        },
                        ODataType = null
                    };

                    var team = await Graph.Groups[result.Id].Team
                               .Request()
                               .PutAsync(teamSettings);


                    var conversationMember = new AadUserConversationMember
                    {
                        AdditionalData = new Dictionary <string, object>()
                    };

                    foreach (var row in item.ParticipantsList)
                    {
                        conversationMember.AdditionalData.Add(
                            "*****@*****.**", $"https://graph.microsoft.com/v1.0/users('{row}')");
                    }

                    await Graph.Teams[team.Id].Members
                    .Request()
                    .AddAsync(conversationMember);
                }

                response = new CreateOrAddTeamOutputData();

                logger.Information(
                    "Type: CreateOrAddTeamActivity; Method: Execute; Info: Create team for request successfully");
            }
            catch (Exception e)
            {
                logger.Error($"Type: CreateOrAddTeamActivity; Method: Execute; Error: {e.Message}");
                throw;
            }

            return(await Task.FromResult(response));
        }