예제 #1
0
        internal static void UpdateContact(this Mapper mapper, Sample.Business.Contact source, Contact target)
        {
            // Verify null args:
            if (Object.ReferenceEquals(source, null))
            {
                return;
            }
            else if (Object.ReferenceEquals(target, null))
            {
                throw new Max.Domain.Mapping.MappingException("No target provided to map Contact on.");
            }

            // Perform base type mapping:
            mapper.UpdateBaseObject(source, target);

            // Perform mapping of properties:
            target.Id           = source.ContactID;
            target.Title        = source.Title;
            target.FirstName    = source.FirstName;
            target.MiddleName   = source.MiddleName;
            target.LastName     = source.LastName;
            target.Suffix       = source.Suffix;
            target.EmailAddress = source.EmailAddress;
            target.Phone        = source.Phone;

            // Call partial AfterUpdate method:
            AfterUpdateContact(mapper, source, target);
        }
예제 #2
0
 public static Contact MapToContact(this Mapper mapper, Sample.Business.Contact source)
 {
     if (source == null)
     {
         return(null);
     }
     else
     {
         return(mapper.MapToContact(source, new Contact()));
     }
 }
        public static Sample.Business.Contact MapFromContact(this ReverseMapper mapper, Contact source, Sample.Business.Contact target)
        {
            // Null maps to null:
            if (source == null)
            {
                return(null);
            }

            // Check if object already mapped (as in circular reference scenarios):
            object mappedTarget = mapper.GetMappedTarget(source);

            if (Object.ReferenceEquals(mappedTarget, null) == false)
            {
                return((Sample.Business.Contact)mappedTarget);
            }

            // Retrieve target object:
            if (target == null)
            {
                target = mapper.TryGetTarget <Sample.Business.Contact>(source);
            }
            if ((target == null) && (mapper.CanCreate(typeof(Sample.Business.Contact))))
            {
                mapper.RegisterAsNewObject(target = new Sample.Business.Contact());
            }
            if (target == null)
            {
                throw new Max.Domain.Mapping.MappingException(String.Format("Cannot map {0} to an existing instance.", source.GetType().Name));
            }

            // Register mapping:
            mapper.RegisterMapping(source, target);

            // Perform mapping:
            if (mapper.CanUpdate(target))
            {
                mapper.UpdateContact(source, target);
            }

            // Return target:
            return(target);
        }
예제 #4
0
        internal static Contact MapToContact(this Mapper mapper, Sample.Business.Contact source, Contact target)
        {
            // Null maps to null:
            if (source == null)
            {
                return(null);
            }

            // Check if object already mapped (as in circular reference scenarios):
            object mappedTarget = mapper.GetMappedTarget(source);

            // If so, return mapped instance:
            if (Object.ReferenceEquals(mappedTarget, null) == false)
            {
                return((Contact)mappedTarget);
            }

            // Else, register mapping and map target:
            mapper.RegisterMapping(source, target);
            mapper.UpdateContact(source, target);

            // Return mapped target:
            return(target);
        }
        internal static void UpdateContact(this ReverseMapper mapper, Contact source, Sample.Business.Contact target)
        {
            // Verify null args:
            if (Object.ReferenceEquals(source, null))
            {
                return;
            }
            else if (Object.ReferenceEquals(target, null))
            {
                throw new Max.Domain.Mapping.MappingException("No target provided to map Contact on.");
            }

            // Map source to target:
            mapper.UpdateBaseObject(source, target);
            if (target.ContactID != source.Id)
            {
                target.ContactID = source.Id;
            }
            if (target.Title != source.Title)
            {
                target.Title = (String.IsNullOrWhiteSpace(source.Title)) ? null : source.Title.Trim();
            }
            if (target.FirstName != source.FirstName)
            {
                target.FirstName = (String.IsNullOrWhiteSpace(source.FirstName)) ? null : source.FirstName.Trim();
            }
            if (target.MiddleName != source.MiddleName)
            {
                target.MiddleName = (String.IsNullOrWhiteSpace(source.MiddleName)) ? null : source.MiddleName.Trim();
            }
            if (target.LastName != source.LastName)
            {
                target.LastName = (String.IsNullOrWhiteSpace(source.LastName)) ? null : source.LastName.Trim();
            }
            if (target.Suffix != source.Suffix)
            {
                target.Suffix = (String.IsNullOrWhiteSpace(source.Suffix)) ? null : source.Suffix.Trim();
            }
            if (target.EmailAddress != source.EmailAddress)
            {
                target.EmailAddress = (String.IsNullOrWhiteSpace(source.EmailAddress)) ? null : source.EmailAddress.Trim();
            }
            if (target.Phone != source.Phone)
            {
                target.Phone = (String.IsNullOrWhiteSpace(source.Phone)) ? null : source.Phone.Trim();
            }

            // Call partial AfterUpdate method:
            AfterUpdateContact(mapper, source, target);
        }
 static partial void AfterUpdateContact(this ReverseMapper mapper, Contact source, Sample.Business.Contact target);