Exemple #1
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);
        }
Exemple #2
0
        public virtual Member ToMember(Member member)
        {
            if (member == null)
            {
                throw new ArgumentNullException("member");
            }

            //preserve member type
            var memberType = member.MemberType;

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

            member.Addresses = this.Addresses.OrderBy(x => x.Id).Select(x => x.ToAddress(new Address())).ToList();
            member.Emails    = this.Emails.OrderBy(x => x.Id).Select(x => x.Address).ToList();
            member.Notes     = this.Notes.OrderBy(x => x.Id).Select(x => x.ToNote(new Note())).ToList();
            member.Phones    = this.Phones.OrderBy(x => x.Id).Select(x => x.Number).ToList();

            return(member);
        }
        public virtual Member ToModel(Member member)
        {
            if (member == null)
            {
                throw new ArgumentNullException(nameof(member));
            }

            //preserve member type
            var memberType = member.MemberType;

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

            member.Addresses = Addresses.OrderBy(x => x.Id).Select(x => x.ToModel(AbstractTypeFactory <Address> .TryCreateInstance())).ToList();
            member.Emails    = Emails.OrderBy(x => x.Id).Select(x => x.Address).ToList();
            member.Notes     = Notes.OrderBy(x => x.Id).Select(x => x.ToModel(new Note())).ToList();
            member.Phones    = Phones.OrderBy(x => x.Id).Select(x => x.Number).ToList();
            member.Groups    = Groups.OrderBy(x => x.Id).Select(x => x.Group).ToList();

            return(member);
        }
Exemple #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*/ });
            }
        }