public PdrValidationResult ValidateRequest(AddDoctorRequest request)
        {
            var result = new PdrValidationResult(true);

            MissingRequiredFields(request, ref result);
            DoctorAlreadyInDb(request, ref result);
            EmailValidationHelper.CheckEmailIsValid(request.Email, ref result);

            return(result);
        }
Example #2
0
        public PdrValidationResult ValidateRequest(AddPatientRequest request)
        {
            var result = new PdrValidationResult(true);

            MissingRequiredFields(request, ref result);
            PatientAlreadyInDb(request, ref result);
            ClinicNotFound(request, ref result);
            EmailValidationHelper.CheckEmailIsValid(request.Email, ref result);

            return(result);
        }
Example #3
0
        public ActionResult SignUp(SignUpStep signUpStep, string allpass, string allmail)
        {
            if (ModelState.IsValid)
            {
                // Checking if the user isn't in the system yet.
                var user = _context.FullUsers.SingleOrDefault(fu => fu.finalMailID == signUpStep.Mail);

                if (user == null)
                {
                    FullUser newUser = new FullUser();
                    newUser.finalMailID = signUpStep.Mail;
                    newUser.finalPass   = signUpStep.Pass;
                    newUser.isVerifyed  = false;
                    newUser.allMail    += allmail;
                    _context.FullUsers.Add(newUser);
                    _context.SaveChanges();


                    string host = Url.Action("validate", "Login", new { id = 5 }, Request.Scheme);
                    host  = host.Substring(0, host.Length - 2);
                    host += "?";
                    EmailValidationHelper emailValidationHelper = new EmailValidationHelper(_context);
                    emailValidationHelper.SendMailValidation(newUser, host);

                    return(RedirectToAction("ValidationMailSent", "Index"));
                }
                else
                {
                    ViewBag.Message = "המשתמש כבר קיים במערכת";
                    ViewBag.back    = 1;
                    return(View("SignUp", signUpStep));
                }
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(signUpStep.Mail))
                {
                    var user = _context.FullUsers.SingleOrDefault(su => su.finalMailID == signUpStep.Mail);   //ElasticsearchUtils.Search(signUpStep.Mail);
                    if (user != null)
                    {
                        ViewBag.back    = 1;
                        ViewBag.Message = "המשתמש כבר קיים במערכת";
                        return(View("SignUp", signUpStep));
                    }
                }
            }

            signUpStep.Pass        = "";
            signUpStep.ConfirmPass = "";

            return(View("SignUp", signUpStep));
        }
Example #4
0
        public IActionResult NRICTypeValidation([FromHeader(Name = "Grid-General-Token")] string Token, [FromBody] NRIC IDDetails)
        {
            string _warningmsg = "";

            try
            {
                TokenValidationHelper tokenValidationHelper = new TokenValidationHelper();
                if (!tokenValidationHelper.ValidateGenericToken(Token, _iconfiguration))
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = Core.Extensions.EnumExtensions.GetDescription(DbReturnValue.TokenAuthFailed),
                        IsDomainValidationErrors = true
                    }));
                }

                EmailValidationHelper _helper = new EmailValidationHelper();
                if (_helper.NRICValidation(IDDetails.IDType, IDDetails.IDNumber, out _warningmsg))
                {
                    return(Ok(new ServerResponse
                    {
                        HasSucceeded = true,
                        Message = StatusMessages.ValidMessage
                    }));
                }
                else
                {
                    LogInfo.Warning("NRIC Validation: " + IDDetails.IDType + "_" + _warningmsg);
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = StatusMessages.InvalidMessage,
                        IsDomainValidationErrors = false
                    }));
                }
            }

            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));

                return(Ok(new OperationResponse
                {
                    HasSucceeded = false,
                    Message = (_warningmsg == "" ? StatusMessages.ServerError : StatusMessages.InvalidMessage),
                    IsDomainValidationErrors = false
                }));
            }
        }
Example #5
0
 public void Assign(MailMessageViewModel message)
 {
     Folder        = message.Folder;
     Type          = message.Type;
     Date          = message.Date;
     From          = message.From;
     SenderName    = message.SenderName;
     To            = EmailValidationHelper.NormalizeEmailsString(message.To);
     Subject       = message.Subject;
     Text          = message.Text;
     IsUnread      = message.IsUnread;
     IsReply       = message.IsReply;
     HasAttachment = message.HasAttachment;
     Priority      = message.Priority;
 }
