private void AddProperty(string key, string label, int personId, string value, string formattedValue, bool selected = false)
        {
            var property      = GetProperty(key, true, label);
            var propertyValue = property.Values.Where(v => v.PersonId == personId).FirstOrDefault();

            if (propertyValue == null)
            {
                propertyValue = new PersonPropertyValue {
                    PersonId = personId
                };
                property.Values.Add(propertyValue);
            }
            propertyValue.Value          = value ?? string.Empty;
            propertyValue.FormattedValue = formattedValue ?? string.Empty;
            propertyValue.Selected       = selected;
        }
        /// <summary>
        /// Sets the primary.
        /// </summary>
        /// <param name="primaryPersonId">The primary person identifier.</param>
        public void SetPrimary(int primaryPersonId)
        {
            PrimaryPersonId = primaryPersonId;

            foreach (var personProperty in Properties)
            {
                PersonPropertyValue value = null;

                if (personProperty.Values.Any(v => v.Value != null && v.Value != ""))
                {
                    // Find primary person's non-blank value
                    value = personProperty.Values.Where(v => v.PersonId == primaryPersonId && v.Value != null && v.Value != "").FirstOrDefault();
                    if (value == null)
                    {
                        // Find any other selected value
                        value = personProperty.Values.Where(v => v.Selected).FirstOrDefault();
                        if (value == null)
                        {
                            // Find first non-blank value
                            value = personProperty.Values.Where(v => v.Value != "").FirstOrDefault();
                            if (value == null)
                            {
                                value = personProperty.Values.FirstOrDefault();
                            }
                        }
                    }
                }
                else
                {
                    value = personProperty.Values.Where(v => v.PersonId == primaryPersonId).FirstOrDefault();
                }

                // Unselect all the values
                personProperty.Values.ForEach(v => v.Selected = false);

                if (value != null)
                {
                    value.Selected = true;
                }
            }
        }
Example #3
0
 private void AddProperty( string key, string label, int personId, DefinedValue value, bool selected = false )
 {
     var property = GetProperty( key, true, label );
     var propertyValue = property.Values.Where( v => v.PersonId == personId ).FirstOrDefault();
     if ( propertyValue == null )
     {
         propertyValue = new PersonPropertyValue { PersonId = personId };
         property.Values.Add( propertyValue );
     }
     propertyValue.Value = value != null ? value.Id.ToString() : string.Empty;
     propertyValue.FormattedValue = value != null ? value.Value : string.Empty;
     propertyValue.Selected = selected;
 }