public static Account CreateRecruiterModelToAccountModel(this CreateRecruiterModel model) { if (model == null) { return(null); } var account = new Account { AccountType = JobHop.Common.Enums.AccountType.Recruiter, Email = model.Email, Status = UserStatus.Active }; try { //standardize phone number var formatedPhoneNumber = PhoneNumberHelpers.GetFormatedPhoneNumber(model.PhoneNumber); account.PhoneNumber = formatedPhoneNumber; account.UserName = formatedPhoneNumber; } catch (NumberParseException) { throw new CustomException(Errors.INVALID_PHONE_NUMBER, Errors.INVALID_PHONE_NUMBER_MSG); } return(account); }
public async Task <AccountViewModel> CreateRecruiter([FromBody] CreateRecruiterModel bindingModel) { var account = bindingModel.CreateRecruiterModelToAccountModel(); if (account == null || !ModelState.IsValid) { throw new CustomException(Errors.INVALID_REGISTRATION_DATA, Errors.INVALID_REGISTRATION_DATA_MSG); } account.AccountPermissions = new List <Models.AccountPermission>() { new Models.AccountPermission { PermissionId = PermissionsList.RECRUITER_PERMISSION } }; account = await _accountService.CreateAsync(account, bindingModel.Password); try { //publish a recruiter account is created message to rabbit mq bus and wait for response var response = await _rawRabbitBus.RequestAsync <RecruiterAccountCreated, RpcResult>(new RecruiterAccountCreated { Id = account.Id, Email = account.Email, PhoneNumber = account.PhoneNumber, FirstName = bindingModel.FirstName, LastName = bindingModel.LastName, Gender = bindingModel.Gender, Status = account.Status }); if (!response.Success) { // account created but profile creating has an error, should be log and check if (!string.IsNullOrEmpty(response.Error)) { throw new CustomException(response.Error); } } } catch (System.Exception) { //got unhandle exception while creating recruiter profile, should be logs and correct consistency between 2 server throw; } var viewModel = account.ToViewModel(); return(viewModel); }