public async Task <PhoneNumberViewModel> Handle(CreatePhoneNumberCommand request, CancellationToken cancellationToken = default) { var contact = await _db.Contacts.SingleOrDefaultAsync(c => c.Id == request.ContactId, cancellationToken); if (contact == null) { throw new RequestException(nameof(request.ContactId), "Contact with specified Id not found"); } var lib = PhoneNumberUtil.GetInstance(); var parsed = lib.Parse(request.Number, "HR"); var number = new Domain.PhoneNumber { ContactId = request.ContactId, Number = lib.Format(parsed, PhoneNumberFormat.E164) }; _db.PhoneNumbers.Add(number); await _db.SaveChangesAsync(cancellationToken); var result = new PhoneNumberViewModel(number); _logger.LogDebug("Phone number {@PhoneNumber} added to contact {ContactName} with id {ContactId}", number, contact.Name, contact.Id); var notification = new PhoneNumberAddedNotification(new ContactViewModel(contact), result); await _mediator.Publish(notification); return(result); }
private Domain.PhoneNumber MapPhoneNumber(PhoneNumber phoneNumber) { var dPn = new Domain.PhoneNumber(); dPn.Number = phoneNumber.Number; dPn.IsVerified = phoneNumber.IsVerified; dPn.VerificationCode = phoneNumber.VerificationCode; dPn.VerificationCodeCreatedDate = phoneNumber.VerificationCodeCreatedDate; return(dPn); }
private PhoneNumber MapPhoneNumber(Domain.PhoneNumber dPn, Guid personId) { var phoneNumber = new PhoneNumber(); phoneNumber.PersonId = personId; phoneNumber.Number = dPn.Number; phoneNumber.IsVerified = dPn.IsVerified; phoneNumber.VerificationCode = dPn.VerificationCode; phoneNumber.VerificationCodeCreatedDate = dPn.VerificationCodeCreatedDate; return(phoneNumber); }