public async Task ResendVerifyCode([FromBody] SendVerificationCodeToPhoneNumberModel model) { var verification = await _verificationService.GetVerificationCodeFromPhoneNumberAsync(model.PhoneNumber, VerificationPurpose.RegistrationPhoneNumber); if (verification == null) { throw new CustomException(Errors.VERIFICATION_NOT_FOUND, Errors.VERIFICATION_NOT_FOUND_MSG); } // expired the verification if retried counter or resent counter exceeded limit // do not use >= for Resend because of we need increase Resend counter and expired immediatelly the verification else if (verification.Retry >= VerificationService.MAX_RETRY || verification.Resend > VerificationService.MAX_RESEND) { throw new CustomException(Errors.VERIFICATION_LOCKED, Errors.VERIFICATION_LOCKED_MSG); } else { if (verification.Resend == VerificationService.MAX_RESEND) { await _verificationService.IncreaseResendCounter(verification.Id); throw new CustomException(Errors.VERIFICATION_LOCKED, Errors.VERIFICATION_LOCKED_MSG); } else { string smsContent = $"Verification code at JobHop: {verification.VerifyCode}"; var formatedPhoneNumber = PhoneNumberHelpers.GetFormatedPhoneNumber(model.PhoneNumber); //send SMS using eSMS.vn var response = await _esmsService.SendSMS(formatedPhoneNumber, smsContent, 4); if (response.IsSuccessStatusCode) { await _verificationService.IncreaseResendCounter(verification.Id); } else { throw new CustomException(response.StatusCode.ToString()); } } } }