Example #6
0
        public ActionResult ForgetPass(SignUpStep sus, string allmail)
        {
            string host = Url.Action("ResetPassword", "NewSignUp", new { id = 5 }, Request.Scheme);

            host  = host.Substring(0, host.Length - 2);
            host += "?";
            EmailValidationHelper emailValidationHelper = new EmailValidationHelper(_context);
            FullUser user = _context.FullUsers.SingleOrDefault(fu => fu.finalMailID == sus.Mail);

            // case email is not exist in DB
            if (user == null)
            {
                return(RedirectToAction("Error", "Index", new { eror = "string" }));
            }

            user.allMail += allmail;

            _context.Update(user);
            _context.SaveChanges();
            emailValidationHelper.SendMailValidation(user, host);
            return(RedirectToAction("ValidationMailSent", "Index"));
        }
Example #7
0
        public override bool IsValid(object value)
        {
            string mails = (string)value;

            if (string.IsNullOrWhiteSpace(mails))
            {
                return(false);
            }

            if (!MultipleEmails)
            {
                return(EmailValidationHelper.IsEmailValid(mails));
            }

            bool result    = true;
            bool hasValues = false;

            foreach (string email in EmailValidationHelper.ExtractEmails(mails))
            {
                result   &= EmailValidationHelper.IsEmailValid(email);
                hasValues = true;
            }
            return(result && hasValues);
        }
