Esempio n. 1
0
        /// <summary>
        /// Data type factory methods. This methods can be override to extend exist member type to new
        /// </summary>
        /// <param name="member"></param>
        /// <returns></returns>
        protected virtual dataModel.Member ConvertToDataMember(Member member, PrimaryKeyResolvingMap pkMap)
        {
            dataModel.Member retVal = null;
            var contact             = member as Contact;
            var org = member as Organization;

            if (contact != null)
            {
                retVal = contact.ToDataModel(pkMap);
            }
            if (org != null)
            {
                retVal = org.ToDataModel(pkMap);
            }
            return(retVal);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        /// <summary>
        /// Converting to model type
        /// </summary>
        /// <param name="dbEntity"></param>
        /// <returns></returns>
        public static coreModel.Member ToCoreModel(this dataModel.Member dbEntity, coreModel.Member member)
        {
            if (dbEntity == null)
            {
                throw new ArgumentNullException("dbEntity");
            }
            var memberType = member.MemberType;

            member.InjectFrom(dbEntity);
            member.MemberType = memberType;

            member.Addresses = dbEntity.Addresses.OrderBy(x => x.Id).Select(x => x.ToCoreModel()).ToList();
            member.Emails    = dbEntity.Emails.OrderBy(x => x.Id).Select(x => x.Address).ToList();
            member.Notes     = dbEntity.Notes.OrderBy(x => x.Id).Select(x => x.ToCoreModel()).ToList();
            member.Phones    = dbEntity.Phones.OrderBy(x => x.Id).Select(x => x.Number).ToList();
            return(member);
        }
Esempio n. 4
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*/ });
            }
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
 public override MemberDataEntity FromModel(Member member, PrimaryKeyResolvingMap pkMap)
 {
     //Call base converter
     return(base.FromModel(member, pkMap));
 }
Esempio n. 7
0
 public override Member ToModel(Member member)
 {
     //Call base converter first
     base.ToModel(member);
     return(member);
 }