Exemple #1
0
        public void AddToFavorites()
        {
            base.ThrowIfCannotActAsOwner();
            OwaStoreObjectId owaStoreObjectId = (OwaStoreObjectId)base.GetParameter("Id");

            if (owaStoreObjectId.OwaStoreObjectIdType != OwaStoreObjectIdType.MailBoxObject && owaStoreObjectId.OwaStoreObjectIdType != OwaStoreObjectIdType.ArchiveMailboxObject)
            {
                throw new OwaInvalidRequestException("Only mailbox objects can be added to favorites.");
            }
            using (Folder folder = Utilities.GetFolder <Folder>(base.UserContext, owaStoreObjectId, FolderList.FolderTreeQueryProperties))
            {
                if (Utilities.IsDefaultFolder(folder, DefaultFolderType.Root))
                {
                    throw new OwaInvalidRequestException("Cannot add root folder to favorites.");
                }
                if (!string.IsNullOrEmpty(folder.ClassName) && !ObjectClass.IsOfClass(folder.ClassName, "IPF.Note"))
                {
                    throw new OwaInvalidRequestException("Only mail folder can be added to favorites.");
                }
                if (Utilities.IsDefaultFolder(folder, DefaultFolderType.SearchFolders))
                {
                    throw new OwaInvalidRequestException("Cannot add search folder root to favorites.");
                }
                NavigationNodeCollection navigationNodeCollection = NavigationNodeCollection.TryCreateNavigationNodeCollection(base.UserContext, base.UserContext.MailboxSession, NavigationNodeGroupSection.First);
                navigationNodeCollection.RemoveFolderByLegacyDNandId(((MailboxSession)folder.Session).MailboxOwnerLegacyDN, owaStoreObjectId.StoreObjectId);
                if (base.IsParameterSet("tgtid"))
                {
                    StoreObjectId storeObjectId = (StoreObjectId)base.GetParameter("tgtid");
                }
                if (base.IsParameterSet("tgtid"))
                {
                    int num = navigationNodeCollection[0].Children.FindChildByNodeId((StoreObjectId)base.GetParameter("tgtid"));
                    if (num < 0)
                    {
                        base.RenderPartialFailure(817935633, OwaEventHandlerErrorCode.NotSet);
                    }
                    else
                    {
                        if (base.IsParameterSet("mt"))
                        {
                            int num2 = (int)base.GetParameter("mt");
                            if (num2 != 1 && num2 != 2)
                            {
                                throw new OwaInvalidRequestException("Only before or after is valid.");
                            }
                            if (num2 == 2)
                            {
                                num++;
                            }
                        }
                        navigationNodeCollection.InsertMyFolderToFavorites(folder, num);
                    }
                }
                else
                {
                    navigationNodeCollection.AppendFolderToFavorites(folder);
                }
                navigationNodeCollection.Save(base.UserContext.MailboxSession);
            }
            NavigationHost.RenderFavoritesAndNavigationTrees(this.Writer, base.UserContext, null, new NavigationNodeGroupSection[]
            {
                NavigationNodeGroupSection.First
            });
        }