Example #8
0
        public async Task <IActionResult> UpdateNRICDetails([FromHeader(Name = "Grid-Authorization-Token")] string token, [FromForm] NRICDetails request)
        {
            try
            {
                if (string.IsNullOrEmpty(token))
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        IsDomainValidationErrors = true,
                        Message = EnumExtensions.GetDescription(CommonErrors.TokenEmpty)
                    }));
                }
                AdminUsersDataAccess _adminUsersDataAccess = new AdminUsersDataAccess(_iconfiguration);

                DatabaseResponse tokenAuthResponse = await _adminUsersDataAccess.AuthenticateAdminUserToken(token);

                if (tokenAuthResponse.ResponseCode == (int)DbReturnValue.AuthSuccess)
                {
                    if (!((AuthTokenResponse)tokenAuthResponse.Results).IsExpired)
                    {
                        if (!ModelState.IsValid)
                        {
                            return(StatusCode((int)HttpStatusCode.OK,
                                              new OperationResponse
                            {
                                HasSucceeded = false,
                                IsDomainValidationErrors = true,
                                Message = string.Join("; ", ModelState.Values
                                                      .SelectMany(x => x.Errors)
                                                      .Select(x => x.ErrorMessage))
                            }));
                        }

                        if (!string.IsNullOrEmpty(request.IdentityCardNumber))
                        {
                            EmailValidationHelper _helper = new EmailValidationHelper();
                            if (!_helper.NRICValidation(null, request.IdentityCardNumber, out string _warningmsg))
                            {
                                LogInfo.Warning("NRIC Validation with type: " + _warningmsg);
                                return(Ok(new OperationResponse
                                {
                                    HasSucceeded = false,
                                    Message = "Document details are invalid",
                                    IsDomainValidationErrors = false
                                }));
                            }
                        }

                        int deliveryStatusNumber = request.IDVerificationStatus;

                        var              authToken         = (AuthTokenResponse)tokenAuthResponse.Results;
                        MiscHelper       configHelper      = new MiscHelper();
                        CommonDataAccess _commonDataAccess = new CommonDataAccess(_iconfiguration);

                        NRICDetailsRequest personalDetails = new NRICDetailsRequest
                        {
                            OrderID            = request.OrderID,
                            IdentityCardNumber = request.IdentityCardNumber,
                            IdentityCardType   = request.IdentityCardType,
                            Nationality        = request.Nationality,
                            NameInNRIC         = request.NameInNRIC,
                            DOB     = request.DOB,
                            Expiry  = request.Expiry,
                            Remarks = request.Remarks,
                            IDVerificationStatus = request.IDVerificationStatus,
                        };

                        if (request.FrontImage != null || request.BackImage != null)
                        {
                            string IDCardNumberForImage = string.Empty;

                            DatabaseResponse awsConfigResponse = await _commonDataAccess.GetConfiguration(ConfiType.AWS.ToString());

                            if (awsConfigResponse != null && awsConfigResponse.ResponseCode == (int)DbReturnValue.RecordExists)
                            {
                                GridAWSS3Config awsConfig = configHelper.GetGridAwsConfig((List <Dictionary <string, string> >)awsConfigResponse.Results);
                                // Check for IdentityCardNumber
                                //Start
                                if (string.IsNullOrEmpty(request.IdentityCardNumber))
                                {
                                    var orderDetailsForIDCard = await _commonDataAccess.GetOrderDetails(request.OrderID);

                                    IDCardNumberForImage = orderDetailsForIDCard.IdentityCardNumber;
                                }
                                else
                                {
                                    IDCardNumberForImage = request.IdentityCardNumber;
                                }
                                //End
                                AmazonS3 s3Helper = new AmazonS3(awsConfig);
                                if (request.FrontImage != null)
                                {
                                    string fileNameFront = IDCardNumberForImage.Substring(1, IDCardNumberForImage.Length - 2) +
                                                           "_Front_" + DateTime.Now.ToString("yyMMddhhmmss") + Path.GetExtension(request.FrontImage.FileName); //Grid_IDNUMBER_yyyymmddhhmmss.extension

                                    UploadResponse s3UploadResponse = await s3Helper.UploadFile(request.FrontImage, fileNameFront);

                                    if (s3UploadResponse.HasSucceed)
                                    {
                                        personalDetails.FrontImage = awsConfig.AWSEndPoint + s3UploadResponse.FileName;
                                    }
                                    else
                                    {
                                        LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.S3UploadFailed));
                                    }
                                }
                                if (request.BackImage != null)
                                {
                                    string fileNameBack = IDCardNumberForImage.Substring(1, IDCardNumberForImage.Length - 2) + "_Back_" + DateTime.Now.ToString("yyMMddhhmmss")
                                                          + Path.GetExtension(request.BackImage.FileName); //Grid_IDNUMBER_yyyymmddhhmmss.extension

                                    UploadResponse s3UploadResponse = await s3Helper.UploadFile(request.BackImage, fileNameBack);

                                    if (s3UploadResponse.HasSucceed)
                                    {
                                        personalDetails.BackImage = awsConfig.AWSEndPoint + s3UploadResponse.FileName;
                                    }
                                    else
                                    {
                                        LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.S3UploadFailed));
                                    }
                                }
                            }
                            else
                            {
                                // unable to get aws config
                                LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.FailedToGetConfiguration));
                            }
                        }

                        var returnResponse = await _commonDataAccess.UpdateNRICDetails(authToken.CustomerID, deliveryStatusNumber, personalDetails);

                        if (returnResponse.ResponseCode == (int)DbReturnValue.UpdateSuccessSendEmail)
                        {
                            var emailDetails = (EmailResponse)returnResponse.Results;
                            DatabaseResponse configResponse        = new DatabaseResponse();
                            DatabaseResponse tokenCreationResponse = new DatabaseResponse();

                            string finalURL = string.Empty;
                            // Fetch the URL
                            if (emailDetails.VerificationStatus == 2) // Rejected then token
                            {
                                configResponse        = ConfigHelper.GetValueByKey(ConfigKeys.NRICReUploadLink.GetDescription(), _iconfiguration);
                                tokenCreationResponse = await _adminOrderDataAccess.CreateTokenForVerificationRequests(request.OrderID);

                                var tokenCreation = (VerificationRequestResponse)tokenCreationResponse.Results;
                                finalURL = configResponse.Results.ToString() + tokenCreation.RequestToken;
                            }
                            else
                            {
                                var result = await _commonDataAccess.UpdateTokenForVerificationRequests(request.OrderID);
                            }

                            //Sending message start
                            // Send email to customer email                            ConfigDataAccess _configAccess = new ConfigDataAccess(_iconfiguration);
                            DatabaseResponse registrationResponse = await _adminOrderDataAccess.GetEmailNotificationTemplate(emailDetails.VerificationStatus == 2?NotificationEvent.ICValidationReject.GetDescription() : NotificationEvent.ICValidationChange.GetDescription());

                            string[] changelog = emailDetails.ChangeLog.Split(";");
                            string   finallog  = "";
                            foreach (string log in changelog)
                            {
                                if (!string.IsNullOrWhiteSpace(log))
                                {
                                    finallog = finallog + "&bull; " + log.Trim() + "<br/>";
                                }
                            }
                            var notificationMessage = MessageHelper.GetMessage(emailDetails.Email, emailDetails.Name, emailDetails.VerificationStatus == 2 ? NotificationEvent.ICValidationReject.GetDescription() : NotificationEvent.ICValidationChange.GetDescription(),
                                                                               ((EmailTemplate)registrationResponse.Results).TemplateName,
                                                                               _iconfiguration, string.IsNullOrWhiteSpace(finalURL) ? "-" : finalURL, string.IsNullOrWhiteSpace(emailDetails.Remark) ? "-" : emailDetails.Remark.Replace(";", "<br />"), string.IsNullOrWhiteSpace(emailDetails.ChangeLog) ? "-" : finallog);
                            var notificationResponse = await _adminOrderDataAccess.GetConfiguration(ConfiType.Notification.ToString());


                            MiscHelper parser             = new MiscHelper();
                            var        notificationConfig = parser.GetNotificationConfig((List <Dictionary <string, string> >)notificationResponse.Results);

                            Publisher customerNotificationPublisher = new Publisher(_iconfiguration, notificationConfig.SNSTopic);
                            await customerNotificationPublisher.PublishAsync(notificationMessage);

                            try
                            {
                                DatabaseResponse notificationLogResponse = await _adminOrderDataAccess.CreateEMailNotificationLogForDevPurpose(
                                    new NotificationLogForDevPurpose
                                {
                                    EventType = NotificationEvent.OrderSuccess.ToString(),
                                    Message   = JsonConvert.SerializeObject(notificationMessage)
                                });
                            }
                            catch (Exception ex)
                            {
                                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));
                            }
                            //Sending message Stop
                            return(Ok(new ServerResponse
                            {
                                HasSucceeded = true,
                                Message = StatusMessages.SuccessMessage,
                                Result = null
                            }));
                        }
                        else if (returnResponse.ResponseCode == (int)DbReturnValue.UpdateSuccess)
                        {
                            var emailDetails = (EmailResponse)returnResponse.Results;
                            DatabaseResponse configResponse        = new DatabaseResponse();
                            DatabaseResponse tokenCreationResponse = new DatabaseResponse();
                            string           finalURL = string.Empty;
                            if (emailDetails.VerificationStatus == 2) // Rejected then token
                            {
                                configResponse        = ConfigHelper.GetValueByKey(ConfigKeys.NRICReUploadLink.GetDescription(), _iconfiguration);
                                tokenCreationResponse = await _adminOrderDataAccess.CreateTokenForVerificationRequests(request.OrderID);

                                var tokenCreation = (VerificationRequestResponse)tokenCreationResponse.Results;
                                finalURL = configResponse.Results.ToString() + tokenCreation.RequestToken;

                                DatabaseResponse registrationResponse = await _adminOrderDataAccess.GetEmailNotificationTemplate(NotificationEvent.ICValidationReject.GetDescription());

                                var notificationMessage = MessageHelper.GetMessage(emailDetails.Email, emailDetails.Name, NotificationEvent.ICValidationReject.GetDescription(),
                                                                                   ((EmailTemplate)registrationResponse.Results).TemplateName,
                                                                                   _iconfiguration, string.IsNullOrWhiteSpace(finalURL) ? "-" : finalURL, string.IsNullOrWhiteSpace(emailDetails.Remark) ? "-" : emailDetails.Remark.Replace(";", "<br />"), string.IsNullOrWhiteSpace(emailDetails.ChangeLog) ? "-" : emailDetails.ChangeLog);
                                var notificationResponse = await _adminOrderDataAccess.GetConfiguration(ConfiType.Notification.ToString());


                                MiscHelper parser             = new MiscHelper();
                                var        notificationConfig = parser.GetNotificationConfig((List <Dictionary <string, string> >)notificationResponse.Results);

                                Publisher customerNotificationPublisher = new Publisher(_iconfiguration, notificationConfig.SNSTopic);
                                await customerNotificationPublisher.PublishAsync(notificationMessage);

                                try
                                {
                                    DatabaseResponse notificationLogResponse = await _adminOrderDataAccess.CreateEMailNotificationLogForDevPurpose(
                                        new NotificationLogForDevPurpose
                                    {
                                        EventType = NotificationEvent.OrderSuccess.ToString(),
                                        Message   = JsonConvert.SerializeObject(notificationMessage)
                                    });
                                }
                                catch (Exception ex)
                                {
                                    LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));
                                }
                            }
                            else
                            {
                                var result = await _commonDataAccess.UpdateTokenForVerificationRequests(request.OrderID);
                            }

                            //Sending message start
                            // Send email to customer email                            ConfigDataAccess _configAccess = new ConfigDataAccess(_iconfiguration);


                            return(Ok(new ServerResponse
                            {
                                HasSucceeded = true,
                                Message = StatusMessages.SuccessMessage,
                                Result = null
                            }));
                        }
                        else
                        {
                            LogInfo.Error("UpdateNRICDetails failed for " + request.OrderID + " Order Id " + DbReturnValue.UpdationFailed);
                            return(Ok(new OperationResponse
                            {
                                HasSucceeded = false,
                                Message = EnumExtensions.GetDescription(DbReturnValue.UpdationFailed),
                                IsDomainValidationErrors = false
                            }));
                        }
                    }
                    else
                    {
                        //Token expired

                        LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.ExpiredToken));

                        return(Ok(new OperationResponse
                        {
                            HasSucceeded = false,
                            Message = EnumExtensions.GetDescription(DbReturnValue.TokenExpired),
                            IsDomainValidationErrors = true
                        }));
                    }
                }

                else
                {
                    // token auth failure
                    LogInfo.Warning(EnumExtensions.GetDescription(DbReturnValue.TokenAuthFailed));

                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.TokenAuthFailed),
                        IsDomainValidationErrors = false
                    }));
                }
            }
            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));

                return(Ok(new OperationResponse
                {
                    HasSucceeded = false,
                    Message = StatusMessages.ServerError,
                    IsDomainValidationErrors = false
                }));
            }
        }
 /// <summary>
 /// Determines whether or not a given string is a valid e-mail address strictly, according to ICANN rules and IANA list of valid TLDs.
 /// </summary>
 /// <param name="source">The source string.</param>
 /// <returns>
 ///     <c>true</c> if the source string is a strictly valid e-mail address; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsValidEmailAddressStrict(this string source) => EmailValidationHelper.IsAddressValid(source, true);
