public static customerDto.Contact ToContactDto(this Contact customer) { var retVal = new customerDto.Contact { Id = customer.Id, Name = customer.Name, FirstName = customer.FirstName, FullName = customer.FullName, LastName = customer.LastName, MiddleName = customer.MiddleName, Salutation = customer.Salutation, PhotoUrl = customer.PhotoUrl, MemberType = "Contact", }; if (!customer.UserGroups.IsNullOrEmpty()) { retVal.Groups = customer.UserGroups.ToArray(); } if (!customer.Addresses.IsNullOrEmpty()) { retVal.Addresses = new List <customerDto.Address>(); foreach (var address in customer.Addresses) { var addressDto = address.ToCustomerAddressDto(); if (string.IsNullOrEmpty(addressDto.FirstName)) { addressDto.FirstName = customer.FirstName; } if (string.IsNullOrEmpty(addressDto.LastName)) { addressDto.LastName = customer.LastName; } if (string.IsNullOrEmpty(addressDto.Email)) { addressDto.Email = customer.Email; } retVal.Addresses.Add(addressDto); } } if (!customer.Emails.IsNullOrEmpty()) { retVal.Emails = customer.Emails; } //TODO: It needs to be rework to support only a multiple organizations for a customer by design. if (customer.OrganizationId != null) { retVal.Organizations = new List <string>() { customer.OrganizationId }; } if (customer.OrganizationsIds != null) { retVal.Organizations = customer.OrganizationsIds.Concat(retVal.Organizations ?? Array.Empty <string>()).Distinct().ToArray(); } return(retVal); }
public virtual customerDto.Contact ToContactDto(Contact customer) { var retVal = new customerDto.Contact { Id = customer.Id, FirstName = customer.FirstName, FullName = customer.FullName, LastName = customer.LastName, MiddleName = customer.MiddleName, MemberType = "Contact" }; if (!customer.UserGroups.IsNullOrEmpty()) { retVal.Groups = customer.UserGroups.ToArray(); } if (!customer.Addresses.IsNullOrEmpty()) { retVal.Addresses = customer.Addresses.Select(ToCustomerAddressDto).ToList(); } if (!customer.Emails.IsNullOrEmpty()) { retVal.Emails = customer.Emails; } return(retVal); }
public virtual Contact ToContact(customerDto.Contact contactDto) { var result = new Contact { Id = contactDto.Id, MemberType = contactDto.MemberType, UserGroups = contactDto.Groups, FullName = contactDto.FullName, FirstName = contactDto.FirstName, LastName = contactDto.LastName, Emails = contactDto.Emails, TimeZone = contactDto.TimeZone, DefaultLanguage = contactDto.DefaultLanguage }; if (contactDto.Addresses != null) { result.Addresses = contactDto.Addresses.Select(ToAddress).ToList(); } result.DefaultBillingAddress = result.Addresses.FirstOrDefault(a => (a.Type & AddressType.Billing) == AddressType.Billing); result.DefaultShippingAddress = result.Addresses.FirstOrDefault(a => (a.Type & AddressType.Shipping) == AddressType.Shipping); if (contactDto.Emails != null) { result.Emails = contactDto.Emails; } if (!contactDto.DynamicProperties.IsNullOrEmpty()) { result.DynamicProperties = contactDto.DynamicProperties.Select(ToDynamicProperty).ToList(); } return(result); }
public static Contact ToContact(this customerDto.Contact contactDto) { var result = new Contact { Id = contactDto.Id, Name = contactDto.Name, MemberType = contactDto.MemberType, UserGroups = contactDto.Groups, FullName = contactDto.FullName, FirstName = contactDto.FirstName, LastName = contactDto.LastName, Emails = contactDto.Emails, TimeZone = contactDto.TimeZone, DefaultLanguage = contactDto.DefaultLanguage, OrganizationId = contactDto.Organizations?.FirstOrDefault(), OrganizationsIds = contactDto.Organizations, Salutation = contactDto.Salutation, PhotoUrl = contactDto.PhotoUrl, Title = contactDto.Title, }; if (contactDto.Addresses != null) { result.Addresses = contactDto.Addresses.Select(ToAddress).ToList(); } result.DefaultBillingAddress = result.Addresses .OrderBy(a => a.Id) .FirstOrDefault(a => contactDto.DefaultBillingAddressId != null && a.Id == contactDto.DefaultBillingAddressId) ?? result.Addresses .OrderBy(a => a.Id) .FirstOrDefault(a => a.Type.HasFlag(AddressType.Billing)); result.DefaultShippingAddress = result.Addresses .OrderBy(a => a.Id) .FirstOrDefault(a => contactDto.DefaultShippingAddressId != null && a.Id == contactDto.DefaultShippingAddressId) ?? result.Addresses .OrderBy(a => a.Id) .FirstOrDefault(a => a.Type.HasFlag(AddressType.Shipping)); if (contactDto.Emails != null) { result.Emails = contactDto.Emails; } if (!contactDto.DynamicProperties.IsNullOrEmpty()) { result.DynamicProperties = new MutablePagedList <DynamicProperty>(contactDto.DynamicProperties.Select(ToDynamicProperty).ToList()); } if (!contactDto.SecurityAccounts.IsNullOrEmpty()) { result.SecurityAccounts = contactDto.SecurityAccounts.Select(x => new SecurityAccount { Id = x.Id, Roles = x.Roles?.Select(role => role.Name).ToList(), IsLockedOut = (x.LockoutEndDateUtc ?? DateTime.MinValue) > DateTime.UtcNow, UserName = x.UserName, }); } return(result); }
public static customerDto.Contact ToContactDto(this Contact customer) { var retVal = new customerDto.Contact { Id = customer.Id, Name = customer.Name, FirstName = customer.FirstName, FullName = customer.FullName, LastName = customer.LastName, MiddleName = customer.MiddleName, Salutation = customer.Salutation, PhotoUrl = customer.PhotoUrl, MemberType = "Contact", }; if (!customer.UserGroups.IsNullOrEmpty()) { retVal.Groups = customer.UserGroups.ToArray(); } if (!customer.Addresses.IsNullOrEmpty()) { retVal.Addresses = new List <customerDto.Address>(); foreach (var address in customer.Addresses) { var addressDto = address.ToCustomerAddressDto(); if (string.IsNullOrEmpty(addressDto.FirstName)) { addressDto.FirstName = customer.FirstName; } if (string.IsNullOrEmpty(addressDto.LastName)) { addressDto.LastName = customer.LastName; } if (string.IsNullOrEmpty(addressDto.Email)) { addressDto.Email = customer.Email; } retVal.Addresses.Add(addressDto); } } if (!customer.Emails.IsNullOrEmpty()) { retVal.Emails = customer.Emails; } //Support only one organization then if (customer.OrganizationId != null) { retVal.Organizations = new List <string>() { customer.OrganizationId }; } return(retVal); }
public virtual customerDto.Contact ToCustomerContactDto(CustomerInfo customer) { var retVal = new customerDto.Contact(); retVal.InjectFrom <NullableAndEnumValueInjecter>(customer); if (customer.Addresses != null) { retVal.Addresses = customer.Addresses.Select(ToCustomerAddressDto).ToList(); } if (!string.IsNullOrEmpty(customer.Email)) { retVal.Emails = new[] { customer.Email }.ToList(); } retVal.FullName = customer.FullName; return(retVal); }
public virtual CustomerInfo ToCustomerInfo(customerDto.Contact contactDto) { var result = ServiceLocator.Current.GetInstance <CustomerFactory>().CreateCustomerInfo(); result.InjectFrom <NullableAndEnumValueInjecter>(contactDto); result.IsRegisteredUser = true; if (contactDto.Addresses != null) { result.Addresses = contactDto.Addresses.Select(ToAddress).ToList(); } result.DefaultBillingAddress = result.Addresses.FirstOrDefault(a => (a.Type & AddressType.Billing) == AddressType.Billing); result.DefaultShippingAddress = result.Addresses.FirstOrDefault(a => (a.Type & AddressType.Shipping) == AddressType.Shipping); // TODO: Need separate properties for first, middle and last name if (!string.IsNullOrEmpty(contactDto.FullName)) { var nameParts = contactDto.FullName.Split(_nameSeparator, 2); if (nameParts.Length > 0) { result.FirstName = nameParts[0]; } if (nameParts.Length > 1) { result.LastName = nameParts[1]; } } if (contactDto.Emails != null) { result.Email = contactDto.Emails.FirstOrDefault(); } if (!contactDto.DynamicProperties.IsNullOrEmpty()) { result.DynamicProperties = contactDto.DynamicProperties.Select(ToDynamicProperty).ToList(); } return(result); }
public static CustomerInfo ToCustomerInfo(this customerDto.Contact contactDto) { return(CustomerConverterInstance.ToCustomerInfo(contactDto)); }