protected override async Task Handle(RegisterUserCommand command) { IPDetail ipDetail = new FIL.Contracts.DataModels.IPDetail(); var country = _countryRepository.GetByAltId(new Guid(command.PhoneCode.Split("~")[1])); var user = new FIL.Contracts.DataModels.User { AltId = Guid.NewGuid(), Email = command.Email, Password = command.PasswordHash, RolesId = command.ChannelId == Channels.Feel ? 11 : 2, // TODO: XXX: Need a default CreatedBy = command.ModifiedBy, CreatedUtc = DateTime.UtcNow, UserName = command.UserName, FirstName = command.FirstName, LastName = command.LastName, PhoneCode = command.PhoneCode.Split("~")[0], PhoneNumber = command.PhoneNumber, ChannelId = command.ChannelId, SignUpMethodId = command.SignUpMethodId, IsEnabled = true, IsRASVMailOPT = command.IsMailOpt, CountryId = country.Id }; user.IPDetailId = user.IPDetailId == 0 ? null : user.IPDetailId; var userDetails = _userRepository.Save(user); if (command.ChannelId == Channels.Feel) { var feelUserAdditional = new FeelUserAdditionalDetail { UserId = Convert.ToInt32(userDetails.Id), OptedForMailer = Convert.ToBoolean(command.IsMailOpt), SocialLoginId = null, SignUpMethodId = Convert.ToInt32(command.SignUpMethodId), IsEnabled = true }; _feelUserAdditionalDetailRepository.Save(feelUserAdditional); } try { if (command.ReferralId != null) { var referral = _referralRepository.GetByAltId(Guid.Parse(command.ReferralId)); if (referral != null) { userDetails.ReferralId = referral.Id; } } ipDetail = _saveIPProvider.SaveIp(command.Ip); if (ipDetail != null) { userDetails.IPDetailId = ipDetail.Id; _userRepository.Save(userDetails); } } catch { ipDetail = null; } if (command.SiteId == Site.RASVSite) { await _mediator.Publish(new Events.Event.HubSpot.VisitorInfoEvent(user)); } }
protected override async Task <ICommandResult> Handle(RegisterUserWithOTPCommand command) { RegisterUserWithOTPCommandCommandResult response = new RegisterUserWithOTPCommandCommandResult(); IPDetail ipDetail = new FIL.Contracts.DataModels.IPDetail(); var user = new User(); if (command.ChannelId == Channels.Feel) { user = _userRepository.GetByEmailAndChannel(command.Email, command.ChannelId, null); } if (user == null) { var country = _countryRepository.GetByAltId(new Guid(command.PhoneCode.Split("~")[1])); var userModel = new User { AltId = Guid.NewGuid(), Email = command.Email, Password = command.PasswordHash, RolesId = command.ChannelId == Channels.Feel ? 11 : 2, CreatedBy = command.ModifiedBy, CreatedUtc = DateTime.UtcNow, UserName = command.UserName, FirstName = command.FirstName, LastName = command.LastName, PhoneCode = command.PhoneCode.Split("~")[0], PhoneNumber = command.PhoneNumber, ChannelId = command.ChannelId, SignUpMethodId = command.SignUpMethodId, IsEnabled = true, CountryId = country.Id }; userModel.IPDetailId = userModel.IPDetailId == 0 ? null : userModel.IPDetailId; userModel = _userRepository.Save(userModel); response.Success = true; response.User = userModel; try { if (command.ReferralId != null) { var referral = _referralRepository.GetByAltId(Guid.Parse(command.ReferralId)); if (referral != null) { userModel.ReferralId = referral.Id; } } ipDetail = _saveIPProvider.SaveIp(command.Ip); if (ipDetail != null) { userModel.IPDetailId = ipDetail.Id; _userRepository.Save(userModel); } } catch { ipDetail = null; } } else if (string.IsNullOrEmpty(user.PhoneCode) && string.IsNullOrEmpty(user.PhoneNumber)) { user.PhoneConfirmed = true; user.PhoneCode = command.PhoneCode; user.PhoneNumber = command.PhoneNumber; user = _userRepository.Save(user); response.Success = true; response.User = user; } else { response.EmailAlreadyRegistered = true; } return(response); }