コード例 #1
0
        /// <summary>
        /// Send email with a list of roles applied to new users in set groups
        /// </summary>
        /// <param name="graphServiceClient"></param>
        /// <param name="groups"></param>
        /// <returns></returns>
        public async static Task SendGridEmailNewGroups(List <string> groups)
        {
            List <KeyValuePair <string, string> >     accounts   = ReadCsv.GetEmailAccounts();
            List <SendGrid.Helpers.Mail.EmailAddress> recipients = new List <SendGrid.Helpers.Mail.EmailAddress>();

            foreach (var account in accounts)
            {
                string name    = account.Key;
                string address = account.Value;

                var emailAddress = new SendGrid.Helpers.Mail.EmailAddress()
                {
                    Name  = name,
                    Email = address
                };
                recipients.Add(emailAddress);
            }
            await SendGridNewGroupRolesEmail(groups, recipients);
        }
コード例 #2
0
        /// <summary>
        /// Send error email
        /// </summary>
        /// <param name="errorMessage"></param>
        /// <param name="exMsg"></param>
        /// <returns></returns>
        public async static Task SendGridErrorEmail(string errorMessage, string exMsg)
        {
            List <KeyValuePair <string, string> >     accounts   = ReadCsv.GetEmailAccounts();
            List <SendGrid.Helpers.Mail.EmailAddress> recipients = new List <SendGrid.Helpers.Mail.EmailAddress>();

            foreach (var account in accounts)
            {
                string name    = account.Key;
                string address = account.Value;

                var emailAddress = new SendGrid.Helpers.Mail.EmailAddress()
                {
                    Name  = name,
                    Email = address
                };
                recipients.Add(emailAddress);
            }
            await SendGridErrorEmail(errorMessage, exMsg, recipients);
        }
コード例 #3
0
        /// <summary>
        /// Assign roles to all groups in GroupRoles.csv
        /// </summary>
        /// <param name="graphServiceClient"></param>
        /// <param name="userId"></param>
        /// <param name="roleName"></param>
        /// <returns></returns>
        public async static Task AssignRoles(GraphServiceClient graphServiceClient)
        {
            try
            {
                List <KeyValuePair <string, string> > groupRoleDict = await ReadCsv.GetGroupRoles(graphServiceClient);

                var directoryRole = await graphServiceClient.DirectoryRoles.Request().GetAsync();

                var directoryRoleTemplate = await graphServiceClient.DirectoryRoleTemplates.Request().GetAsync();

                var groups = await graphServiceClient.Groups.Request().GetAsync();

                List <string> newMembersList = new List <string>();

                foreach (KeyValuePair <string, string> entry in groupRoleDict)
                {
                    List <string> members  = new List <string>();
                    string        groupId  = entry.Key;
                    string        roleName = entry.Value;

                    members = await GetMembersfromGroup(graphServiceClient : graphServiceClient, groupId : groupId, roleName : roleName, groups : groups,
                                                        directoryRole : directoryRole, directoryRoleTemplate : directoryRoleTemplate);

                    if (members != null)
                    {
                        newMembersList.AddRange(members);
                    }
                }
                //EMAIL here
                //await Email.SendEmailNewGroups(graphServiceClient, newMembersList);
                await Email.SendGridEmailNewGroups(newMembersList);
            }
            catch (ArgumentException ex)
            {
                string errorMsg = "Failed to assign roles in AssignRoles method.";
                string exMsg    = ex.Message;
                await ErrorHandling.ErrorEvent(errorMsg, exMsg);
            }
        }