/// <summary>
 /// Patch 
 /// </summary>
 /// <param name="source"></param>
 /// <param name="target"></param>
 public static void Patch(this dataModel.ContactPropertyValue source, dataModel.ContactPropertyValue target)
 {
     var patchInjectionPolicy = new PatchInjection<dataModel.ContactPropertyValue>(x => x.BooleanValue, x => x.DateTimeValue,
                                                                                   x => x.DecimalValue, x => x.IntegerValue,
                                                                                   x => x.ShortTextValue, x => x.LongTextValue, x => x.ValueType);
     target.InjectFrom(patchInjectionPolicy, source);
 }
 private static object GetPropertyValue(dataModel.ContactPropertyValue propValue)
 {
     object retVal = null;
     switch ((coreModel.PropertyValueType)propValue.ValueType)
     {
         case coreModel.PropertyValueType.Boolean:
             retVal = propValue.BooleanValue;
             break;
         case coreModel.PropertyValueType.DateTime:
             retVal = propValue.DateTimeValue;
             break;
         case coreModel.PropertyValueType.Decimal:
             retVal = propValue.DecimalValue;
             break;
         case coreModel.PropertyValueType.Integer:
             retVal = propValue.IntegerValue;
             break;
         case coreModel.PropertyValueType.LongText:
             retVal = propValue.LongTextValue;
             break;
         case coreModel.PropertyValueType.ShortText:
             retVal = propValue.ShortTextValue;
             break;
     }
     return retVal;
 }
Example #3
0
        /// <summary>
        /// Patch changes
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
        public static void Patch(this dataModel.Contact source, dataModel.Contact target)
        {
            if (target == null)
                throw new ArgumentNullException("target");

            var patchInjection = new PatchInjection<dataModel.Contact>(x => x.FirstName, x => x.MiddleName, x => x.LastName, x=> x.BirthDate, x => x.DefaultLanguage,
                                                                           x => x.FullName, x => x.Salutation,
                                                                           x => x.TimeZone);
            target.InjectFrom(patchInjection, source);
            //Path base type properties
            ((dataModel.Member)source).Patch(target);
        }
Example #4
0
        public static dataModel.Member ToDataModel(this coreModel.Member member, dataModel.Member dbEntity)
        {
            if (member == null)
                throw new ArgumentNullException("member");

            dbEntity.InjectFrom(member);

            if (member.Phones != null)
            {
                dbEntity.Phones = new ObservableCollection<dataModel.Phone>(member.Phones.Select(x => new dataModel.Phone
                {
                    Number = x,
                    MemberId = member.Id
                }));
            }

            if (member.Emails != null)
            {
                dbEntity.Emails = new ObservableCollection<dataModel.Email>(member.Emails.Select(x => new dataModel.Email
                {
                    Address = x,
                    MemberId = member.Id
                }));
            }

            if (member.Addresses != null)
            {
                dbEntity.Addresses = new ObservableCollection<dataModel.Address>(member.Addresses.Select(x => x.ToDataModel()));
                foreach (var address in dbEntity.Addresses)
                {
                    address.MemberId = member.Id;
                }
            }

            if (member.Notes != null)
            {
                dbEntity.Notes = new ObservableCollection<dataModel.Note>(member.Notes.Select(x => x.ToDataModel()));
                foreach (var note in dbEntity.Notes)
                {
                    note.MemberId = member.Id;
                }
            }
            return dbEntity;
        }
Example #5
0
        /// <summary>
        /// Patch changes
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
        public static void Patch(this dataModel.Member source, dataModel.Member target)
        {
            if (target == null)
                throw new ArgumentNullException("target");

            var patchInjection = new PatchInjection<dataModel.Member>(x => x.Name);
            target.InjectFrom(patchInjection, source);

            if (!source.Phones.IsNullCollection())
            {
                var phoneComparer = AnonymousComparer.Create((dataModel.Phone x) => x.Number);
                source.Phones.Patch(target.Phones, phoneComparer, (sourcePhone, targetPhone) => targetPhone.Number = sourcePhone.Number);
            }

            if (!source.Emails.IsNullCollection())
            {
                var addressComparer = AnonymousComparer.Create((dataModel.Email x) => x.Address);
                source.Emails.Patch(target.Emails, addressComparer, (sourceEmail, targetEmail) => targetEmail.Address = sourceEmail.Address);
            }

            if (!source.Addresses.IsNullCollection())
            {
                source.Addresses.Patch(target.Addresses, new AddressComparer(), (sourceAddress, targetAddress) => sourceAddress.Patch(targetAddress));
            }

            if (!source.Notes.IsNullCollection())
            {
                var noteComparer = AnonymousComparer.Create((dataModel.Note x) => x.Id ?? x.Body);
                source.Notes.Patch(target.Notes, noteComparer, (sourceNote, targetNote) => sourceNote.Patch(targetNote));
            }

            if (!source.MemberRelations.IsNullCollection())
            {
                var relationComparer = AnonymousComparer.Create((dataModel.MemberRelation x) => x.AncestorId);
                source.MemberRelations.Patch(target.MemberRelations, relationComparer, (sourceRel, targetRel) => { /*Nothing todo*/ });
            }
        }
 private static void SetPropertyValue(dataModel.ContactPropertyValue retVal, coreModel.Property property)
 {
     switch (property.ValueType)
     {
         case coreModel.PropertyValueType.Boolean:
             retVal.BooleanValue = Convert.ToBoolean(property.Value);
             break;
         case coreModel.PropertyValueType.DateTime:
             retVal.DateTimeValue = Convert.ToDateTime(property.Value);
             break;
         case coreModel.PropertyValueType.Decimal:
             retVal.DecimalValue = Convert.ToDecimal(property.Value);
             break;
         case coreModel.PropertyValueType.Integer:
             retVal.IntegerValue = Convert.ToInt32(property.Value);
             break;
         case coreModel.PropertyValueType.LongText:
             retVal.LongTextValue = Convert.ToString(property.Value);
             break;
         case coreModel.PropertyValueType.ShortText:
             retVal.ShortTextValue = Convert.ToString(property.Value);
             break;
     }
 }
