private void ProcessChildGroups(Group group, string webUrl, string accessToken)
        {
            // relink all child groups; if the root group is being deleted, set children parent ids to 0; if
            // a sub-group is deleted, set child parent ids to parent id of sub-group
            var childGroups      = _groupRepository.GetAll(webUrl, accessToken, "&$filter=(ParentId eq " + group.Id + ")");
            var childClauses     = _clauseRepository.GetAll(webUrl, accessToken, "&$filter=(GroupId eq " + group.Id + ")");
            var newChildParentId = group.ParentId > 0 ? group.ParentId : 0;

            foreach (var childGroup in childGroups)
            {
                var ownerId = childGroup.Owner.Id;
                childGroup.ParentId = newChildParentId;
                childGroup.ToClient = false;
                childGroup.OwnerId  = ownerId;
                _groupRepository.Update(webUrl, accessToken, childGroup);
            }

            foreach (var childClause in childClauses)
            {
                var ownerId = childClause.Owner.Id;
                childClause.GroupId  = newChildParentId;
                childClause.ToClient = false;
                childClause.OwnerId  = ownerId;
                _clauseRepository.Update(webUrl, accessToken, childClause);
            }
        }
Пример #2
0
        /// <summary>
        /// Gets all clauses.
        /// </summary>
        /// <param name="webUrl">The web URL.</param>
        /// <param name="accessToken">The access token.</param>
        /// <param name="query">The query.</param>
        /// <param name="currentUserEmail">The current user email.</param>
        /// <param name="isUserAdmin">if set to <c>true</c> [is user admin].</param>
        public override IEnumerable <Clause> GetAll(string webUrl, string accessToken, string query, string currentUserEmail, bool isUserAdmin)
        {
            var clauses = _clauseRepository.GetAll(webUrl, accessToken, query).Select(t =>
            {
                t.ToClient = true;
                return(t);
            }).ToList();

            return(BuildClauses(clauses, webUrl, accessToken, currentUserEmail, isUserAdmin));
        }
        /// <summary>
        /// Get all ListItems from SharePoint List
        /// </summary>
        /// <param name="webUrl">URL of SharePoint Web which contains the list</param>
        /// <param name="accessToken">OAuth Access Token to be used as authentication with SharePoint REST API</param>
        /// <param name="query">OData Query Parameters</param>
        /// <returns>All List Items</returns>
        public virtual IEnumerable <T> GetAll(string webUrl, string query = "", string accessToken = "")
        {
            accessToken = GetAccessToken(accessToken);
            var results = Repository.GetAll(webUrl, accessToken, query).Select(t =>
            {
                t.ToClient = true;
                return(t);
            }).ToList();

            return(results);
        }
        private IEnumerable <Group> BuildGroups(IEnumerable <Group> groups, string webUrl, string accessToken,
                                                string currentUserEmail, bool isUserAdmin)
        {
            // retrieve groups
            var allGroups = _groupRepository.GetAll(webUrl, accessToken, "").ToList();

            return(groups.Select(group =>
            {
                var parentGroup = allGroups.SingleOrDefault(g => g.Id == group.ParentId);
                if (parentGroup != null)
                {
                    group.IsLocked = parentGroup.IsLocked;
                    group.ParentGroupTitle = parentGroup.Title;
                }
                else
                {
                    group.ParentGroupTitle = "Ungrouped";
                }
                group.ToClient = true;
                group.DesigneesList = group.Designees != null ? group.Designees.results : new List <SharePointUser>();
                return SetGroupOwnership(group, parentGroup, currentUserEmail, isUserAdmin);
            }));
        }
Пример #5
0
        private IEnumerable <Clause> BuildClauses(IEnumerable <Clause> clauses, string webUrl, string accessToken,
                                                  string currentUserEmail, bool isUserAdmin)
        {
            // retrieve tags
            var tags = _tagRepository.GetAll(webUrl, accessToken, "").ToList();

            // retrieve favorites
            var favourites = _favouritesRepository.GetAll(webUrl, accessToken, "").ToList();

            // retrieve external links
            var externalLinks = _externalLinksRepository.GetAll(webUrl, accessToken, "").ToList();

            // retrieve groups
            var groups = _groupRepository.GetAll(webUrl, accessToken, "").ToList();

            var buildClauses = clauses as IList <Clause> ?? clauses.ToList();

            return(buildClauses.Select(clause =>
            {
                var tempSearchKeys = new List <string>();
                var titleTokens = clause.Title.Split(' ');
                tempSearchKeys.Add(clause.Title);
                titleTokens.ForEach(tempSearchKeys.Add);
                var tagIds = clause.Tags ?? string.Empty;

                if (!string.IsNullOrWhiteSpace(tagIds))
                {
                    //split and parse
                    var tagList =
                        tagIds.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
                        .Select(int.Parse)
                        .ToList();
                    clause.TagsList = tags.Where(t => tagList.Contains(t.Id)).ToList();
                    foreach (var tag in clause.TagsList)
                    {
                        tempSearchKeys.Add(tag.Title);
                        var tagTokens = tag.Title.Split(' ');
                        tagTokens.ForEach(tempSearchKeys.Add);
                    }
                }
                else
                {
                    clause.TagsList = new List <Tag>();
                }

                if (favourites.Any())
                {
                    clause.Favourite = favourites.FirstOrDefault(f => f.ClauseId == clause.Id);
                }

                if (externalLinks.Any())
                {
                    clause.ExternalLinks = externalLinks.Where(e => e.ClauseId == clause.Id).ToList();
                    foreach (var externalLink in clause.ExternalLinks)
                    {
                        externalLink.Text = HttpUtility.UrlDecode(externalLink.Text);
                    }
                }
                else
                {
                    clause.ExternalLinks = new List <ExternalLink>();
                }

                clause.SearchIndices = tempSearchKeys;

                var clauseGroup = groups.SingleOrDefault(g => g.Id == clause.GroupId);

                List <Group> parentGroups = new List <Group>();
                // find parents recursive, to find level 1 & 2 group
                if (clauseGroup?.ParentId != null && clauseGroup.ParentId.Value > 0)
                {
                    var parentGroup = groups.SingleOrDefault(g => g.Id == clauseGroup.ParentId.Value);
                    while (parentGroup != null)
                    {
                        parentGroups.Add(parentGroup);
                        if (parentGroup.ParentId.HasValue && parentGroup.ParentId.Value > 0)
                        {
                            parentGroup = groups.SingleOrDefault(g => g.Id == parentGroup.ParentId.Value);
                        }
                        else
                        {
                            parentGroup = null;
                        }
                    }
                }

                clause = ProcessGroup(clause, clauseGroup, parentGroups);
                clause.ToClient = true;
                clause.Text = HttpUtility.UrlDecode(clause.Text);
                clause.Title = HttpUtility.UrlDecode(clause.Title);
                clause.DesigneesList = clause.Designees != null ? clause.Designees.results : new List <SharePointUser>();
                return SetClauseOwnership(clause, clauseGroup, currentUserEmail, isUserAdmin);
            }));
        }