/// <summary> /// Processes the registration information. /// </summary> /// <param name="registrationInfo">The registration information.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">registrationInfo</exception> public IRegistrationView ProcessRegistrationInfo(IRegistrationView registrationInfo) { if (registrationInfo == null) { throw new System.ArgumentNullException(nameof(registrationInfo)); } var processingMessage = string.Empty; var isDataOkay = true; // validate entries // 1) check userId does not exist in RegisterTable var registrationData = this.accountRepository.GetRegistrationByUsername(registrationInfo.Username); var isRecordExist = (registrationData == null) ? false : true; if (isRecordExist) { processingMessage = Messages.UserAlreadyExistText; isDataOkay = false; } // 2) check that email not used if no error so far if (isDataOkay) { registrationData = this.accountRepository.GetRegistrationByEmail(registrationInfo.Email); isRecordExist = (registrationData == null) ? false : true; // checks if registration already exist isDataOkay = isRecordExist ? false : true; // implies registration info already exists and registration can not go through // set processing message if (isRecordExist) { processingMessage = isRecordExist ? Messages.EmailAlreadyUsedText : ""; // email already used for registration if (registrationData.IsRegistered) { processingMessage = (isRecordExist && registrationData.IsRegistered) ? Messages.ConfirmRegistrationText : ""; // email used and registration not confirmed by user } } } // get updated view model to be returned to controller var aboutUsSourceCollection = this.lookupRepository.GetAboutUsSourceCollection().ToList(); var returnViewModel = this.accountViewsModelFactory.CreateUpdatedRegistraionView(registrationInfo, processingMessage, aboutUsSourceCollection); if (!isDataOkay) { returnViewModel.ProcessingMessage = processingMessage; return(returnViewModel); } //save data to database var userId = 0; // encrypt password here registrationInfo.Password = this.encryptionService.Encrypt(registrationInfo.Password); var IsEmployee = this.employeeOnBoardRepository.GetEmployeeByEmail(registrationInfo.Email) == null ? false: true; if (registrationInfo.SelectedRole == "Employee" && IsEmployee == false) { processingMessage = Messages.NoEmployeeRecord; returnViewModel.ProcessingMessage = processingMessage; return(returnViewModel); } if (IsEmployee && registrationInfo.SelectedRole == "Employee") { var employee = this.employeeOnBoardRepository.GetEmployeeByEmail(registrationInfo.Email); registrationInfo.FirstName = employee.FirstName; registrationInfo.LastName = employee.LastName; registrationInfo.PhoneNumber = employee.MobileNumber; registrationInfo.AboutUsOthers = "Bought by my company"; registrationInfo.CompanyId = employee.CompanyId; } var savedData = this.accountRepository.SaveUserInfo(registrationInfo, out userId); //: Create User App Role this.accountRepository.CreateUserRole(registrationInfo); //Generate Activation Code string activationCode = String.Format("{0}{1}", userId, this.usersRepository.CreateActivationCode()); this.accountRepository.StoreActivationCode(userId, activationCode); // generate email details var registrationRequestEmail = emailFactory.CreateRegistrationRequestEmail(registrationInfo, userId, activationCode); var emailKey = this.environment[EnvironmentValues.EmailKey]; // send email to user including token or unique id for registration confirmation this.email.Send(emailKey, "aahrms.automataapps.com", "AA HRMS Team", registrationRequestEmail.Subject, registrationRequestEmail.Recipients, registrationInfo.LastName + " " + registrationInfo.FirstName, string.Empty, registrationRequestEmail.Body); return(returnViewModel); }