Example #7
0
        protected virtual Member ConvertToMember(dataModel.Member dbMember)
        {
            Member retVal = null;
            var dbContact = dbMember as dataModel.Contact;
            var dbOrg = dbMember as dataModel.Organization;

            if (dbContact != null)
            {
                var contact = dbContact.ToCoreModel();
                //Load all security accounts associated with this contact
                var result = Task.Run(() => _securityService.SearchUsersAsync(new UserSearchRequest { MemberId = contact.Id, TakeCount = int.MaxValue })).Result;
                contact.SecurityAccounts = result.Users.ToList();
                retVal = contact;
            }

            if (dbOrg != null)
            {
                retVal = dbOrg.ToCoreModel();
            }

            return retVal;
        }
        /// <summary>
        /// Patch changes
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
        public static void Patch(this dataModel.Contact source, dataModel.Contact target)
        {
            if (target == null)
                throw new ArgumentNullException("target");
            var patchInjection = new PatchInjection<dataModel.Contact>(x => x.BirthDate, x => x.DefaultLanguage,
                                                                           x => x.FullName, x => x.Salutation,
                                                                           x => x.TimeZone);
            target.InjectFrom(patchInjection, source);

            if (!source.Phones.IsNullCollection())
            {
                var phoneComparer = AnonymousComparer.Create((dataModel.Phone x) => x.Number);
                source.Phones.Patch(target.Phones, phoneComparer, (sourcePhone, targetPhone) => targetPhone.Number = sourcePhone.Number);
            }
            if (!source.Emails.IsNullCollection())
            {
                var addressComparer = AnonymousComparer.Create((dataModel.Email x) => x.Address);
                source.Emails.Patch(target.Emails, addressComparer, (sourceEmail, targetEmail) => targetEmail.Address = sourceEmail.Address);
            }
            if (!source.Addresses.IsNullCollection())
            {
                source.Addresses.Patch(target.Addresses, new AddressComparer(), (sourceAddress, targetAddress) => sourceAddress.Patch(targetAddress));
            }
            if (!source.ContactPropertyValues.IsNullCollection())
            {
                var propertyComparer = AnonymousComparer.Create((dataModel.ContactPropertyValue x) => x.Name);
                source.ContactPropertyValues.Patch(target.ContactPropertyValues, propertyComparer, (sourceProperty, targetProperty) => sourceProperty.Patch(targetProperty));
            }
            if (!source.Notes.IsNullCollection())
            {
                var noteComparer = AnonymousComparer.Create((dataModel.Note x) => x.Id ?? x.Body);
                source.Notes.Patch(target.Notes, noteComparer, (sourceNote, targetNote) => sourceNote.Patch(targetNote));
            }
            if (!source.MemberRelations.IsNullCollection())
            {
                var relationComparer = AnonymousComparer.Create((dataModel.MemberRelation x) => x.Id);
                source.MemberRelations.Patch(target.MemberRelations, relationComparer, (sourceRel, targetRel) => { /*Nothing todo*/ });
            }
        }
Example #9
0
 /// <summary>
 /// Patch 
 /// </summary>
 /// <param name="source"></param>
 /// <param name="target"></param>
 public static void Patch(this dataModel.Note source, dataModel.Note target)
 {
     var patchInjectionPolicy = new PatchInjection<dataModel.Note>(x => x.Body, x => x.Title);
     target.InjectFrom(patchInjectionPolicy, source);
 }
        /// <summary>
        /// Patch changes
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
        public static void Patch(this dataModel.Organization source, dataModel.Organization target)
        {
            if (target == null)
                throw new ArgumentNullException("target");
            var patchInjection = new PatchInjection<dataModel.Organization>(x => x.Name, x => x.Description,
                                                                           x => x.OwnerId, x => x.OrgType,
                                                                           x => x.BusinessCategory);
            target.InjectFrom(patchInjection, source);

            if (!source.Phones.IsNullCollection())
            {
                var phoneComparer = AnonymousComparer.Create((dataModel.Phone x) => x.Number);
                source.Phones.Patch(target.Phones, phoneComparer, (sourcePhone, targetPhone) => targetPhone.Number = sourcePhone.Number);
            }
            if (!source.Emails.IsNullCollection())
            {
                var addressComparer = AnonymousComparer.Create((dataModel.Email x) => x.Address);
                source.Emails.Patch(target.Emails, addressComparer, (sourceEmail, targetEmail) => targetEmail.Address = sourceEmail.Address);
            }
            if (!source.Addresses.IsNullCollection())
            {
                source.Addresses.Patch(target.Addresses, new AddressComparer(), (sourceAddress, targetAddress) => sourceAddress.Patch(targetAddress));
            }
            if (!source.Notes.IsNullCollection())
            {
                var noteComparer = AnonymousComparer.Create((dataModel.Note x) => x.Id);
                source.Notes.Patch(target.Notes, noteComparer, (sourceNote, targetNote) => sourceNote.Patch(targetNote));
            }
        }