Esempio n. 1
0
        public ActionResult PlayWithSecurityGroups(PlayWithUsersViewModel model)
        {
            AntiForgery.Validate();

            var groups         = UsersGroupsHelper.ListGroups(100);
            var securityGroups = UsersGroupsHelper.ListSecurityGroups(100);
            var group          = UsersGroupsHelper.GetGroup(groups[0].Id);
            var owners         = UsersGroupsHelper.ListGroupOwners(group.Id);
            var members        = UsersGroupsHelper.ListGroupMembers(group.Id);

            var someone = UsersGroupsHelper.GetUser(model.UserPrincipalName);

            UsersGroupsHelper.AddMemberToGroup(someone, group.Id);
            members = UsersGroupsHelper.ListGroupMembers(group.Id);
            UsersGroupsHelper.RemoveMemberFromGroup(someone, group.Id);

            return(View("Index"));
        }
Esempio n. 2
0
        public ActionResult PlayWithUnifiedGroups(PlayWithUsersViewModel model)
        {
            AntiForgery.Validate();

            var groups         = UsersGroupsHelper.ListUnifiedGroups(100);
            var group          = UsersGroupsHelper.GetGroup(groups[0].Id);
            var owners         = UsersGroupsHelper.ListGroupOwners(group.Id);
            var members        = UsersGroupsHelper.ListGroupMembers(group.Id);
            var photo          = UsersGroupsHelper.GetGroupPhoto(group.Id);
            var calendar       = UnifiedGroupsHelper.GetUnifiedGroupCalendar(group.Id);
            var calendarEvents = UnifiedGroupsHelper.ListUnifiedGroupEvents(group.Id);
            var events         = UnifiedGroupsHelper.ListUnifiedGroupEvents(group.Id, DateTime.Now,
                                                                            DateTime.Now.AddMonths(1), 0);

            var conversations      = UnifiedGroupsHelper.ListUnifiedGroupConversations(group.Id);
            var threads            = UnifiedGroupsHelper.ListUnifiedGroupThreads(group.Id);
            var postsOfThread      = UnifiedGroupsHelper.ListUnifiedGroupThreadPosts(group.Id, threads[0].Id);
            var singlePostOfThread = UnifiedGroupsHelper.GetUnifiedGroupThreadPost(group.Id, threads[0].Id, postsOfThread[0].Id);

            UnifiedGroupsHelper.ReplyToUnifiedGroupThread(group.Id, threads[0].Id,
                                                          new Models.ConversationThreadPost
            {
                Body = new Models.ItemBody
                {
                    Type    = Models.BodyType.Html,
                    Content = "<html><body><div>This is the body of a post created via the Microsoft Graph API!</div></body></html>",
                },
                NewParticipants = new List <Models.UserInfoContainer>(
                    new Models.UserInfoContainer[] {
                    new Models.UserInfoContainer {
                        Recipient = new Models.UserInfo {
                            Name    = model.MailSendToDescription,
                            Address = model.MailSendTo,
                        }
                    }
                }),
            });

            var drive = UnifiedGroupsHelper.GetUnifiedGroupDrive(group.Id);

            var newUnifiedGroup = UnifiedGroupsHelper.AddUnifiedGroup(
                new Models.Group
            {
                DisplayName     = "Created via API",
                MailEnabled     = true,
                SecurityEnabled = false,
                GroupTypes      = new List <String>(new String[] { "Unified" }),
                MailNickname    = "APICreated",
            });

            // Wait for a while to complete Office 365 Group creation
            System.Threading.Thread.Sleep(TimeSpan.FromSeconds(30));

            MemoryStream memPhoto = new MemoryStream();

            using (FileStream fs = new FileStream(Server.MapPath("~/AppIcon.png"), FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                Byte[] newPhoto = new Byte[fs.Length];
                fs.Read(newPhoto, 0, (Int32)(fs.Length - 1));
                memPhoto.Write(newPhoto, 0, newPhoto.Length);
                memPhoto.Position = 0;
            }

            try
            {
                if (memPhoto.Length > 0)
                {
                    UnifiedGroupsHelper.UpdateUnifiedGroupPhoto(newUnifiedGroup.Id, memPhoto);
                }
            }
            catch (Exception ex)
            {
                // Handle the exception
            }

            UnifiedGroupsHelper.DeleteUnifiedGroup(newUnifiedGroup.Id);

            return(View("Index"));
        }