public async Task <int> SendOtpToMember(MemberRegistrationBO memberInfo) { var auditLogBO = new AuditLogBO(); var response = await _memberRegistrationService.SendOtpToMember(memberInfo, auditLogBO); return(response); }
public async Task <Tuple <int, string, string> > ValidateMember([FromBody] MemberRegistrationBO memberRegBO) { var auditLogBO = new AuditLogBO(); var response = await _memberVerifyService.IsMemberValid(memberRegBO, auditLogBO); return(response); }
public async Task <int> RegisterMember([FromBody] MemberRegistrationBO memberRegistration) { var auditLogBO = new AuditLogBO(); var statusCode = await _memberRegistrationService.RegisterMember(memberRegistration, auditLogBO); return(statusCode); }
/// <summary> /// Determines whether [is member valid] [the specified member reg bo]. /// </summary> /// <param name="memberRegBO">The member reg bo.</param> /// <param name="auditLogBO">The audit log bo.</param> /// <returns></returns> public Task <Tuple <int, string, string> > IsMemberValid(MemberRegistrationBO memberRegBO, AuditLogBO auditLogBO) { if (memberRegBO == null) { throw new CustomException(nameof(MemberConstants.MemberVerifyServiceIsMemberValidInputEmptyErrorCode)); } return(_memberVerifyDa.IsMemberValid(memberRegBO, auditLogBO)); }
/// <summary> /// Sends the otp to member. /// </summary> /// <param name="memberInfo">The member information.</param> /// <param name="auditLogBO">The audit log bo.</param> /// <returns></returns> /// <exception cref="CustomException">MemberRegistrationServiceSendOtpToMemberInputEmptyErrorCode</exception> public async Task <int> SendOtpToMember(MemberRegistrationBO memberInfo, AuditLogBO auditLogBO) { if (memberInfo == null) { throw new CustomException(nameof(MemberConstants.MemberRegistrationServiceSendOtpToMemberInputEmptyErrorCode)); } return(await _memberRegistrationDa.SendOtpToMember(memberInfo, auditLogBO)); }
/// <summary> /// Determines whether [is member valid] [the specified member reg bo]. /// </summary> /// <param name="memberRegBO">The member reg bo.</param> /// <param name="auditLogBO">The audit log bo.</param> /// <returns></returns> public async Task <Tuple <int, string, string> > IsMemberValid(MemberRegistrationBO memberRegBO, AuditLogBO auditLogBO) { var statusCode = MemberRegistrationVerification.InvalidMemberId; var externalId = memberRegBO.ExternalId; var memberVerificationStatus = await VerifyMemberDetails(memberRegBO, statusCode, externalId); await AuditMapper.MapAuditAndQueue(auditLogBO, AuditAction.Select, null); return(Tuple.Create((int)memberVerificationStatus.Item1, memberVerificationStatus.Item2, memberVerificationStatus.Item3)); }
/// <summary> /// Upates the member email and phone number. /// </summary> /// <param name="memberRegistration">The member registration.</param> private async Task UpateMemberEmailAndPhoneNumber(MemberRegistrationBO memberRegistration) { var memberDetailsRepo = _unitOfWork.GetRepository <MemberDetail>(); var memberDetails = await this.GetMemberDetailsForUpdateAsync(memberRegistration); if (memberDetails.Item2.MemberDetailId != 0) { memberDetailsRepo.Update(memberDetails.Item2); _unitOfWork.SaveChanges(); } }
/// <summary> /// Upates the email and phone number to admin123. /// </summary> /// <param name="memberRegistration">The member registration.</param> /// <returns></returns> private async Task <string> UpateEmailAndPhoneNumberToAdmin123(MemberRegistrationBO memberRegistration) { var admin123 = new Admin123Mapper(_unitOfWork); try { var memberDetails = await this.GetMemberDetailsForUpdateAsync(memberRegistration); if (!string.IsNullOrEmpty(memberDetails.Item1)) { var admin123BO = new Admin123BO { CORPID = _appSettings.Value.CorpId, AGENT = _appSettings.Value.AgentId, //UNIQUEID = $"{memberDetails.Item1}-{AppSettings.Environment}", LASTNAME = memberRegistration.LastName }; if (memberRegistration.UpdateToAdmin123 || (memberRegistration.EmailNotFound && memberRegistration.PhoneNumberNotFound)) { admin123BO.PHONE1 = memberRegistration.PhoneNumber; admin123BO.EMAIL = memberRegistration.Email; } else if (memberRegistration.EmailNotFound) { admin123BO.EMAIL = memberRegistration.Email; } else if (memberRegistration.PhoneNumberNotFound) { admin123BO.EMAIL = memberRegistration.PhoneNumber; } var memberDetailsObject = JsonConvert.SerializeObject(admin123BO); var uri = new Uri(_appSettings.Value.Admin123Url); var stringContent = new StringContent(memberDetailsObject, UnicodeEncoding.UTF8, "application/json"); var task = Task.Run(() => admin123.PostURIAsync(uri, stringContent, _appSettings.Value.Admin123User, _appSettings.Value.Admin123Password, memberDetailsObject, memberDetails.Item1)); task.Wait(); return(task.Result); } return(string.Empty); } catch (Exception ex) { await admin123.InsertAdmin123LogAsync(ex.StackTrace, ex.Message.ToString()); throw; } }
/// <summary> /// Registers the member. /// </summary> /// <param name="memberRegistration">The member registration.</param> /// <param name="auditLogBO">The audit log bo.</param> /// <returns></returns> /// <exception cref="CustomException"> /// MemberMemberForRegistrationEmptyErrorCode /// or /// MemberStatusForMemberRegisterMemberEmptyErrorCode /// </exception> public async Task <int> RegisterMember(MemberRegistrationBO memberRegistration, AuditLogBO auditLogBO) { if (memberRegistration == null) { throw new CustomException(nameof(MemberConstants.MemberMemberForRegistrationEmptyErrorCode)); } var statusCode = await _memberRegistrationDa.RegisterMember(memberRegistration, auditLogBO); if (statusCode == 0) { throw new CustomException(nameof(MemberConstants.MemberStatusForMemberRegisterMemberEmptyErrorCode)); } return(statusCode); }
/// <summary> /// Verifies the member details. /// </summary> /// <param name="memberRegistration">The member registration.</param> /// <param name="externalId">The external identifier.</param> /// <param name="statusCode">The status code.</param> /// <returns></returns> private async Task <MemberRegistrationVerification> VerifyMemberDetails(MemberRegistrationBO memberRegistration, string externalId, MemberRegistrationVerification statusCode) { var memberRepo = _unitOfWork.GetRepository <Member>(); var memberDependentRepo = _unitOfWork.GetRepository <MemberDependent>(); var memberDetailsRepo = _unitOfWork.GetRepository <MemberDetail>(); MemberDependent memDependentDetails; var memDetails = await memberRepo.GetFirstOrDefaultAsync(a => a, predicate : b => b.Admin123Id == externalId); if (memDetails == null) { memDetails = await memberRepo.GetFirstOrDefaultAsync(a => a, predicate : b => b.ExternalId == externalId); memDependentDetails = await memberDependentRepo.GetFirstOrDefaultAsync(a => a, predicate : b => b.ExternalId == externalId); } else { memDependentDetails = await memberDependentRepo.GetFirstOrDefaultAsync(a => a, predicate : b => b.Admin123Id == externalId); } if (memDetails != null) { statusCode = memDetails.UserId != null ? MemberRegistrationVerification.ExistingMember : MemberRegistrationVerification.Verified; if (statusCode == MemberRegistrationVerification.Verified) { memberRegistration.MemberId = memDetails.MemberId; memDetails.UserId = memberRegistration.UserId; memberRepo.Update(memDetails); } } else if (memDependentDetails != null) { statusCode = memDependentDetails.UserId != null ? MemberRegistrationVerification.ExistingMember : MemberRegistrationVerification.Verified; if (statusCode == MemberRegistrationVerification.Verified) { memberRegistration.MemberId = memDependentDetails.MemberId; memDependentDetails.UserId = memberRegistration.UserId; memberDependentRepo.Update(memDependentDetails); } } return(statusCode); }
/// <summary> /// Sends the otp to member. /// </summary> /// <param name="memberInfo">The member information.</param> /// <param name="auditLogBO">The audit log bo.</param> /// <returns></returns> /// <exception cref="Exception"></exception> public async Task <int> SendOtpToMember(MemberRegistrationBO memberInfo, AuditLogBO auditLogBO) { var sentOtpStatus = MemberRegistrationVerification.InvalidDetails; var member = await _unitOfWork.GetRepository <Member>().GetFirstOrDefaultAsync(predicate: m => m.ExternalId == memberInfo.ExternalId); if (member != null && memberInfo.Mode != 0 && !string.IsNullOrEmpty(memberInfo.ModeValue)) { var memberDetail = await _unitOfWork.GetRepository <MemberDetail>().GetFirstOrDefaultAsync( predicate: detail => detail.MemberDetailId == member.MemberDetailId); var rand = new Random(); var otpValue = rand.Next(100000, 999999); _memoryCache.Set(member.MemberId, otpValue); _memoryCache.Set(member.MemberId + MemberConstants.GeneratedTime, DateTime.Now); var notification = await _unitOfWork.GetRepository <Notification>().GetFirstOrDefaultAsync(predicate: n => n.Type == (int)EmailType.MemberRegistrationOtp); if (notification != null) { var otpMessageContent = notification.Content.Replace("{otp}", otpValue.ToString()); switch (memberInfo.Mode) { case (int)NotificationType.Email: var mailDetails = MemberMapper.Map(memberInfo.ModeValue, otpMessageContent, notification.Subject, _appSettings, notification.From); if (await _emailService.SendEmailAsync(mailDetails)) { sentOtpStatus = MemberRegistrationVerification.SentOtpSuccessfully; } break; case (int)NotificationType.Sms: var smsDetails = MemberMapper.Map(_appSettings.Value.CountryCode + memberInfo.ModeValue, otpMessageContent, _appSettings); if (_sMsService.SendMessage(smsDetails)) { sentOtpStatus = MemberRegistrationVerification.SentOtpSuccessfully; } break; default: break; } } } //await AuditMapper.AuditLogging(auditLogBO, null, AuditAction.Select, memberInfo); return((int)sentOtpStatus); }
/// <summary> /// Send an conformation mail to member registered mailID /// </summary> /// <param name="memberRegistration">MemberRegistrationBO</param> private async Task SendRegistrationConformationMail(MemberRegistrationBO memberRegistration) { if (memberRegistration != null) { var notificaton = await _unitOfWork.GetRepository <Notification>().GetFirstOrDefaultAsync(predicate: n => n.Type == (int)EmailType.MemberRegistrationSuccess); if (notificaton != null) { var subject = notificaton.Subject.Replace("{externalId}", memberRegistration.ExternalId); var message = notificaton.Content.Replace("{firstname}", memberRegistration.FirstName). Replace("{lastname}", memberRegistration.LastName). Replace("{loginPath}", _appSettings.Value.LoginPath); var emailDetails = MemberMapper.Map(memberRegistration.Email, message, subject, _appSettings, notificaton.From); await _emailService.SendEmailAsync(emailDetails); } } }
public static Users Map(MemberRegistrationBO memberRegistrationBO) { return(new Users { UserId = memberRegistrationBO.UserId, UserType = EntityType.Member, UserName = memberRegistrationBO.UserName, Email = memberRegistrationBO.Email, PortalId = 2, IsEmailVerified = memberRegistrationBO.EmailConfirmed, LockoutEnabled = true, FirstName = memberRegistrationBO.FirstName, LastName = memberRegistrationBO.LastName, Status = UserStatus.Active, PhoneNumber = memberRegistrationBO.PhoneNumber, CreatedBy = memberRegistrationBO.UserId, CreatedOn = DateTime.UtcNow, }); }
/// <summary> /// Registers the member. /// </summary> /// <param name="memberRegistration">The member registration.</param> /// <param name="auditLogBO">The audit log bo.</param> /// <returns></returns> public async Task <int> RegisterMember(MemberRegistrationBO memberRegistration, AuditLogBO auditLogBO) { bool isSuccessful; var externalId = memberRegistration.ExternalId; var statusCode = MemberRegistrationVerification.InvalidMemberId; var isRegistrationSuccessful = 0; if (!string.IsNullOrEmpty(externalId)) { statusCode = await VerifyMemberDetails(memberRegistration, externalId, statusCode); if (statusCode == MemberRegistrationVerification.Verified) { var user = MemberMapper.Map(memberRegistration); using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { try { //_unitOfWork.GetRepository<Users>().Insert(user); //_unitOfWork.DbContext.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Users ON"); //isRegistrationSuccessful += _unitOfWork.SaveChanges(); //_unitOfWork.DbContext.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Users OFF"); var newUserIdSecurityQA = memberRegistration.SecurityQuestionAnswer.Select(item => new UserSecurityQuestionAnswers { UserId = user.UserId, SecurityQuestionId = item.SecurityQuestionId, Answer = EncryptionHelper.HashCode(item.Answer), CreatedBy = item.CreatedBy, CreatedOn = DateTime.UtcNow, ModifiedBy = item.ModifiedBy, ModifiedOn = memberRegistration.ModifiedOn }); _unitOfWork.GetRepository <UserSecurityQuestionAnswers>().Insert(newUserIdSecurityQA); isRegistrationSuccessful += _unitOfWork.SaveChanges(); } catch (Exception ex) { scope.Dispose(); throw; } scope.Complete(); } isSuccessful = isRegistrationSuccessful > 0; if ((isSuccessful && memberRegistration.UpdateToAdmin123) || memberRegistration.PhoneNumberNotFound || memberRegistration.EmailNotFound) { await this.UpateMemberEmailAndPhoneNumber(memberRegistration); await this.UpateEmailAndPhoneNumberToAdmin123(memberRegistration); } await AuditMapper.AuditLogging(auditLogBO, null, AuditAction.Update, memberRegistration); } else { isSuccessful = false; } if (isSuccessful) { await SendRegistrationConformationMail(memberRegistration); } } return((int)statusCode); }
/// <summary> /// Gets the member details for update. /// </summary> /// <param name="memberRegistration">The member registration.</param> /// <returns></returns> private async Task <Tuple <string, MemberDetail> > GetMemberDetailsForUpdateAsync(MemberRegistrationBO memberRegistration) { var memberDetailsRepo = _unitOfWork.GetRepository <MemberDetail>(); var memberDetails = new MemberDetail(); var member = await _unitOfWork.GetRepository <Member>().GetFirstOrDefaultAsync(a => a, predicate: m => m.Admin123Id == memberRegistration.ExternalId || m.ExternalId == memberRegistration.ExternalId); if (member != null) { memberDetails = await memberDetailsRepo.GetFirstOrDefaultAsync(a => a, predicate : md => md.MemberDetailId == member.MemberDetailId); if (memberDetails != null) { if (memberRegistration.UpdateToAdmin123 || (memberRegistration.EmailNotFound && memberRegistration.PhoneNumberNotFound)) { memberDetails.PhoneNumber = memberRegistration.PhoneNumber; memberDetails.EmailId = memberRegistration.Email; } else if (memberRegistration.EmailNotFound) { memberDetails.EmailId = memberRegistration.Email; } else if (memberRegistration.PhoneNumberNotFound) { memberDetails.EmailId = memberRegistration.PhoneNumber; } } } return(Tuple.Create(member.ExternalId, memberDetails)); }
/// <summary> /// Verifies the member details. /// </summary> /// <param name="memberRegBO">The member reg bo.</param> /// <param name="statusCode">The status code.</param> /// <param name="externalId">The external identifier.</param> /// <returns></returns> private async Task <Tuple <MemberRegistrationVerification, string, string> > VerifyMemberDetails(MemberRegistrationBO memberRegBO, MemberRegistrationVerification statusCode, string externalId) { DateTime? dateOfBirth = memberRegBO.Dob; var memberRepo = _unitOfWork.GetRepository <Member>(); var memberDependentRepo = _unitOfWork.GetRepository <MemberDependent>(); var memberDetailsRepo = _unitOfWork.GetRepository <MemberDetail>(); MemberDependent memberDependentDetails; var phoneNUmber = string.Empty; var emailId = string.Empty; var memDetails = await memberRepo.GetFirstOrDefaultAsync(a => a, predicate : b => b.Admin123Id == externalId); if (memDetails == null) { memDetails = await memberRepo.GetFirstOrDefaultAsync(a => a, predicate : b => b.ExternalId == externalId); memberDependentDetails = await memberDependentRepo.GetFirstOrDefaultAsync(a => a, predicate : b => b.ExternalId == externalId); } else { memberDependentDetails = await memberDependentRepo.GetFirstOrDefaultAsync(a => a, predicate : b => b.Admin123Id == externalId); } if (memDetails != null) { statusCode = memDetails.UserId != null ? MemberRegistrationVerification.ExistingMember : MemberRegistrationVerification.ValidMemberId; //if valid memberId if (statusCode != MemberRegistrationVerification.ExistingMember) { var memAddress = await _unitOfWork.GetRepository <MemberAddress>().GetFirstOrDefaultAsync(a => a, predicate: b => b.MemberId == memDetails.MemberId); var memberDetails = await _unitOfWork.GetRepository <MemberDetail>().GetFirstOrDefaultAsync(a => a, predicate: b => b.MemberDetailId == memDetails.MemberDetailId); if (memAddress != null && memberDetails != null) { var memberDetailsResponse = await memberDetailsRepo.GetFirstOrDefaultAsync(a => a, predicate : b => b.MemberDetailId == memDetails.MemberDetailId && b.DateOfBirth.Date == dateOfBirth.Value.Date && b.FirstName.ToLower().Trim() == memberRegBO.FirstName.ToLower().Trim() && b.LastName.ToLower().Trim() == memberRegBO.LastName.ToLower().Trim() && memAddress.ZipCode == memberRegBO.ZipCode); statusCode = memberDetailsResponse != null ? MemberRegistrationVerification.Verified : MemberRegistrationVerification.InvalidDetails; if (statusCode.Equals(MemberRegistrationVerification.Verified)) { //phoneNumber or email null check and validation if value is not null var errorStatusCode = memberDetails.PhoneNumber == null && memberDetails.EmailId == null ? MemberRegistrationVerification.EmailIdAndPhoneNumberAreEmpty : (memberDetails.EmailId == null ? MemberRegistrationVerification.EmailIdEmpty : (memberDetails.PhoneNumber == null ? MemberRegistrationVerification.PhoneNumberEmpty : statusCode)); phoneNUmber = !string.IsNullOrEmpty(memberDetailsResponse.PhoneNumber) ? memberDetailsResponse.PhoneNumber.Substring(7, 3).PadLeft(10, '*') : null; emailId = !string.IsNullOrEmpty(memberDetailsResponse.EmailId) ? (memberDetailsResponse.EmailId.Split('@')[0].Substring(0, 2) + new string('*', memberDetailsResponse.EmailId.Split('@')[0].Length - 2) + "@" + memberDetailsResponse.EmailId.Split('@')[1]) : null; if (errorStatusCode != MemberRegistrationVerification.EmailIdAndPhoneNumberAreEmpty) { statusCode = (memberDetailsResponse.EmailId.ToLower() != memberRegBO.Email.ToLower() && memberDetailsResponse.PhoneNumber != memberRegBO.PhoneNumber) ? MemberRegistrationVerification.InvalidEmailIdAndPhoneNumber : (memberDetailsResponse.EmailId.ToLower() != memberRegBO.Email.ToLower() ? MemberRegistrationVerification.InvalidEmailId : (memberDetailsResponse.PhoneNumber != memberRegBO.PhoneNumber ? MemberRegistrationVerification.InvalidPhoneNumber : MemberRegistrationVerification.Verified)); statusCode = (errorStatusCode == MemberRegistrationVerification.EmailIdEmpty && statusCode == MemberRegistrationVerification.InvalidPhoneNumber) ? MemberRegistrationVerification.EmailIdEmptyAndInvalidPhoneNumber : ((errorStatusCode == MemberRegistrationVerification.PhoneNumberEmpty && statusCode == MemberRegistrationVerification.InvalidEmailId) ? MemberRegistrationVerification.PhoneNumberEmptyAndInvalidEmailId : statusCode); } } } else { statusCode = MemberRegistrationVerification.InvalidDetails; } } } else if (memberDependentDetails != null) { statusCode = memberDependentDetails.UserId != null ? MemberRegistrationVerification.ExistingMember : MemberRegistrationVerification.ValidMemberId; //if valid memberId if (statusCode != MemberRegistrationVerification.ExistingMember) { var memAddress = await _unitOfWork.GetRepository <MemberAddress>().GetFirstOrDefaultAsync(a => a, predicate: b => b.MemberId == memberDependentDetails.MemberId); var dependentDetails = await _unitOfWork.GetRepository <MemberDetail>().GetFirstOrDefaultAsync(a => a, predicate: b => b.MemberDetailId == memberDependentDetails.MemberDetailId); if (memAddress != null) { var memberDependentDetailsResponse = await memberDetailsRepo.GetFirstOrDefaultAsync(a => a, predicate : b => b.DateOfBirth.Date == dateOfBirth.Value.Date && b.MemberDetailId == memberDependentDetails.MemberDetailId && b.FirstName == memberRegBO.FirstName && b.LastName == memberRegBO.LastName && memAddress.ZipCode == memberRegBO.ZipCode); statusCode = memberDependentDetailsResponse != null ? MemberRegistrationVerification.Verified : MemberRegistrationVerification.InvalidDetails; if (statusCode.Equals(MemberRegistrationVerification.Verified)) { //phoneNumber or email null check and validation if value is not null var errorStatusCode = dependentDetails.PhoneNumber == null && dependentDetails.EmailId == null ? MemberRegistrationVerification.EmailIdAndPhoneNumberAreEmpty : (dependentDetails.EmailId == null ? MemberRegistrationVerification.EmailIdEmpty : (dependentDetails.PhoneNumber == null ? MemberRegistrationVerification.PhoneNumberEmpty : statusCode)); phoneNUmber = memberDependentDetailsResponse.PhoneNumber; emailId = memberDependentDetailsResponse.EmailId; if (errorStatusCode != MemberRegistrationVerification.EmailIdAndPhoneNumberAreEmpty) { statusCode = (memberDependentDetailsResponse.EmailId.ToLower() != memberRegBO.Email.ToLower() && memberDependentDetailsResponse.PhoneNumber != memberRegBO.PhoneNumber) ? MemberRegistrationVerification.InvalidEmailIdAndPhoneNumber : (memberDependentDetailsResponse.EmailId.ToLower() != memberRegBO.Email.ToLower() ? MemberRegistrationVerification.InvalidEmailId : (memberDependentDetailsResponse.PhoneNumber != memberRegBO.PhoneNumber ? MemberRegistrationVerification.InvalidPhoneNumber : MemberRegistrationVerification.Verified)); statusCode = (errorStatusCode == MemberRegistrationVerification.EmailIdEmpty && statusCode == MemberRegistrationVerification.InvalidPhoneNumber) ? MemberRegistrationVerification.EmailIdEmptyAndInvalidPhoneNumber : ((errorStatusCode == MemberRegistrationVerification.PhoneNumberEmpty && statusCode == MemberRegistrationVerification.InvalidEmailId) ? MemberRegistrationVerification.PhoneNumberEmptyAndInvalidEmailId : statusCode); } } } else { statusCode = MemberRegistrationVerification.InvalidDetails; } } } return(Tuple.Create(statusCode, phoneNUmber, emailId)); }