-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathRockCommon.cs
147 lines (126 loc) · 5.27 KB
/
RockCommon.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using System;
using System.Collections.Generic;
using Rock.Mobile.Util.Strings;
using Rock.Mobile.Network;
using System.IO;
using Rock.Mobile.IO;
using Rock.Client;
using Rock.Mobile.Util;
using System.Net;
using Newtonsoft.Json;
using Rock.Mobile;
namespace FamilyManager
{
//TODO: MOVE THIS OUT OF HERE AND CCV MOBILE AND INTO SOMETHING COMMON
public static class RockActions
{
public static void SetBirthday( Rock.Client.Person person, DateTime? birthday )
{
// update the birthdate field
person.BirthDate = birthday;
// and the day/month/year fields.
if ( person.BirthDate.HasValue )
{
person.BirthDay = person.BirthDate.Value.Day;
person.BirthMonth = person.BirthDate.Value.Month;
person.BirthYear = person.BirthDate.Value.Year;
}
else
{
person.BirthDay = null;
person.BirthMonth = null;
person.BirthYear = null;
}
}
public static void SetPhoneNumberDigits( Rock.Client.PhoneNumber phoneNumber, string digits )
{
phoneNumber.Number = digits;
phoneNumber.NumberFormatted = digits.AsPhoneNumber( );
}
public static Rock.Client.GroupLocation CreateHomeAddress( string street, string city, string state, string zip )
{
// try to find the group, and if it doesn't exist, make it
Rock.Client.GroupLocation homeLocation = new Rock.Client.GroupLocation();
homeLocation.GroupLocationTypeValueId = GroupLocationTypeHomeValueId;
// for the address location, default the country to the built in country code.
homeLocation.Location = new Rock.Client.Location();
homeLocation.Location.Country = CountryCode;
// populate it
homeLocation.Location.Street1 = street;
homeLocation.Location.City = city;
homeLocation.Location.State = state;
homeLocation.Location.PostalCode = zip;
// return it.
return homeLocation;
}
public static Rock.Client.GroupLocation GetFamilyHomeAddress( Rock.Client.Group family )
{
// look at each location within the family
foreach ( Rock.Client.GroupLocation groupLocation in family.GroupLocations )
{
// find their "Home Location" within the family group type.
if ( groupLocation.GroupLocationTypeValue.Guid.ToString( ).ToLower( ) == Rock.Client.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME.ToLower( ) )
{
return groupLocation;
}
}
return null;
}
public static bool IsFullAddress( Rock.Client.GroupLocation address )
{
// by full address, we mean street, city, state, zip
if ( string.IsNullOrWhiteSpace( address.Location.Street1 ) == false &&
string.IsNullOrWhiteSpace( address.Location.City ) == false &&
string.IsNullOrWhiteSpace( address.Location.State ) == false &&
string.IsNullOrWhiteSpace( address.Location.PostalCode ) == false )
{
return true;
}
return false;
}
public const int CellPhoneValueId = 12;
public static Rock.Client.PhoneNumber TryGetPhoneNumber( Rock.Client.Person person, int phoneTypeId )
{
Rock.Client.PhoneNumber requestedNumber = null;
// if the user has phone numbers
if ( person.PhoneNumbers != null )
{
// get an enumerator
IEnumerator<Rock.Client.PhoneNumber> enumerator = person.PhoneNumbers.GetEnumerator( );
enumerator.MoveNext( );
// search for the phone number type requested
while ( enumerator.Current != null )
{
Rock.Client.PhoneNumber phoneNumber = enumerator.Current as Rock.Client.PhoneNumber;
// is this the right type?
if ( phoneNumber.NumberTypeValueId == phoneTypeId )
{
requestedNumber = phoneNumber;
break;
}
enumerator.MoveNext( );
}
}
return requestedNumber;
}
public static List<string> Genders { get; set; }
static RockActions( )
{
Genders = new List<string>( );
Genders.Add( "Unknown" );
Genders.Add( "Male" );
Genders.Add( "Female" );
}
/// <summary>
/// These are values that, while generated when the Rock database is created,
/// are extremely unlikely to ever change. If they do change, simply update them here to match
/// Rock.
/// </summary>
public const int NeighborhoodGroupGeoFenceValueId = 48;
public const int NeighborhoodGroupValueId = 49;
public const int GroupLocationTypeHomeValueId = 19;
public const int PersonConnectionStatusValueId = 146;
public const int PersonRecordStatusValueId = 5;
public const string CountryCode = "US";
}
}