Skip to content

Commit

Permalink
PT-13804: create Member types via AbstractTypeFactory (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksavosteev authored Oct 25, 2023
1 parent 28ae532 commit a71e631
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,11 @@ public virtual async Task<IdentityResultResponse> Handle(InviteUserCommand reque
{
using var userManager = _userManagerFactory();

var contact = new Contact
{
FirstName = string.Empty,
LastName = string.Empty,
FullName = string.Empty,
Emails = new List<string> { email }
};
var contact = AbstractTypeFactory<Contact>.TryCreateInstance();
contact.FullName = string.Empty;
contact.LastName = string.Empty;
contact.FullName = string.Empty;
contact.Emails = new List<string> { email };

if (!string.IsNullOrEmpty(request.OrganizationId))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using VirtoCommerce.CustomerModule.Core.Model;
using VirtoCommerce.Platform.Core.Common;
using VirtoCommerce.ProfileExperienceApiModule.Data.Commands;
using VirtoCommerce.ProfileExperienceApiModule.Data.Models.RegisterOrganization;
using VirtoCommerce.TaxModule.Core.Model;
Expand All @@ -13,16 +14,19 @@ public ProfileMappingProfile()
{
CreateMap<Contact, Customer>();

CreateMap<CustomerModule.Core.Model.Address, TaxModule.Core.Model.Address>();
CreateMap<Address, TaxModule.Core.Model.Address>();

CreateMap<CreateOrganizationCommand, CustomerModule.Core.Model.Organization>()
.ConvertUsing((command, org, context) =>
CreateMap<CreateOrganizationCommand, Organization>()
.ConvertUsing((command, organization, context) =>
{
org = new CustomerModule.Core.Model.Organization { Name = command.Name, Addresses = command.Addresses };
return org;
organization = AbstractTypeFactory<Organization>.TryCreateInstance();
organization.Name = command.Name;
organization.Addresses = command.Addresses;

return organization;
});

CreateMap<UpdateOrganizationCommand, CustomerModule.Core.Model.Organization>()
CreateMap<UpdateOrganizationCommand, Organization>()
.ForMember(x => x.DynamicProperties, opt => opt.Ignore());

CreateMap<CreateContactCommand, Contact>()
Expand All @@ -34,35 +38,34 @@ public ProfileMappingProfile()
CreateMap<RegisteredOrganization, Organization>()
.ConvertUsing((input, result) =>
{
result = new Organization()
{
Name = input.Name,
Description = input.Description,
Addresses = input.Address == null ?
result = AbstractTypeFactory<Organization>.TryCreateInstance();
result.Name = input.Name;
result.Description = input.Description;

result.Addresses = input.Address == null ?
null :
new List<Address> { input.Address }
};
new List<Address> { input.Address };

return result;
});

CreateMap<RegisteredContact, Contact>()
.ConvertUsing((input, result) =>
{
result = new Contact()
{
FirstName = input.FirstName,
LastName = input.LastName,
MiddleName = input.MiddleName,
BirthDate = input.Birthdate,
About = input.About,
Phones = input.PhoneNumber == null ?
result = AbstractTypeFactory<Contact>.TryCreateInstance();
result.FirstName = input.FirstName;
result.LastName = input.LastName;
result.MiddleName = input.MiddleName;
result.BirthDate = input.Birthdate;
result.About = input.About;

result.Phones = input.PhoneNumber == null ?
null :
new List<string> { input.PhoneNumber },
Addresses = input.Address == null ?
new List<string> { input.PhoneNumber };

result.Addresses = input.Address == null ?
null :
new List<Address> { input.Address }
};
new List<Address> { input.Address };

return result;
});
Expand Down

0 comments on commit a71e631

Please sign in to comment.