Пример #1
0
        /// <summary>
        /// Creates the current row from group location.
        /// </summary>
        /// <param name="groupLocation">The group location.</param>
        /// <param name="effectiveDateTime">The effective date time.</param>
        /// <returns></returns>
        public static GroupLocationHistorical CreateCurrentRowFromGroupLocation(GroupLocation groupLocation, DateTime effectiveDateTime)
        {
            var locationName = groupLocation.Location?.ToString(true);

            var groupLocationHistoricalCurrent = new GroupLocationHistorical
            {
                GroupLocationId          = groupLocation.Id,
                GroupId                  = groupLocation.GroupId,
                GroupLocationTypeValueId = groupLocation.GroupLocationTypeValueId,
                GroupLocationTypeName    = groupLocation.GroupLocationTypeValue?.Value,
                LocationId               = groupLocation.LocationId,
                LocationName             = locationName,
                LocationModifiedDateTime = groupLocation.Location?.ModifiedDateTime,

                // Set the Modified/Created fields for GroupLocationHistorical to be the current values from the GroupLocation table
                ModifiedDateTime        = groupLocation.ModifiedDateTime,
                ModifiedByPersonAliasId = groupLocation.ModifiedByPersonAliasId,
                CreatedByPersonAliasId  = groupLocation.CreatedByPersonAliasId,
                CreatedDateTime         = groupLocation.CreatedDateTime,

                // Set HistoricalTracking fields
                CurrentRowIndicator = true,
                EffectiveDateTime   = effectiveDateTime,
                ExpireDateTime      = HistoricalTracking.MaxExpireDateTime
            };

            return(groupLocationHistoricalCurrent);

            #endregion
        }
Пример #2
0
 /// <summary>
 /// Copies the properties from another GroupLocation object to this GroupLocation object
 /// </summary>
 /// <param name="target">The target.</param>
 /// <param name="source">The source.</param>
 public static void CopyPropertiesFrom(this GroupLocation target, GroupLocation source)
 {
     target.GroupId    = source.GroupId;
     target.LocationId = source.LocationId;
     target.GroupLocationTypeValueId = source.GroupLocationTypeValueId;
     target.IsMailingLocation        = source.IsMailingLocation;
     target.IsMappedLocation         = source.IsMappedLocation;
     target.GroupMemberPersonId      = source.GroupMemberPersonId;
     target.Id   = source.Id;
     target.Guid = source.Guid;
 }
