Ejemplo n.º 1
0
        /// <summary>
        /// Convert a DbCustomer into a domain Customer
        /// </summary>
        public static Customer FromDbCustomer(DbCustomer sqlCustomer)
        {
            if (sqlCustomer == null)
            {
                return(null);
            }

            var id    = CustomerId.Create(sqlCustomer.Id);
            var name  = PersonalName.Create(sqlCustomer.FirstName, sqlCustomer.LastName);
            var email = EmailAddress.Create(sqlCustomer.Email);
            var cust  = Customer.Create(id, name, email);

            return(cust);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create a domain customer from a DTO or null if not valid.
        /// </summary>
        public static Customer DtoToCustomer(CustomerDto dto)
        {
            if (dto == null)
            {
                // dto can be null if deserialization fails
                return(null);
            }

            var id    = CustomerId.Create(dto.Id);
            var name  = PersonalName.Create(dto.FirstName, dto.LastName);
            var email = EmailAddress.Create(dto.Email);
            var cust  = Customer.Create(id, name, email);

            return(cust);
        }