From a71e631ac641c40bc497ec76514e6009a6296fd8 Mon Sep 17 00:00:00 2001 From: Konstantin Savosteev Date: Wed, 25 Oct 2023 16:20:13 +0200 Subject: [PATCH] PT-13804: create Member types via AbstractTypeFactory (#62) --- .../Commands/InviteUserCommandHandler.cs | 12 ++--- .../Mapping/ProfileMappingProfile.cs | 53 ++++++++++--------- 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/VirtoCommerce.ProfileExperienceApiModule.Data/Commands/InviteUserCommandHandler.cs b/src/VirtoCommerce.ProfileExperienceApiModule.Data/Commands/InviteUserCommandHandler.cs index 7633f0ef..67692189 100644 --- a/src/VirtoCommerce.ProfileExperienceApiModule.Data/Commands/InviteUserCommandHandler.cs +++ b/src/VirtoCommerce.ProfileExperienceApiModule.Data/Commands/InviteUserCommandHandler.cs @@ -61,13 +61,11 @@ public virtual async Task Handle(InviteUserCommand reque { using var userManager = _userManagerFactory(); - var contact = new Contact - { - FirstName = string.Empty, - LastName = string.Empty, - FullName = string.Empty, - Emails = new List { email } - }; + var contact = AbstractTypeFactory.TryCreateInstance(); + contact.FullName = string.Empty; + contact.LastName = string.Empty; + contact.FullName = string.Empty; + contact.Emails = new List { email }; if (!string.IsNullOrEmpty(request.OrganizationId)) { diff --git a/src/VirtoCommerce.ProfileExperienceApiModule.Data/Mapping/ProfileMappingProfile.cs b/src/VirtoCommerce.ProfileExperienceApiModule.Data/Mapping/ProfileMappingProfile.cs index bc07180e..c2d9160f 100644 --- a/src/VirtoCommerce.ProfileExperienceApiModule.Data/Mapping/ProfileMappingProfile.cs +++ b/src/VirtoCommerce.ProfileExperienceApiModule.Data/Mapping/ProfileMappingProfile.cs @@ -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; @@ -13,16 +14,19 @@ public ProfileMappingProfile() { CreateMap(); - CreateMap(); + CreateMap(); - CreateMap() - .ConvertUsing((command, org, context) => + CreateMap() + .ConvertUsing((command, organization, context) => { - org = new CustomerModule.Core.Model.Organization { Name = command.Name, Addresses = command.Addresses }; - return org; + organization = AbstractTypeFactory.TryCreateInstance(); + organization.Name = command.Name; + organization.Addresses = command.Addresses; + + return organization; }); - CreateMap() + CreateMap() .ForMember(x => x.DynamicProperties, opt => opt.Ignore()); CreateMap() @@ -34,14 +38,13 @@ public ProfileMappingProfile() CreateMap() .ConvertUsing((input, result) => { - result = new Organization() - { - Name = input.Name, - Description = input.Description, - Addresses = input.Address == null ? + result = AbstractTypeFactory.TryCreateInstance(); + result.Name = input.Name; + result.Description = input.Description; + + result.Addresses = input.Address == null ? null : - new List
{ input.Address } - }; + new List
{ input.Address }; return result; }); @@ -49,20 +52,20 @@ public ProfileMappingProfile() CreateMap() .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.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 { input.PhoneNumber }, - Addresses = input.Address == null ? + new List { input.PhoneNumber }; + + result.Addresses = input.Address == null ? null : - new List
{ input.Address } - }; + new List
{ input.Address }; return result; });