/// <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);
        }
Esempio n. 2
0
        /// <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));
        }