public HttpResponseMessage RegisterUser(TakamulUser oTakamulUser, int nLanguageID) { ApiResponse oApiResponse = new ApiResponse(); string sResultMessage = string.Empty; if (ModelState.IsValid) { try { int nOTPNumber = CommonHelper.nGenerateRandomInteger(1000, 9999); UserInfoViewModel oUserInfoViewModel = new UserInfoViewModel() { APPLICATION_ID = oTakamulUser.ApplicationID, USER_TYPE_ID = 4, //Mobile user type FULL_NAME = oTakamulUser.FullName, PHONE_NUMBER = oTakamulUser.PhoneNumber, EMAIL = oTakamulUser.Email, ADDRESS = oTakamulUser.Addresss, AREA_ID = oTakamulUser.AreaID, WILAYAT_ID = oTakamulUser.WilayatID, VILLAGE_ID = oTakamulUser.VillageID, OTP_NUMBER = nOTPNumber, DEVICE_ID = oTakamulUser.DeviceID, PREFERED_LANGUAGE_ID = nLanguageID }; Response oResponse = this.oIAuthenticationService.oInsertMobileUser(oUserInfoViewModel); if (oResponse.OperationResult == enumOperationResult.Success) { oApiResponse.OperationResult = 1; sResultMessage = nLanguageID == 2 ? "User registered successfully." : "تم تسجيل المستخدم بنجاح."; oApiResponse.OperationResultMessage = sResultMessage; oApiResponse.ResponseID = Convert.ToInt32(oResponse.ResponseID); oApiResponse.ResponseCode = nOTPNumber.ToString(); Languages enmUserLanuage = (Languages)Enum.Parse(typeof(Languages), nLanguageID.ToString()); //Send OTP via SMS and update in DB SMSNotification oSMSNotification = new SMSNotification(); SMSViewModel oSMSViewModel = new SMSViewModel(); //oSMSViewModel.Language = enmUserLanuage == Languages.English ? 0 : 64; oSMSViewModel.Language = 64; string sMessage = string.Empty; if (enmUserLanuage == Languages.English) { sMessage = string.Format("Thank you for registering with {0}, Your activation code is : {1}.", oResponse.ResponseCode, oUserInfoViewModel.OTP_NUMBER); } else { string sMessagePart1 = "نشكرك على تسجيلك في تطبيق "; sMessagePart1 = sMessagePart1 + oResponse.ResponseCode + ", "; string sMessagePart2 = "رمز التفعيل الخاص بك هو : "; sMessagePart2 = sMessagePart2 + oUserInfoViewModel.OTP_NUMBER; sMessage = sMessagePart1 + sMessagePart2; } oSMSViewModel.Message = sMessage; oSMSViewModel.Recipient = oUserInfoViewModel.PHONE_NUMBER; oSMSViewModel.RecipientType = 1; bool bSentSMS = oSMSNotification.bSendOTPSMS(oSMSViewModel); Response oResponseOTPStatus = this.oIAuthenticationService.oUpdateOTPStatus(oApiResponse.ResponseID, bSentSMS); } else if (oResponse.OperationResult == enumOperationResult.AlreadyExistRecordFaild) { oApiResponse.OperationResult = -3; sResultMessage = nLanguageID == 2 ? "The user already exists.Please contact app administrator." : "المستخدم مسجل من قبل. الرجاء الاتصال بمشرف التطبيق."; oApiResponse.OperationResultMessage = sResultMessage; } else { oApiResponse.OperationResult = 0; sResultMessage = nLanguageID == 2 ? "Error Occured.Please contact app administrator." : "حدث خطأ الرجاء الاتصال بمشرف التطبيق."; oApiResponse.OperationResultMessage = sResultMessage; } return(Request.CreateResponse(HttpStatusCode.OK, oApiResponse)); } catch (Exception ex) { oApiResponse.OperationResult = 0; sResultMessage = nLanguageID == 2 ? "An error occurred during the operation. Please try again later." : "حدث خطأ يرجى المحاولة لاحقا مرة أخرى"; oApiResponse.OperationResultMessage = sResultMessage; return(Request.CreateResponse(HttpStatusCode.InternalServerError, oApiResponse)); Elmah.ErrorLog.GetDefault(HttpContext.Current).Log(new Elmah.Error(ex)); } } oApiResponse.OperationResult = 0; sResultMessage = nLanguageID == 2 ? "Validation failed." : "خطاء في التحقق."; oApiResponse.OperationResultMessage = sResultMessage; return(Request.CreateResponse(HttpStatusCode.BadRequest, oApiResponse)); }
public HttpResponseMessage ResendOTPNumber(int nApplicationID, string sPhoneNumber, int nLanguageID) { ApiResponse oApiResponse = new ApiResponse(); string sResultMessage = string.Empty; try { int nOTPNumber = CommonHelper.nGenerateRandomInteger(1000, 9999); Response oResponse = this.oIAuthenticationService.oResendOTPNumber(nApplicationID, sPhoneNumber, nOTPNumber); if (oResponse.OperationResult == enumOperationResult.Success) { oApiResponse.OperationResult = 1; sResultMessage = nLanguageID == 2 ? "OTP has been successfully sent." : "تم إرسال رمز التفعيل بنجاح ."; oApiResponse.OperationResultMessage = sResultMessage; //TODO::integrate with sms service and update status to database oApiResponse.ResponseCode = nOTPNumber.ToString(); Languages enmUserLanuage = (Languages)Enum.Parse(typeof(Languages), nLanguageID.ToString()); //Send OTP via SMS and update in DB SMSNotification oSMSNotification = new SMSNotification(); SMSViewModel oSMSViewModel = new SMSViewModel(); //oSMSViewModel.Language = enmUserLanuage == Languages.English ? 0 : 64; oSMSViewModel.Language = 64; string sMessage = string.Empty; if (enmUserLanuage == Languages.English) { sMessage = string.Format("Thank you for registering with {0}, Your activation code is : {1}.", oResponse.ResponseCode, nOTPNumber); } else { string sMessagePart1 = "نشكرك على تسجيلك في تطبيق "; sMessagePart1 = sMessagePart1 + oResponse.ResponseCode + ", "; string sMessagePart2 = "رمز التفعيل الخاص بك هو : "; sMessagePart2 = sMessagePart2 + nOTPNumber; sMessage = sMessagePart1 + sMessagePart2; } oSMSViewModel.Message = sMessage; oSMSViewModel.Recipient = sPhoneNumber; oSMSViewModel.RecipientType = 1; bool bSentSMS = oSMSNotification.bSendOTPSMS(oSMSViewModel); Response oResponseOTPStatus = this.oIAuthenticationService.oUpdateOTPStatus(oApiResponse.ResponseID, bSentSMS); } else if (oResponse.OperationResult == enumOperationResult.RelatedRecordFaild) { oApiResponse.OperationResult = -2; sResultMessage = nLanguageID == 2 ? "You have exceeded the maximum number of attempt.Please contact app administrator." : "لقد تجاوزت الحد الأقصى لعدد المحاولات. يرجى الاتصال بمشرف التطبيق ."; oApiResponse.OperationResultMessage = sResultMessage; } else if (oResponse.OperationResult == enumOperationResult.AlreadyExistRecordFaild) { oApiResponse.OperationResult = -3; sResultMessage = nLanguageID == 2 ? "The user does not exist.Please contact app administrator" : "المستخدم غير مسجل . يرجى الاتصال بمشرف التطبيق"; oApiResponse.OperationResultMessage = sResultMessage; } else { oApiResponse.OperationResult = 0; sResultMessage = nLanguageID == 2 ? "An error Occured.Please contact app administrator." : "حدث خطأ الرجاء الاتصال بمشرف التطبيق."; oApiResponse.OperationResultMessage = sResultMessage; } return(Request.CreateResponse(HttpStatusCode.OK, oApiResponse)); } catch (Exception ex) { oApiResponse.OperationResult = 0; sResultMessage = nLanguageID == 2 ? "An error occurred during the operation. Please try again later." : "حدث خطأ يرجى المحاولة لاحقا مرة أخرى"; oApiResponse.OperationResultMessage = sResultMessage; return(Request.CreateResponse(HttpStatusCode.InternalServerError, oApiResponse)); Elmah.ErrorLog.GetDefault(HttpContext.Current).Log(new Elmah.Error(ex)); } }