Пример #3
0
 /// <summary>
 /// Clones this GroupLocation object to a new GroupLocation object
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="deepCopy">if set to <c>true</c> a deep copy is made. If false, only the basic entity properties are copied.</param>
 /// <returns></returns>
 public static GroupLocation Clone(this GroupLocation source, bool deepCopy)
 {
     if (deepCopy)
     {
         return(source.Clone() as GroupLocation);
     }
     else
     {
         var target = new GroupLocation();
         target.CopyPropertiesFrom(source);
         return(target);
     }
 }
        /// <summary>
        /// Deletes the specified GroupLocation and sets GroupLocationHistorical.GroupLocationId to NULL.
        /// Will not delete the GroupLocation and return false if the GroupLocationHistorical.GroupLocationId fails to update.
        /// Will try to determine current person alias from HttpContext.
        /// Caller is responsible to save changes.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns></returns>
        public override bool Delete(GroupLocation item)
        {
            // Remove the ID from GroupLocationHistorical before deleting
            var  rockContext = this.Context as Rock.Data.RockContext;
            bool isNulled    = new GroupLocationHistoricalService(rockContext).SetGroupLocationIdToNullForGroupLocationId(item.Id);

            if (!isNulled)
            {
                return(false);
            }

            // Delete the GroupLocation
            return(base.Delete(item));
        }
 /// <summary>
 /// Copies the properties from another GroupLocation object to this GroupLocation object
 /// </summary>
 /// <param name="target">The target.</param>
 /// <param name="source">The source.</param>
 public static void CopyPropertiesFrom(this GroupLocation target, GroupLocation source)
 {
     target.Id      = source.Id;
     target.GroupId = source.GroupId;
     target.GroupLocationTypeValueId = source.GroupLocationTypeValueId;
     target.GroupMemberPersonAliasId = source.GroupMemberPersonAliasId;
     target.IsMailingLocation        = source.IsMailingLocation;
     target.IsMappedLocation         = source.IsMappedLocation;
     target.LocationId              = source.LocationId;
     target.CreatedDateTime         = source.CreatedDateTime;
     target.ModifiedDateTime        = source.ModifiedDateTime;
     target.CreatedByPersonAliasId  = source.CreatedByPersonAliasId;
     target.ModifiedByPersonAliasId = source.ModifiedByPersonAliasId;
     target.Guid      = source.Guid;
     target.ForeignId = source.ForeignId;
 }
        /// <summary>
        /// Adds the new family address.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="family">The family.</param>
        /// <param name="locationTypeGuid">The location type unique identifier.</param>
        /// <param name="street1">The street1.</param>
        /// <param name="street2">The street2.</param>
        /// <param name="city">The city.</param>
        /// <param name="state">The state.</param>
        /// <param name="postalCode">The postal code.</param>
        /// <param name="country">The country.</param>
        /// <param name="moveExistingToPrevious">if set to <c>true</c> [move existing to previous].</param>
        public static void AddNewFamilyAddress( RockContext rockContext, Group family, string locationTypeGuid,
            string street1, string street2, string city, string state, string postalCode, string country, bool moveExistingToPrevious = false )
        {
            if ( !String.IsNullOrWhiteSpace( street1 ) ||
                 !String.IsNullOrWhiteSpace( street2 ) ||
                 !String.IsNullOrWhiteSpace( city ) ||
                 !String.IsNullOrWhiteSpace( postalCode ) ||
                 !string.IsNullOrWhiteSpace( country ) )
            {
                var locationType = Rock.Web.Cache.DefinedValueCache.Read( locationTypeGuid.AsGuid() );
                if ( locationType != null )
                {
                    var location = new LocationService( rockContext ).Get( street1, street2, city, state, postalCode, country );
                    if ( location != null )
                    {
                        var groupLocationService = new GroupLocationService( rockContext );
                        if ( !groupLocationService.Queryable()
                            .Where( gl =>
                                gl.GroupId == family.Id &&
                                gl.GroupLocationTypeValueId == locationType.Id &&
                                gl.LocationId == location.Id )
                            .Any() )
                        {

                            var familyChanges = new List<string>();

                            if ( moveExistingToPrevious )
                            {
                                var prevLocationType = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_PREVIOUS );
                                if ( prevLocationType != null )
                                {
                                    foreach ( var prevLoc in groupLocationService.Queryable( "Location,GroupLocationTypeValue" )
                                        .Where( gl =>
                                            gl.GroupId == family.Id &&
                                            gl.GroupLocationTypeValueId == locationType.Id ) )
                                    {
                                        History.EvaluateChange( familyChanges, prevLoc.Location.ToString(), prevLoc.GroupLocationTypeValue.Value, prevLocationType.Value );
                                        prevLoc.GroupLocationTypeValueId = prevLocationType.Id;
                                        prevLoc.IsMailingLocation = false;
                                        prevLoc.IsMappedLocation = false;
                                    }
                                }
                            }

                            string addressChangeField = locationType.Value;

                            var groupLocation = groupLocationService.Queryable()
                                .Where( gl =>
                                    gl.GroupId == family.Id &&
                                    gl.LocationId == location.Id )
                                .FirstOrDefault();
                            if ( groupLocation == null )
                            {
                                groupLocation = new GroupLocation();
                                groupLocation.Location = location;
                                groupLocation.IsMailingLocation = true;
                                groupLocation.IsMappedLocation = true;
                                family.GroupLocations.Add( groupLocation );
                            }
                            groupLocation.GroupLocationTypeValueId = locationType.Id;

                            History.EvaluateChange( familyChanges, addressChangeField, string.Empty, groupLocation.Location.ToString() );
                            History.EvaluateChange( familyChanges, addressChangeField + " Is Mailing", string.Empty, groupLocation.IsMailingLocation.ToString() );
                            History.EvaluateChange( familyChanges, addressChangeField + " Is Map Location", string.Empty, groupLocation.IsMappedLocation.ToString() );

                            rockContext.SaveChanges();

                            foreach ( var fm in family.Members )
                            {
                                HistoryService.SaveChanges( rockContext, typeof( Person ), Rock.SystemGuid.Category.HISTORY_PERSON_FAMILY_CHANGES.AsGuid(),
                                    fm.PersonId, familyChanges, family.Name, typeof( Group ), family.Id );
                            }
                        }
                    }
                }
            }
        }