예제 #1
0
        public PaginatedList <OrganizationCard> PendingOrganizationAccess(Guid personId)
        {
            PaginatedList <OrganizationCard> cards = new PaginatedList <OrganizationCard>();

            _accessRequestRepo.ForceIgnoreSecurity();
            var accessRequests = _accessRequestRepo.Find(null, ar => ar.IsAccessRequested.HasValue && ar.IsAccessRequested.Value && ar.PersonId == personId, ar => ar.AccessRequestedOn, OrderByDirectionType.Descending);

            _accessRequestRepo.ForceSecurity();
            var orgIds = accessRequests.Items.Select(om => om.OrganizationId).Distinct().ToArray();

            if (orgIds.Length > 0)
            {
                var orgs = _organizationRepo.Find(null, o => orgIds.Contains(o.Id), o => o.Name, OrderByDirectionType.Ascending);

                foreach (Organization org in orgs.Items)
                {
                    OrganizationCard card = new OrganizationCard
                    {
                        Id                   = org.Id.Value,
                        Name                 = org.Name,
                        CreatedOn            = org.CreatedOn,
                        IsOrganizationMember = false
                    };
                    //card.CanLeave = true;
                    //var orgMem = orgMems.Items.Where(om => om.OrganizationId == org.Id).FirstOrDefault();
                    //if (orgMem != null)
                    //{
                    //    card.JoinedOn = orgMem.CreatedOn;
                    //    if (orgMem.IsAdministrator.HasValue && orgMem.IsAdministrator.Value)
                    //        card.CanDelete = true;
                    //}
                    Guid creatorPersonId = Guid.Empty;
                    if (Guid.TryParse(org.CreatedBy, out creatorPersonId))
                    {
                        Person creatorPerson = _personRepo.GetOne(creatorPersonId);
                        if (creatorPerson != null)
                        {
                            card.CreatedBy = string.Format("{0}", creatorPerson.Name);
                        }
                    }
                    if (string.IsNullOrEmpty(card.CreatedBy))
                    {
                        card.CreatedBy = org.CreatedBy;
                    }

                    cards.Add(card);
                }
            }

            return(cards);
        }
        public PaginatedList <OrganizationCard> MyOrganizations(Guid personId, bool IncludeAccessRequestedOrg = false)
        {
            _organzationMemberRepo.ForceIgnoreSecurity();
            var orgMems = _organzationMemberRepo.Find(null, om => om.PersonId.Equals(personId));
            var orgIds  = orgMems.Items.Select(om => om.OrganizationId).Distinct().ToArray();
            var orgs    = _organizationRepo.Find(null, o => orgIds.Contains(o.Id));

            _organzationMemberRepo.ForceSecurity();


            PaginatedList <OrganizationCard> cards = new PaginatedList <OrganizationCard>();

            foreach (Organization org in orgs.Items)
            {
                OrganizationCard card = new OrganizationCard
                {
                    Id        = org.Id.Value,
                    Name      = org.Name,
                    CreatedOn = org.CreatedOn,
                    CanLeave  = true
                };
                var orgMem = orgMems.Items.Where(om => om.OrganizationId == org.Id).FirstOrDefault();
                if (orgMem != null)
                {
                    card.JoinedOn             = orgMem.CreatedOn;
                    card.IsOrganizationMember = true;
                    if (orgMem.IsAdministrator.HasValue && orgMem.IsAdministrator.Value)
                    {
                        card.CanDelete = true;
                    }
                }
                Guid creatorPersonId = Guid.Empty;
                if (Guid.TryParse(org.CreatedBy, out creatorPersonId))
                {
                    Person creatorPerson = _personRepo.GetOne(creatorPersonId);
                    if (creatorPerson != null)
                    {
                        card.CreatedBy = string.Format("{0}", creatorPerson.Name);
                    }
                }
                if (string.IsNullOrEmpty(card.CreatedBy))
                {
                    card.CreatedBy = org.CreatedBy;
                }


                cards.Add(card);
            }

            if (IncludeAccessRequestedOrg)
            {
                //organizations requested for access
                var accessRequest = PendingOrganizationAccess(personId);
                if (accessRequest?.Items?.Count > 0)
                {
                    cards.Items.AddRange(accessRequest.Items);
                }
            }

            cards.ParentId   = personId;
            cards.TotalCount = cards.Items.Count;
            return(cards);
        }