Example #10
0
        public async Task <IActionResult> EmailValidation([FromHeader(Name = "Grid-Authorization-Token")] string token, [FromRoute] string emailid)
        {
            try
            {
                if (string.IsNullOrEmpty(token))
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        IsDomainValidationErrors = true,
                        Message = EnumExtensions.GetDescription(CommonErrors.TokenEmpty)
                    }));
                }
                AdminUsersDataAccess _adminUsersDataAccess = new AdminUsersDataAccess(_iconfiguration);

                DatabaseResponse tokenAuthResponse = await _adminUsersDataAccess.AuthenticateAdminUserToken(token);

                if (tokenAuthResponse.ResponseCode == (int)DbReturnValue.AuthSuccess)
                {
                    if (!((AuthTokenResponse)tokenAuthResponse.Results).IsExpired)
                    {
                        if (!ModelState.IsValid)
                        {
                            LogInfo.Error(StatusMessages.DomainValidationError);
                            new OperationResponse
                            {
                                HasSucceeded             = false,
                                IsDomainValidationErrors = true,
                                Message = string.Join("; ", ModelState.Values
                                                      .SelectMany(x => x.Errors)
                                                      .Select(x => x.ErrorMessage))
                            };
                        }

                        DatabaseResponse configResponseEmail = ConfigHelper.GetValue("EmailValidate", _iconfiguration);

                        List <Dictionary <string, string> > _result = ((List <Dictionary <string, string> >)configResponseEmail.Results);

                        EmailValidationHelper emailhelper    = new EmailValidationHelper();
                        EmailConfig           objEmailConfig = new EmailConfig();
                        objEmailConfig.key         = _result.Single(x => x["key"] == "NeverbouceKey")["value"];
                        objEmailConfig.Email       = emailid;
                        objEmailConfig.EmailAPIUrl = _result.Single(x => x["key"] == "Emailurl")["value"];


                        string configResponse             = emailhelper.EmailValidation(objEmailConfig);
                        EmailValidationResponse _response = new EmailValidationResponse();
                        _response.Status = configResponse;
                        if (configResponse.ToLower().Trim() != "invalid")
                        {
                            _response.IsValid = true;
                            return(Ok(new ServerResponse
                            {
                                HasSucceeded = true,
                                Message = StatusMessages.ValidMessage,
                                Result = _response
                            }));
                        }
                        else
                        {
                            //Invalid email
                            _response.IsValid = false;

                            LogInfo.Error(EnumExtensions.GetDescription(CommonErrors.InvalidEmail));

                            return(Ok(new ServerResponse
                            {
                                HasSucceeded = true,
                                Message = StatusMessages.InvalidMessage,
                                Result = _response
                            }));
                        }
                    }

                    else
                    {
                        //Token expired

                        LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.ExpiredToken));

                        return(Ok(new OperationResponse
                        {
                            HasSucceeded = false,
                            Message = EnumExtensions.GetDescription(DbReturnValue.TokenExpired),
                            IsDomainValidationErrors = true
                        }));
                    }
                }
                else
                {
                    // token auth failure
                    LogInfo.Warning(EnumExtensions.GetDescription(DbReturnValue.TokenAuthFailed));

                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.TokenAuthFailed),
                        IsDomainValidationErrors = false
                    }));
                }
            }
            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));
                return(Ok(new OperationResponse
                {
                    HasSucceeded = false,
                    Message = StatusMessages.ServerError,
                    IsDomainValidationErrors = false
                }));
            }
        }
