GetGlobalAttributeValue() public method

Returns a Rock.Model.AttributeValue for a Rock.Model.Attribute by Key.
public GetGlobalAttributeValue ( string key ) : AttributeValue
key string A representing the name of the Global Attribute's key value.
return AttributeValue
Ejemplo n.º 1
0
        public void Execute(IJobExecutionContext context)
        {
            JobDataMap dataMap = context.JobDetail.JobDataMap;
            string livePlatformUrl = dataMap.GetString("Address") ?? "http://live.newpointe.org/api/v1/events/current";

            //Check ChurchOnline Platform API to see if there is a live event

            using (WebClient wc = new WebClient())
            {
                LivePlatformUrlJson = wc.DownloadString(livePlatformUrl);
            }

            dynamic isServiceLive = JsonConvert.DeserializeObject(LivePlatformUrlJson);

            string isLive = isServiceLive.response.item.isLive.ToString();

            // specify which attribute key we want to work with
            var attributeKey = "LiveService";  //production

            var attributeValueService = new AttributeValueService(rockContext);

            // specify NULL as the EntityId since this is a GlobalAttribute
            var globalAttributeValue = attributeValueService.GetGlobalAttributeValue(attributeKey);

            if (globalAttributeValue != null)
            {
                // save updated value to database
                globalAttributeValue.Value = isLive;
                rockContext.SaveChanges();

                // flush the attributeCache for this attribute so it gets reloaded from the database
                //Rock.Web.Cache.AttributeCache.Flush();

                // flush the GlobalAttributeCache since this attribute is a GlobalAttribute
                Rock.Web.Cache.GlobalAttributesCache.Flush();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets the value.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        /// <param name="saveValue">if set to <c>true</c> [save value].</param>
        /// <param name="rockContext">The rock context.</param>
        public void SetValue( string key, string value, bool saveValue, RockContext rockContext = null )
        {
            if ( saveValue )
            {
                if ( rockContext == null )
                {
                    rockContext = new RockContext();
                }

                // Save new value
                var attributeValueService = new AttributeValueService( rockContext );
                var attributeValue = attributeValueService.GetGlobalAttributeValue( key );

                if ( attributeValue == null )
                {
                    var attributeService = new AttributeService( rockContext );
                    var attribute = attributeService.GetGlobalAttribute( key );
                    if ( attribute == null )
                    {
                        attribute = new Rock.Model.Attribute();
                        attribute.FieldTypeId = FieldTypeCache.Read( new Guid( SystemGuid.FieldType.TEXT ) ).Id;
                        attribute.EntityTypeQualifierColumn = string.Empty;
                        attribute.EntityTypeQualifierValue = string.Empty;
                        attribute.Key = key;
                        attribute.Name = key.SplitCase();
                        attributeService.Add( attribute );
                        rockContext.SaveChanges();

                        Attributes.Add( AttributeCache.Read( attribute.Id ) );
                    }

                    attributeValue = new AttributeValue();
                    attributeValueService.Add( attributeValue );
                    attributeValue.IsSystem = false;
                    attributeValue.AttributeId = attribute.Id;

                    if ( !AttributeValues.Keys.Contains( key ) )
                    {
                        AttributeValues.Add( key, new KeyValuePair<string, string>( attribute.Name, value ) );
                    }
                }

                attributeValue.Value = value;
                rockContext.SaveChanges();
            }

            var attributeCache = Attributes.FirstOrDefault( a => a.Key.Equals( key, StringComparison.OrdinalIgnoreCase ) );
            if ( attributeCache != null ) // (Should never be null)
            {
                if ( AttributeValues.Keys.Contains( key ) )
                {
                    AttributeValues[key] = new KeyValuePair<string, string>( attributeCache.Name, value );
                }
                else
                {
                    AttributeValues.Add( key, new KeyValuePair<string, string>( attributeCache.Name, value ) );
                }
            }
        }
Ejemplo n.º 3
0
        protected void CalulateMetrics(int CampusId)
        {
            // specify which attribute key we want to work with
            var attributeKeyCompositeUseGlobalValue = "CompositeUseGlobalValue";
            var attributeKeyCompositeGoalMultiplier = "CompositeGoalMultiplier";

            var attributeValueService = new AttributeValueService(rockContext);

            // specify NULL as the EntityId since this is a GlobalAttribute
            var compositeUseGlobalValue = attributeValueService.GetGlobalAttributeValue(attributeKeyCompositeUseGlobalValue);
            var compositeGoalMultiplier = attributeValueService.GetGlobalAttributeValue(attributeKeyCompositeGoalMultiplier);

            if (bool.Parse(compositeUseGlobalValue.ToString()) == true)
            {
                UseGlobalAttributeGoal = true;
                GoalMultiplier = Convert.ToDouble(compositeGoalMultiplier.ToString());
            }

            //Set Last Sunday Date
            DateTime now = DateTime.Now;
            DateTime dt = DateTime.Now.StartOfWeek(DayOfWeek.Sunday);
            SundayDate = dt.ToShortDateString();
            SundayDateSQLFormatted = dt.Date.ToString("yyyy-MM-dd");

            DateTime lastTuesday = DateTime.Now.AddDays(-1);
            while (lastTuesday.DayOfWeek != DayOfWeek.Wednesday)
                lastTuesday = lastTuesday.AddDays(-1);

            DateTime lastWednesday = DateTime.Now.AddDays(-1);
            while (lastWednesday.DayOfWeek != DayOfWeek.Wednesday)
                lastWednesday = lastWednesday.AddDays(-1);

            FinancialStartDate = lastTuesday.AddDays(-7).ToString("yyyy-MM-dd");
            FinancialEndDate = lastWednesday.ToString("yyyy-MM-dd");

            FinancialStartDateLastWeek = lastTuesday.AddDays(-14).ToString("yyyy-MM-dd");
            FinancialEndDateLastWeek = lastWednesday.AddDays(-7).ToString("yyyy-MM-dd");

            sMonth = DateTime.Now.Month.ToString();
            sYear = DateTime.Now.Year.ToString();
            int iMonth = Int32.Parse(sMonth);
            int iYear = Int32.Parse(sYear);

            int lastDayOfCurrentMonth = DateTime.DaysInMonth(iYear, iMonth);
            int lastDayOfLastMonth = DateTime.DaysInMonth(iYear, iMonth - 1);

            DateTime fiscalYearStartDate = new DateTime(iYear, 9, 1);
            DateTime fiscalYearEndDate = new DateTime(iYear + 1, 8, 31);
            DateTime lastFiscalYearStartDate = new DateTime(iYear - 1, 9, 1);
            DateTime lastFiscalYearEndDate = new DateTime(iYear, 8, 31);

            DateTime start2020 = new DateTime(2020, 1, 1);
            DateTime end2020 = new DateTime(2020, 12, 31);

            if (iMonth < 9)
            {
                fiscalYearStartDate = fiscalYearStartDate.AddYears(-1);
                fiscalYearEndDate = fiscalYearEndDate.AddYears(-1);
                lastFiscalYearStartDate = lastFiscalYearStartDate.AddYears(-1);
                lastFiscalYearEndDate = lastFiscalYearEndDate.AddYears(-1);
            }

            DateTime periodEndDate = new DateTime(iYear, iMonth - 1, lastDayOfLastMonth);
            DateTime lastPeriodEndDate = new DateTime(iYear - 1, iMonth - 1, lastDayOfLastMonth);

            FiscalYearStartDate = fiscalYearStartDate.ToShortDateString();
            FiscalYearEndDate = fiscalYearEndDate.ToShortDateString();
            PeriodStartDate = fiscalYearStartDate.ToShortDateString();
            PeriodEndDate = periodEndDate.ToShortDateString();
            LastPeriodStartDate = lastFiscalYearStartDate.ToShortDateString();
            LastPeriodEndDate = lastPeriodEndDate.ToShortDateString();

            Last8WkStartDate = now.AddDays(-57).ToShortDateString();
            Last8WkEndDate = now.ToShortDateString();
            Last8WkStartDateLy = now.AddDays(-57).AddYears(-1).ToShortDateString();
            Last8WkEndDateLy = now.AddYears(-1).ToShortDateString();

            Last6WkStartDate = now.AddDays(-43).ToShortDateString();
            Last6WkEndDate = now.ToShortDateString();
            Last6WkStartDateLy = now.AddDays(-43).AddYears(-1).ToShortDateString();
            Last6WkEndDateLy = now.AddYears(-1).ToShortDateString();

            DateTime last6WkStartDate = now.AddDays(-43);
            DateTime last6WkEndDate = now;
            DateTime last6WkStartDateLy = now.AddDays(-43).AddYears(-1);
            DateTime last6WkEndDateLy = now.AddYears(-1);

            switch (iMonth)
            {
                case 09:
                    CurrentMonthInFiscalYear = 1;
                    GoalOffsetMultiplier = .083;
                    SecondaryGoalOffsetMultiplier = .89;
                    break;
                case 10:
                    CurrentMonthInFiscalYear = 2;
                    GoalOffsetMultiplier = .167;
                    SecondaryGoalOffsetMultiplier = .90;
                    break;
                case 11:
                    CurrentMonthInFiscalYear = 3;
                    GoalOffsetMultiplier = .25;
                    SecondaryGoalOffsetMultiplier = .91;
                    break;
                case 12:
                    CurrentMonthInFiscalYear = 4;
                    GoalOffsetMultiplier = .333;
                    SecondaryGoalOffsetMultiplier = .92;
                    break;
                case 01:
                    CurrentMonthInFiscalYear = 5;
                    GoalOffsetMultiplier = .417;
                    SecondaryGoalOffsetMultiplier = .93;
                    break;
                case 02:
                    CurrentMonthInFiscalYear = 6;
                    GoalOffsetMultiplier = .5;
                    SecondaryGoalOffsetMultiplier = .94;
                    break;
                case 03:
                    CurrentMonthInFiscalYear = 7;
                    GoalOffsetMultiplier = .583;
                    SecondaryGoalOffsetMultiplier = .95;
                    break;
                case 04:
                    CurrentMonthInFiscalYear = 8;
                    GoalOffsetMultiplier = .667;
                    SecondaryGoalOffsetMultiplier = .96;
                    break;
                case 05:
                    CurrentMonthInFiscalYear = 9;
                    GoalOffsetMultiplier = .75;
                    SecondaryGoalOffsetMultiplier = .97;
                    break;
                case 06:
                    CurrentMonthInFiscalYear = 10;
                    GoalOffsetMultiplier = .883;
                    SecondaryGoalOffsetMultiplier = .98;
                    break;
                case 07:
                    CurrentMonthInFiscalYear = 11;
                    GoalOffsetMultiplier = .917;
                    SecondaryGoalOffsetMultiplier = .99;
                    break;
                case 08:
                    CurrentMonthInFiscalYear = 12;
                    GoalOffsetMultiplier = 1;
                    SecondaryGoalOffsetMultiplier = 1;
                    break;
            }

            //-------Attendance-------

            //Auditorium
            iAttendanceAud = Get6WkAttendanceAuditorium(CampusId, last6WkStartDate, last6WkEndDate);
            iAttendanceAudLastYear = Get6WkAttendanceAuditorium(CampusId, last6WkStartDateLy, last6WkEndDateLy);
            iAttendanceAudGoal2020 = GetMetrics(2, CampusId, start2020, end2020, 1);

            //Kids
            iAttendanceKids = Get6WkAttendanceKids(CampusId, last6WkStartDate, last6WkEndDate);
            iAttendanceKidsLastYear = Get6WkAttendanceKids(CampusId, last6WkStartDateLy, last6WkEndDateLy);
            iAttendanceChildGoal2020 = GetMetrics(3, CampusId, start2020, end2020, 1);

            //Students
            iAttendanceStudents = Get6WkAttendanceStudents(CampusId, last6WkStartDate, last6WkEndDate);
            iAttendanceStudentsLastYear = Get6WkAttendanceStudents(CampusId, last6WkStartDateLy, last6WkEndDateLy);
            iAttendanceStudentGoal2020 = GetMetrics(5, CampusId, start2020, end2020, 1);

            //HighSchool
            iAttendanceHighSchool = Get6WkAttendanceHighSchool(CampusId, last6WkStartDate, last6WkEndDate);
            iAttendanceHighSchoolLastYear = Get6WkAttendanceHighSchool(CampusId, last6WkStartDateLy, last6WkEndDateLy);
            iAttendanceStudentGoal2020 = GetMetrics(5, CampusId, start2020, end2020, 1);

            if (UseGlobalAttributeGoal == true)
            {
                iAttendanceAudGoalCurrent = Convert.ToInt32((double?)iAttendanceAudLastYear * GoalMultiplier);
                iAttendanceChildGoalCurrent = Convert.ToInt32((double?)iAttendanceKidsLastYear * GoalMultiplier);
                iAttendanceStudentGoalCurrent = Convert.ToInt32((double?)iAttendanceStudentsLastYear * GoalMultiplier);
            }
            else
            {
                iAttendanceAudGoalCurrent = GetMetrics(2, CampusId, lastFiscalYearStartDate, fiscalYearEndDate, 1);
                iAttendanceChildGoalCurrent = GetMetrics(3, CampusId, lastFiscalYearStartDate, fiscalYearEndDate, 1);
                iAttendanceStudentGoalCurrent = GetMetrics(5, CampusId, lastFiscalYearStartDate, fiscalYearEndDate, 1);
            }

            //All
            iAttendanceAll = Get6WkAttendanceAll(CampusId, last6WkStartDate, last6WkEndDate);
            iAttendanceAllLastYear = Get6WkAttendanceAll(CampusId, last6WkStartDateLy, last6WkEndDateLy);
            iAttendanceAllGoalCurrent = iAttendanceAudGoalCurrent + iAttendanceChildGoalCurrent + iAttendanceStudentGoalCurrent;
            iAttendanceAllGoal2020 = iAttendanceAudGoal2020 + iAttendanceChildGoal2020 + iAttendanceStudentGoal2020;

            //Calculate attendance goal progress
            iAttendanceAudGoalProgress = (double?)iAttendanceAud / ((double?)iAttendanceAudGoalCurrent * SecondaryGoalOffsetMultiplier) * 100;
            iAttendanceChildGoalProgress = (double?)iAttendanceKids / ((double?)iAttendanceChildGoalCurrent * SecondaryGoalOffsetMultiplier) * 100;
            iAttendanceStudentGoalProgress = (double?)iAttendanceStudents / ((double?)iAttendanceStudentGoalCurrent * SecondaryGoalOffsetMultiplier) * 100;
            iAttendanceHighSchoolGoalProgress = (double?)iAttendanceHighSchool / ((double?)iAttendanceHighSchoolGoalCurrent * SecondaryGoalOffsetMultiplier) * 100;
            iAttendanceAllGoalProgress = (double?)iAttendanceAll / ((double?)iAttendanceAllGoalCurrent * SecondaryGoalOffsetMultiplier) * 100;

            //-------Baptisms-------

            //YTD
            iBaptisms = GetMetrics(11, CampusId, fiscalYearStartDate, periodEndDate, 0);

            //LastYTD
            iBaptismsLastYear = GetMetrics(11, CampusId, lastFiscalYearStartDate, lastPeriodEndDate, 0);

            //Current Goal
            iBaptismsGoalCurrent = GetMetrics(11, CampusId, lastFiscalYearStartDate, fiscalYearEndDate, 1);

            //2020 Goal
            iBaptismsGoal2020 = GetMetrics(11, CampusId, start2020, end2020, 1);

            //8Wk
            iBaptisms8Wk = GetMetrics(11, CampusId, now.AddDays(-57), now, 0);
            iBaptisms8WkLy = GetMetrics(11, CampusId, now.AddDays(-57).AddYears(-1), now.AddYears(-1), 0);
            iBaptisms8WkProgress = (((double)iBaptisms8Wk - (double)iBaptisms8WkLy) / (double)iBaptisms8WkLy) * 100;

            //-------Partners-------

            //YTD
            iPartners = GetMetricsLatest(20, CampusId, fiscalYearStartDate, periodEndDate, 0);

            //LastYTD
            iPartnersLastYear = GetMetricsLatest(20, CampusId, lastFiscalYearStartDate, lastPeriodEndDate, 0);

            //Current Goal
            iPartnersGoalCurrent = GetMetricsLatest(20, CampusId, lastFiscalYearStartDate, fiscalYearEndDate, 1);

            //2020 Goal
            iPartnersGoal2020 = GetMetricsLatest(20, CampusId, start2020, end2020, 1);

            //-------Commitments-------

            //YTD
            iCommitments = GetMetrics(12, CampusId, fiscalYearStartDate, periodEndDate, 0);

            //LastYTD
            iCommitmentsLastYear = GetMetrics(12, CampusId, lastFiscalYearStartDate, lastPeriodEndDate, 0);

            //Current Goal
            iCommitmentsGoalCurrent = GetMetrics(12, CampusId, lastFiscalYearStartDate, fiscalYearEndDate, 1);

            //2020 Goal
            iCommitmentsGoal2020 = GetMetrics(12, CampusId, start2020, end2020, 1);

            //8Wk
            iCommitments8Wk = GetMetrics(12, CampusId, now.AddDays(-57), now, 0);
            iCommitments8WkLy = GetMetrics(12, CampusId, now.AddDays(-57).AddYears(-1), now.AddYears(-1), 0);

            //-------Recommitments-------

            //YTD
            iRecommitments = GetMetrics(13, CampusId, fiscalYearStartDate, periodEndDate, 0);

            //LastYTD
            iRecommitmentsLastYear = GetMetrics(13, CampusId, lastFiscalYearStartDate, lastPeriodEndDate, 0);

            //Current Goal
            iRecommitmentsGoalCurrent = GetMetrics(13, CampusId, lastFiscalYearStartDate, fiscalYearEndDate, 1);

            //2020 Goal
            iRecommitmentsGoal2020 = GetMetrics(13, CampusId, start2020, end2020, 1);

            //8Wk
            iRecommitments8Wk = GetMetrics(13, CampusId, now.AddDays(-57), now, 0);
            iRecommitments8WkLy = GetMetrics(13, CampusId, now.AddDays(-57).AddYears(-1), now.AddYears(-1), 0);

            //-------Volunteers-------

            //YTD
            iVolunteers = GetMetricsLatest(16, CampusId, fiscalYearStartDate, periodEndDate, 0);

            //LastYTD
            iVolunteersLastYear = GetMetricsLatest(16, CampusId, lastFiscalYearStartDate, lastPeriodEndDate, 0);

            //Current Goal
            iVolunteersGoalCurrent = GetMetricsLatest(16, CampusId, lastFiscalYearStartDate, fiscalYearEndDate, 1);

            //2020 Goal
            iVolunteersGoal2020 = GetMetricsLatest(16, CampusId, start2020, end2020, 1);

            //-------SmallGroupParticipants-------

            //YTD
            iSmallGroupParticipants = GetMetricsLatest(17, CampusId, fiscalYearStartDate, periodEndDate, 0);

            //LastYTD
            iSmallGroupParticipantsLastYear = GetMetricsLatest(17, CampusId, lastFiscalYearStartDate, lastPeriodEndDate, 0);

            //Current Goal
            iSmallGroupParticipantsGoalCurrent = GetMetricsLatest(17, CampusId, lastFiscalYearStartDate, fiscalYearEndDate, 1);

            //2020 Goal
            iSmallGroupParticipantsGoal2020 = GetMetricsLatest(17, CampusId, start2020, end2020, 1);

            //-------SmallGroupLeaders-------

            //YTD
            iSmallGroupLeaders = GetMetricsLatest(18, CampusId, fiscalYearStartDate, periodEndDate, 0);

            //LastYTD
            iSmallGroupLeadersLastYear = GetMetricsLatest(18, CampusId, lastFiscalYearStartDate, lastPeriodEndDate, 0);

            //Current Goal
            iSmallGroupLeadersGoalCurrent = GetMetricsLatest(18, CampusId, lastFiscalYearStartDate, fiscalYearEndDate, 1);

            //2020 Goal
            iSmallGroupLeadersGoal2020 = GetMetricsLatest(18, CampusId, start2020, end2020, 1);

            //-------SmallGroups-------

            //YTD
            iSmallGroups = GetMetricsLatest(34, CampusId, fiscalYearStartDate, periodEndDate, 0);

            //LastYTD
            iSmallGroupsLastYear = GetMetricsLatest(34, CampusId, lastFiscalYearStartDate, lastPeriodEndDate, 0);

            //Current Goal
            iSmallGroupsGoalCurrent = GetMetricsLatest(34, CampusId, lastFiscalYearStartDate, fiscalYearEndDate, 1);

            //2020 Goal
            iSmallGroupsGoal2020 = GetMetricsLatest(34, CampusId, start2020, end2020, 1);

            //-------NewtoNewPointe-------

            //YTD
            iNewtoNewPointe = GetMetrics(21, CampusId, fiscalYearStartDate, periodEndDate, 0);

            //LastYTD
            iNewtoNewPointeLastYear = GetMetrics(21, CampusId, lastFiscalYearStartDate, lastPeriodEndDate, 0);

            //Current Goal
            iNewtoNewPointeGoalCurrent = GetMetrics(21, CampusId, lastFiscalYearStartDate, fiscalYearEndDate, 1);

            //2020 Goal
            iNewtoNewPointeGoal2020 = GetMetrics(21, CampusId, start2020, end2020, 1);

            //8Wk
            iNewtoNewPointe8Wk = GetMetrics(21, CampusId, now.AddDays(-57), now, 0);
            iNewtoNewPointe8WkLy = GetMetrics(21, CampusId, now.AddDays(-57).AddYears(-1), now.AddYears(-1), 0);
            dNewtoNewPointe8WkProgress = (((double)iNewtoNewPointe8Wk - (double)iNewtoNewPointe8WkLy) / (double)iNewtoNewPointe8WkLy) * 100;

            //-------DiscoverGroups-------

            //YTD
            iDiscoverGroups = GetMetrics(22, CampusId, fiscalYearStartDate, periodEndDate, 0);

            //LastYTD
            iDiscoverGroupsLastYear = GetMetrics(22, CampusId, lastFiscalYearStartDate, lastPeriodEndDate, 0);

            //Current Goal
            iDiscoverGroupsGoalCurrent = GetMetrics(22, CampusId, lastFiscalYearStartDate, fiscalYearEndDate, 1);

            //2020 Goal
            iDiscoverGroupsGoal2020 = GetMetrics(2, CampusId, start2020, end2020, 1);

            //8Wk
            iDiscoverGroups8Wk = GetMetrics(22, CampusId, now.AddDays(-57), now, 0);
            iDiscoverGroups8WkLy = GetMetrics(22, CampusId, now.AddDays(-57).AddYears(-1), now.AddYears(-1), 0);
            dDiscoverGroups8WkProgress = (((double)iDiscoverGroups8Wk - (double)iDiscoverGroups8WkLy) / (double)iDiscoverGroups8WkLy) * 100;

            //-------CampusGroups-------

            //YTD
            iCampusGroups = GetMetrics(24, CampusId, fiscalYearStartDate, periodEndDate, 0);

            //LastYTD
            iCampusGroupsLastYear = GetMetrics(24, CampusId, lastFiscalYearStartDate, lastPeriodEndDate, 0);

            //Current Goal
            iCampusGroupsGoalCurrent = GetMetrics(24, CampusId, lastFiscalYearStartDate, fiscalYearEndDate, 1);

            //2020 Goal
            iCampusGroupsGoal2020 = GetMetrics(24, CampusId, start2020, end2020, 1);

            //8Wk
            iCampusGroups8Wk = GetMetrics(24, CampusId, now.AddDays(-57), now, 0);
            iCampusGroups8WkLy = GetMetrics(24, CampusId, now.AddDays(-57).AddYears(-1), now.AddYears(-1), 0);
            dCampusGroups8WkProgress = (((double)iCampusGroups8Wk - (double)iCampusGroups8WkLy) / (double)iCampusGroups8WkLy) * 100;

            //-------NewHere-------

            //YTD
            iNewHere = GetMetrics(14, CampusId, fiscalYearStartDate, periodEndDate, 0);

            //LastYTD
            iNewHereLastYear = GetMetrics(14, CampusId, lastFiscalYearStartDate, lastPeriodEndDate, 0);

            //Current Goal
            iNewHereGoalCurrent = GetMetrics(14, CampusId, lastFiscalYearStartDate, fiscalYearEndDate, 1);

            //2020 Goal
            iNewHereGoal2020 = GetMetrics(14, CampusId, start2020, end2020, 1);

            //8Wk
            iNewHere8Wk = GetMetrics(14, CampusId, now.AddDays(-57), now, 0);
            iNewHere8WkLy = GetMetrics(14, CampusId, now.AddDays(-57).AddYears(-1), now.AddYears(-1), 0);
            dNewHere8WkProgress = (((double)iNewHere8Wk - (double)iNewHere8WkLy) / (double)iNewHere8WkLy) * 100;

            //-------Inactive Followups-------

            //Total
            iInactiveFollowup = GetMetrics(35, CampusId, fiscalYearStartDate, periodEndDate, 0);

            //Completed
            iInactiveFollowupComplete = GetMetrics(38, CampusId, fiscalYearStartDate, periodEndDate, 0);

            //Inconplete
            iInactiveFollowupIncomplete = iInactiveFollowup - iInactiveFollowupComplete;

            //Progress
            iInactiveFollowupProgress = (double)iInactiveFollowupComplete / (double)iInactiveFollowup * 100;

            //-------Finances-------

            expenses = .99;
            giving = .95;

            //TODO: need to make a method to get these as a double (not an int)

            //Get Goals based on Global Attribute Multiplier or values stored in metrics table

            if (UseGlobalAttributeGoal == true)
            {
                iBaptismsGoalCurrent = Convert.ToInt32((double?)iBaptismsLastYear * GoalMultiplier);
                iPartnersGoalCurrent = Convert.ToInt32((double?)iPartnersLastYear * GoalMultiplier);
                iCommitmentsGoalCurrent = Convert.ToInt32((double?)iCommitmentsLastYear * GoalMultiplier);
                iRecommitmentsGoalCurrent = Convert.ToInt32((double?)iRecommitmentsLastYear * GoalMultiplier);
                iVolunteersGoalCurrent = Convert.ToInt32((double?)iVolunteersLastYear * GoalMultiplier);
                iSmallGroupParticipantsGoalCurrent = Convert.ToInt32((double?)iSmallGroupParticipantsLastYear * GoalMultiplier);
                iSmallGroupLeadersGoalCurrent = Convert.ToInt32((double?)iSmallGroupLeadersLastYear * GoalMultiplier);
                iNewtoNewPointeGoalCurrent = Convert.ToInt32((double?)iNewtoNewPointeLastYear * GoalMultiplier);
                iDiscoverGroupsGoalCurrent = Convert.ToInt32((double?)iDiscoverGroupsLastYear * GoalMultiplier);
                iCampusGroupsGoalCurrent = Convert.ToInt32((double?)iCampusGroupsLastYear * GoalMultiplier);
                iNewHereGoalCurrent = Convert.ToInt32((double?)iNewHereLastYear * GoalMultiplier);
                iSmallGroupsGoalCurrent = Convert.ToInt32((double?)iSmallGroupsLastYear * GoalMultiplier);

            }
            else
            {
                iBaptismsGoalCurrent = GetMetrics(11, CampusId, lastFiscalYearStartDate, fiscalYearEndDate, 1);
                iPartnersGoalCurrent = GetMetricsLatest(20, CampusId, lastFiscalYearStartDate, fiscalYearEndDate, 1);
                iCommitmentsGoalCurrent = GetMetrics(12, CampusId, lastFiscalYearStartDate, fiscalYearEndDate, 1);
                iRecommitmentsGoalCurrent = GetMetrics(13, CampusId, lastFiscalYearStartDate, fiscalYearEndDate, 1);
                iVolunteersGoalCurrent = GetMetricsLatest(16, CampusId, lastFiscalYearStartDate, fiscalYearEndDate, 1);
                iSmallGroupParticipantsGoalCurrent = GetMetricsLatest(17, CampusId, lastFiscalYearStartDate, fiscalYearEndDate, 1);
                iSmallGroupLeadersGoalCurrent = GetMetricsLatest(17, CampusId, lastFiscalYearStartDate, fiscalYearEndDate, 1);
                iNewtoNewPointeGoalCurrent = GetMetrics(21, CampusId, lastFiscalYearStartDate, fiscalYearEndDate, 1);
                iDiscoverGroupsGoalCurrent = GetMetrics(22, CampusId, lastFiscalYearStartDate, fiscalYearEndDate, 1);
                iCampusGroupsGoalCurrent = GetMetrics(24, CampusId, lastFiscalYearStartDate, fiscalYearEndDate, 1);
                iNewHereGoalCurrent = GetMetrics(14, CampusId, lastFiscalYearStartDate, fiscalYearEndDate, 1);
                iSmallGroupsGoalCurrent = GetMetrics(34, CampusId, lastFiscalYearStartDate, fiscalYearEndDate, 1);
            }

            //-------AllCommitments-------

            //YTD
            iAllCommitments = iCommitments + iRecommitments;

            //LastYTD
            iAllCommitmentsLastYear = iCommitmentsLastYear + iRecommitmentsLastYear;

            //Current Goal
            iAllCommitmentsGoalCurrent = iCommitmentsGoalCurrent + iRecommitmentsGoalCurrent;

            //2020 Goal
            iAllCommitmentsGoal2020 = iCommitmentsGoal2020 + iRecommitmentsGoal2020;

            //Current Goal Progress
            iAllCommitmentsGoalProgress = ((double)iCommitments + (double)iRecommitments) / (((double)iCommitmentsGoalCurrent + (double)iRecommitmentsGoalCurrent) * GoalOffsetMultiplier) * 100;

            //8Wk
            iAllCommitments8Wk = iCommitments8Wk + iRecommitments8Wk;
            iAllCommitments8WkLy = iCommitments8WkLy + iRecommitments8WkLy;
            dAllCommitments8WkProgress = (((double)iAllCommitments8Wk - (double)iAllCommitments8WkLy) / (double)iAllCommitments8WkLy) * 100;

            // Caculate the progress toeards the goals
            iBaptismsGoalProgress = (double)iBaptisms / ((double)iBaptismsGoalCurrent * GoalOffsetMultiplier) * 100;
            iPartnersGoalProgress = (double)iPartners / ((double)iPartnersGoalCurrent * GoalOffsetMultiplier) * 100;
            iCommitmentsGoalProgress = (double)iCommitments / ((double)iCommitmentsGoalCurrent * GoalOffsetMultiplier) * 100;
            iRecommitmentsGoalProgress = (double)iRecommitments / ((double)iRecommitmentsGoalCurrent * GoalOffsetMultiplier) * 100;
            iVolunteersGoalProgress = (double)iVolunteers / ((double)iVolunteersGoalCurrent * GoalOffsetMultiplier) * 100;
            iSmallGroupParticipantsGoalProgress = (double)iSmallGroupParticipants / ((double)iSmallGroupParticipantsGoalCurrent * GoalOffsetMultiplier) * 100;
            iSmallGroupLeadersGoalProgress = (double)iSmallGroupLeaders / ((double)iSmallGroupLeadersGoalCurrent * GoalOffsetMultiplier) * 100;
            iNewtoNewPointeGoalProgress = (double)iNewtoNewPointe / ((double)iNewtoNewPointeGoalCurrent * GoalOffsetMultiplier) * 100;
            iDiscoverGroupsGoalProgress = (double)iDiscoverGroups / ((double)iDiscoverGroupsGoalCurrent * GoalOffsetMultiplier) * 100;
            iCampusGroupsGoalProgress = (double)iCampusGroups / ((double)iCampusGroupsGoalCurrent * GoalOffsetMultiplier) * 100;
            iNewHereGoalProgress = (double)iNewHere / ((double)iNewHereGoalCurrent * GoalOffsetMultiplier) * 100;
            iSmallGroupsGoalProgress = (double)iSmallGroups / ((double)iSmallGroupsGoalCurrent * GoalOffsetMultiplier) * 100;

            //Calculate the Composite Score
            CompositeScore = CalculateCompositeScore();

            //Save to the database

            if (CompositeScore > 0 && CompositeScore < 1000)
            {
                MetricValueService metricValueService = new MetricValueService(rockContext);

                MetricValue metricValue;

                metricValue = new MetricValue();
                metricValueService.Add(metricValue);
                metricValue.MetricId = 39;
                metricValue.Metric = metricValue.Metric ?? new MetricService(rockContext).Get(metricValue.MetricId);

                metricValue.MetricValueType = (MetricValueType)0;
                metricValue.XValue = null;
                metricValue.YValue = (decimal)CompositeScore;
                metricValue.Note = "";
                metricValue.MetricValueDateTime = dt;
                metricValue.EntityId = CampusId;

                rockContext.SaveChanges();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Sets the value.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        /// <param name="saveValue">if set to <c>true</c> [save value].</param>
        /// <param name="rockContext">The rock context.</param>
        public void SetValue( string key, string value, bool saveValue, RockContext rockContext )
        {
            AttributeCache attributeCache = null;

            if ( saveValue )
            {
                // Save new value
                rockContext = rockContext ?? new RockContext();
                var attributeValueService = new AttributeValueService( rockContext );
                var attributeValue = attributeValueService.GetGlobalAttributeValue( key );

                if ( attributeValue == null )
                {
                    var attributeService = new AttributeService( rockContext );
                    var attribute = attributeService.GetGlobalAttribute( key );
                    if ( attribute == null )
                    {
                        attribute = new Rock.Model.Attribute();
                        attribute.FieldTypeId = FieldTypeCache.Read( new Guid( SystemGuid.FieldType.TEXT ) ).Id;
                        attribute.EntityTypeQualifierColumn = string.Empty;
                        attribute.EntityTypeQualifierValue = string.Empty;
                        attribute.Key = key;
                        attribute.Name = key.SplitCase();
                        attributeService.Add( attribute );
                        rockContext.SaveChanges();
                    }

                    attributeValue = new AttributeValue();
                    attributeValue.IsSystem = false;
                    attributeValue.AttributeId = attribute.Id;
                    attributeValueService.Add( attributeValue );
                }

                attributeValue.Value = value;
                rockContext.SaveChanges();
            }

            lock(_obj)
            {
                attributeIds = null;
            }

            AttributeValues.AddOrUpdate( key, value, ( k, v ) => value );

            attributeCache = Attributes.FirstOrDefault( a => a.Key.Equals( key, StringComparison.OrdinalIgnoreCase ) );
            if ( attributeCache != null )
            {
                value = attributeCache.FieldType.Field.FormatValue( null, value, attributeCache.QualifierValues, false );
            }
            AttributeValuesFormatted.AddOrUpdate( key, value, (k, v) => value);
        }