Beispiel #1
0
        private Rock.Model.Group GetMembershipGroup(CheckInPerson person, Rock.Model.Group group)
        {
            group.LoadAttributes();
            var membershipGroupGuid = group.GetAttributeValue("Group");

            if (membershipGroupGuid == null)
            {
                return(null);
            }
            var membershipGroup = new GroupService(_rockContext).Get(membershipGroupGuid.AsGuid());

            return(membershipGroup);
        }
Beispiel #2
0
        /// <summary>
        /// Binds the group members progress repeater.
        /// </summary>
        protected void BindGroupMembersProgressGrid(Group group, GroupMember gMember, RockContext rockContext)
        {
            IQueryable <GroupMember> groupMembersQuery;

            if (gMember != null)
            {
                groupMembersQuery = new GroupMemberService(rockContext).Queryable().Where(a => a.Id == gMember.Id);

                pnlHeader.Visible = false;
            }
            else
            {
                groupMembersQuery = new GroupMemberService(rockContext).Queryable().Where(a => a.GroupId == group.Id);
            }

            group.LoadAttributes(rockContext);
            var defaultIndividualFundRaisingGoal = group.GetAttributeValue("IndividualFundraisingGoal").AsDecimalOrNull();

            groupMembersQuery = groupMembersQuery.Sort(new SortProperty {
                Property = "Person.LastName, Person.NickName"
            });

            var entityTypeIdGroupMember = EntityTypeCache.GetId <Rock.Model.GroupMember>();

            var groupMemberList = groupMembersQuery.ToList().Select(a =>
            {
                var groupMember = a;
                groupMember.LoadAttributes(rockContext);

                var contributionTotal = new FinancialTransactionDetailService(rockContext).Queryable()
                                        .Where(d => d.EntityTypeId == entityTypeIdGroupMember &&
                                               d.EntityId == groupMember.Id)
                                        .Sum(d => ( decimal? )d.Amount) ?? 0;

                var individualFundraisingGoal          = groupMember.GetAttributeValue("IndividualFundraisingGoal").AsDecimalOrNull();
                bool disablePublicContributionRequests = groupMember.GetAttributeValue("DisablePublicContributionRequests").AsBoolean();
                if (!individualFundraisingGoal.HasValue)
                {
                    individualFundraisingGoal = group.GetAttributeValue("IndividualFundraisingGoal").AsDecimalOrNull();
                }

                decimal percentageAchieved = 0;
                if (individualFundraisingGoal != null)
                {
                    percentageAchieved = individualFundraisingGoal == 0 ? 100 : contributionTotal / (0.01M * individualFundraisingGoal.Value);
                }

                var progressBarWidth = percentageAchieved;

                if (percentageAchieved >= 100)
                {
                    progressBarWidth = 100;
                }

                if (!individualFundraisingGoal.HasValue)
                {
                    individualFundraisingGoal = 0;
                }

                return(new
                {
                    groupMember.Person.FullName,
                    groupMember.Person.NickName,
                    groupMember.Person.LastName,
                    GroupName = group.Name,
                    IndividualFundraisingGoal = (individualFundraisingGoal ?? 0.00M).ToString("0.##"),
                    ContributionTotal = contributionTotal.ToString("0.##"),
                    Percentage = percentageAchieved.ToString("0.##"),
                    CssClass = GetProgressCssClass(percentageAchieved),
                    ProgressBarWidth = progressBarWidth
                });
            }).ToList();

            Session["IndividualData"] = groupMemberList;

            this.GroupIndividualFundraisingGoal = groupMemberList.Sum(a => decimal.Parse(a.IndividualFundraisingGoal));
            this.GroupContributionTotal         = groupMemberList.Sum(a => decimal.Parse(a.ContributionTotal));
            this.PercentComplete  = decimal.Round(this.GroupIndividualFundraisingGoal == 0 ? 100 : this.GroupContributionTotal / (this.GroupIndividualFundraisingGoal * 0.01M), 2);
            this.ProgressCssClass = GetProgressCssClass(this.PercentComplete);

            rptFundingProgress.DataSource = groupMemberList;
            rptFundingProgress.DataBind();
        }