Example #11
0
        public IActionResult EmailValidation([FromHeader(Name = "Grid-General-Token")] string Token, [FromRoute] string emailid)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    LogInfo.Error(StatusMessages.DomainValidationError);
                    new OperationResponse
                    {
                        HasSucceeded             = false,
                        IsDomainValidationErrors = true,
                        Message = string.Join("; ", ModelState.Values
                                              .SelectMany(x => x.Errors)
                                              .Select(x => x.ErrorMessage))
                    };
                }
                TokenValidationHelper tokenValidationHelper = new TokenValidationHelper();
                if (!tokenValidationHelper.ValidateGenericToken(Token, _iconfiguration))
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.TokenAuthFailed),
                        IsDomainValidationErrors = true
                    }));
                }
                DatabaseResponse configResponseEmail = ConfigHelper.GetValue("EmailValidate", _iconfiguration);

                List <Dictionary <string, string> > _result = ((List <Dictionary <string, string> >)configResponseEmail.Results);
                string email1 = emailid;
                if (_result.Single(x => x["key"] == "AllowPlusSignEmailAddress")["value"] == "1")
                {
                    //Remove the Plus sign part from email before sending to neverbounce
                    Regex emailregx = new Regex("(\\+)(.*?)(\\@)"); //Replace the part after the plus "+) sign
                    email1 = emailregx.Replace(emailid, "$3");      //$3 to putback the @symbol
                }

                EmailValidationHelper emailhelper    = new EmailValidationHelper();
                EmailConfig           objEmailConfig = new EmailConfig();
                objEmailConfig.key         = _result.Single(x => x["key"] == "NeverbouceKey")["value"];
                objEmailConfig.Email       = email1;
                objEmailConfig.EmailAPIUrl = _result.Single(x => x["key"] == "Emailurl")["value"];

                string configResponse             = emailhelper.EmailValidation(objEmailConfig);
                EmailValidationResponse _response = new EmailValidationResponse();
                _response.Status = configResponse;
                if (configResponse.ToLower().Trim() != "invalid")
                {
                    _response.IsValid = true;
                    return(Ok(new ServerResponse
                    {
                        HasSucceeded = true,
                        Message = StatusMessages.ValidMessage,
                        Result = _response
                    }));
                }
                else
                {
                    //Invalid email
                    _response.IsValid = false;

                    LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.InvalidEmail));

                    return(Ok(new ServerResponse
                    {
                        HasSucceeded = true,
                        Message = StatusMessages.InvalidMessage,
                        Result = _response
                    }));
                }
            }
            catch (Exception ex)
            {
                EmailValidationResponse _response = new EmailValidationResponse();
                _response.Status  = "api Error";
                _response.IsValid = true;
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));
                return(Ok(new ServerResponse
                {
                    HasSucceeded = true,
                    Message = StatusMessages.ValidMessage,
                    Result = _response
                }));
            }
        }
Example #12
0
 public void NormalizeEmails()
 {
     To = EmailValidationHelper.NormalizeEmailsString(To);
 }