public LoginResponseModel ResendOTP(LoginRequestModel requestModel) { IAuthentication _repository = new DataAccess.Authentication.Authentication(); LoginResponseModel objResponse = new LoginResponseModel(); int Result = _repository.CheckPhoneNoExists(requestModel.UserName); if (Result > 0) { objResponse = _repository.GetRegisterOTPCountForUser(requestModel.UserName); DateTime Currentdate = DateTime.Now; DateTime OTPsentdate = Convert.ToDateTime(objResponse.RegisterOTPSentDate); int reslt = 0; if (objResponse.RegisterOTPSentDate == DateTime.MinValue) { string OTP = GenerateNewOTP(); objResponse.OTP = OTP; objResponse.Status = 1; objResponse.Message = "You have Another 2 chance to send OTP"; SMSService.SendSms(requestModel.UserName, (objResponse.OTP), objResponse.OTP); _repository.UpdateRegisterOTPCountForUser(requestModel.UserName, true); } else { reslt = DateTime.Compare(Currentdate.Date, OTPsentdate.Date); if (reslt != 0) { string OTP = GenerateNewOTP(); objResponse.OTP = OTP; objResponse.Status = 1; objResponse.RegisterOTPSentCount = 1; objResponse.Message = "You have Another 2 chance to send OTP"; SMSService.SendSms(requestModel.UserName, (objResponse.OTP), objResponse.OTP); _repository.UpdateRegisterOTPCountForUser(requestModel.UserName, true); } else if (reslt == 0 && objResponse.RegisterOTPSentCount < 3) { string OTP = GenerateNewOTP(); objResponse.OTP = OTP; objResponse.Status = 1; objResponse.RegisterOTPSentCount = objResponse.RegisterOTPSentCount + 1; int balance = 3 - Convert.ToInt32(objResponse.RegisterOTPSentCount); objResponse.Message = "You have another " + balance + " chance to send OTP"; SMSService.SendSms(requestModel.UserName, (objResponse.OTP), objResponse.OTP); _repository.UpdateRegisterOTPCountForUser(requestModel.UserName, false); } else if (reslt == 0 && objResponse.RegisterOTPSentCount >= 3) { objResponse.Status = 2; objResponse.RegisterOTPSentCount = 3; objResponse.Message = "You have Exceeded the limit of resending OTP"; } } } else { objResponse.Status = 0; } return(objResponse); }
public objRegisterResponseModel RegisterUser(objRegisterRequestModel requestModel) { IAuthentication _repository = new DataAccess.Authentication.Authentication(); objRegisterResponseModel objResponse = new objRegisterResponseModel(); int Id = _repository.AddUser(requestModel.objUser); if (Id > 0) { UserModel user = new UserModel(); user.Id = Id; string OTP = GenerateNewOTP(); user.OTP = OTP; user.PhoneNo = requestModel.objUser.PhoneNo; user.FullName = requestModel.objUser.FullName; user.EmailId = requestModel.objUser.EmailId; objResponse.user = user; SMSService.SendSms(requestModel.objUser.PhoneNo, ("Login OTP " + user.OTP), user.OTP); AppResponseView response = new AppResponseView(); response.Message = "User Registered Successfully"; response.Status = 1; objResponse.Response = response; _repository.UpdateRegisterOTPCountForUser(requestModel.objUser.PhoneNo, true); } else { AppResponseView response = new AppResponseView(); response.Message = "User already Registered"; response.Status = 0; objResponse.Response = response; } return(objResponse); }