From 41b2de7b1368587be9486820d5d669bfbcf513e2 Mon Sep 17 00:00:00 2001 From: Iliyan Iliev Date: Mon, 29 Jun 2020 15:27:47 +0300 Subject: [PATCH 1/2] Make partner contact fields optional --- .../LocationService.cs | 24 ++++++++++++++--- ...ce.PartnerManagement.DomainServices.csproj | 4 +-- .../ContactPersonModelValidation.cs | 27 ++++++++----------- 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/MAVN.Service.PartnerManagement.DomainServices/LocationService.cs b/src/MAVN.Service.PartnerManagement.DomainServices/LocationService.cs index 9999482..0259450 100644 --- a/src/MAVN.Service.PartnerManagement.DomainServices/LocationService.cs +++ b/src/MAVN.Service.PartnerManagement.DomainServices/LocationService.cs @@ -66,8 +66,13 @@ public async Task CreateLocationsContactPersonForPartnerAsync(Partner partner) _log.Info("Location creating", context: $"location: {location.ToJson()}"); - if(location.ContactPerson != null && !string.IsNullOrEmpty(location.ContactPerson.Email)) + if (location.ContactPerson != null && (!string.IsNullOrEmpty(location.ContactPerson.Email) || + !string.IsNullOrEmpty(location.ContactPerson.FirstName) || + !string.IsNullOrEmpty(location.ContactPerson.LastName) || + !string.IsNullOrEmpty(location.ContactPerson.PhoneNumber))) + { customerProfileCreateActions.Add(CreateOrUpdatePartnerContact(location)); + } } await Task.WhenAll(customerProfileCreateActions); @@ -120,8 +125,14 @@ public async Task CreateLocationsContactPersonForPartnerAsync(Partner partner) await SetCountryIso3Code(location); _log.Info("Location updating", context: $"location: {location.ToJson()}"); - if (location.ContactPerson != null && !string.IsNullOrEmpty(location.ContactPerson.Email)) + + if (location.ContactPerson != null && (!string.IsNullOrEmpty(location.ContactPerson.Email) || + !string.IsNullOrEmpty(location.ContactPerson.FirstName) || + !string.IsNullOrEmpty(location.ContactPerson.LastName) || + !string.IsNullOrEmpty(location.ContactPerson.PhoneNumber))) + { customerProfileUpdateActions.Add(CreateOrUpdatePartnerContact(location)); + } else deleteActions.Add(_customerProfileClient.PartnerContact.DeleteIfExistAsync(location.Id.ToString())); } @@ -138,8 +149,13 @@ public async Task CreateLocationsContactPersonForPartnerAsync(Partner partner) _log.Info("Location creating", context: $"location: {location.ToJson()}"); - if (location.ContactPerson != null && !string.IsNullOrEmpty(location.ContactPerson.Email)) + if (location.ContactPerson != null && (!string.IsNullOrEmpty(location.ContactPerson.Email) || + !string.IsNullOrEmpty(location.ContactPerson.FirstName) || + !string.IsNullOrEmpty(location.ContactPerson.LastName) || + !string.IsNullOrEmpty(location.ContactPerson.PhoneNumber))) + { customerProfileCreateActions.Add(CreateOrUpdatePartnerContact(location)); + } } } @@ -185,7 +201,7 @@ private async Task CreateOrUpdatePartnerContact(Location location) LocationId = location.Id.ToString(), FirstName = location.ContactPerson.FirstName, LastName = location.ContactPerson.LastName, - Email = location.ContactPerson.Email.ToLower(), + Email = location.ContactPerson.Email?.ToLower(), PhoneNumber = location.ContactPerson.PhoneNumber }); } diff --git a/src/MAVN.Service.PartnerManagement.DomainServices/MAVN.Service.PartnerManagement.DomainServices.csproj b/src/MAVN.Service.PartnerManagement.DomainServices/MAVN.Service.PartnerManagement.DomainServices.csproj index 6d6e3c4..37e2893 100644 --- a/src/MAVN.Service.PartnerManagement.DomainServices/MAVN.Service.PartnerManagement.DomainServices.csproj +++ b/src/MAVN.Service.PartnerManagement.DomainServices/MAVN.Service.PartnerManagement.DomainServices.csproj @@ -8,10 +8,10 @@ - + - + diff --git a/src/MAVN.Service.PartnerManagement/Models/Validation/ContactPerson/ContactPersonModelValidation.cs b/src/MAVN.Service.PartnerManagement/Models/Validation/ContactPerson/ContactPersonModelValidation.cs index 9e65e7f..b319d62 100644 --- a/src/MAVN.Service.PartnerManagement/Models/Validation/ContactPerson/ContactPersonModelValidation.cs +++ b/src/MAVN.Service.PartnerManagement/Models/Validation/ContactPerson/ContactPersonModelValidation.cs @@ -11,39 +11,34 @@ public class ContactPersonModelValidation : AbstractValidator p.FirstName) - .NotNull() - .NotEmpty() - .When(x => !string.IsNullOrEmpty(x.Email) || !string.IsNullOrEmpty(x.LastName) || !string.IsNullOrEmpty(x.PhoneNumber)) .MinimumLength(2) .MaximumLength(50) .WithMessage("The First Name should be present and within a range of 2 to 50 characters long.") .Must(o => o != null && _onlyLettersRegex.IsMatch(o)) - .WithMessage("First Name should contains only letters"); + .WithMessage("First Name should contains only letters") + .When(x => !string.IsNullOrEmpty(x.FirstName)); RuleFor(p => p.LastName) - .NotNull() - .NotEmpty() - .When(x => !string.IsNullOrEmpty(x.Email) || !string.IsNullOrEmpty(x.FirstName) || !string.IsNullOrEmpty(x.PhoneNumber)) .MinimumLength(2) .MaximumLength(50) .WithMessage("The Last Name should be present and within a range of 2 to 50 characters long.") .Must(o => o != null && _onlyLettersRegex.IsMatch(o)) - .WithMessage("Last Name should contains only letters"); + .WithMessage("Last Name should contains only letters") + .When(x => !string.IsNullOrEmpty(x.LastName)); + RuleFor(p => p.Email) - .NotNull() - .NotEmpty() - .When(x => !string.IsNullOrEmpty(x.FirstName) || !string.IsNullOrEmpty(x.LastName) || !string.IsNullOrEmpty(x.PhoneNumber)) .EmailAddress() - .WithMessage("The Email should be present and within a valid email address."); + .WithMessage("The Email should be present and within a valid email address.") + .When(x => !string.IsNullOrEmpty(x.Email)); + RuleFor(p => p.PhoneNumber) - .NotNull() - .NotEmpty() - .When(x => !string.IsNullOrEmpty(x.Email) || !string.IsNullOrEmpty(x.FirstName) || !string.IsNullOrEmpty(x.LastName)) .MinimumLength(3) .MaximumLength(30) - .WithMessage("The Phone number should be present and within a range of 3 to 30 characters long."); + .WithMessage("The Phone number should be present and within a range of 3 to 30 characters long.") + .When(x => !string.IsNullOrEmpty(x.PhoneNumber)); + } } } From 3faabcc70af6a57f9b8f203f3563ef6fb6049a51 Mon Sep 17 00:00:00 2001 From: Iliyan Iliev Date: Mon, 29 Jun 2020 15:29:25 +0300 Subject: [PATCH 2/2] remove blank lines --- .../Validation/ContactPerson/ContactPersonModelValidation.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/MAVN.Service.PartnerManagement/Models/Validation/ContactPerson/ContactPersonModelValidation.cs b/src/MAVN.Service.PartnerManagement/Models/Validation/ContactPerson/ContactPersonModelValidation.cs index b319d62..4ff225c 100644 --- a/src/MAVN.Service.PartnerManagement/Models/Validation/ContactPerson/ContactPersonModelValidation.cs +++ b/src/MAVN.Service.PartnerManagement/Models/Validation/ContactPerson/ContactPersonModelValidation.cs @@ -26,19 +26,16 @@ public ContactPersonModelValidation() .WithMessage("Last Name should contains only letters") .When(x => !string.IsNullOrEmpty(x.LastName)); - RuleFor(p => p.Email) .EmailAddress() .WithMessage("The Email should be present and within a valid email address.") .When(x => !string.IsNullOrEmpty(x.Email)); - RuleFor(p => p.PhoneNumber) .MinimumLength(3) .MaximumLength(30) .WithMessage("The Phone number should be present and within a range of 3 to 30 characters long.") .When(x => !string.IsNullOrEmpty(x.PhoneNumber)); - } } }