/// <summary> /// Update User /// </summary> /// <param name="accountDataTransformation"></param> /// <returns></returns> public async Task <ResponseModel <AccountDataTransformation> > UpdateUser(AccountDataTransformation accountDataTransformation) { ResponseModel <AccountDataTransformation> returnResponse = new ResponseModel <AccountDataTransformation>(); try { _accountManagementDataService.OpenConnection(_connectionStrings.PrimaryDatabaseConnectionString); _accountManagementDataService.BeginTransaction(); User user = await _accountManagementDataService.GetUserByUserId(accountDataTransformation.UserId); if (user == null) { _accountManagementDataService.RollbackTransaction(); returnResponse.ReturnStatus = false; returnResponse.ReturnMessage.Add("User not found."); return(returnResponse); } await _accountManagementDataService.UpdateUser(user); await _accountManagementDataService.UpdateDatabase(); _accountManagementDataService.CommitTransaction(); returnResponse.ReturnStatus = true; } catch (Exception ex) { _accountManagementDataService.RollbackTransaction(); returnResponse.ReturnStatus = false; returnResponse.ReturnMessage.Add(ex.Message); } finally { _accountManagementDataService.CloseConnection(); } returnResponse.Entity = accountDataTransformation; return(returnResponse); }
public async Task <ResponseModel <AccountDataTransformation> > Register(AccountDataTransformation accountDataTransformation) { ResponseModel <AccountDataTransformation> returnResponse = new ResponseModel <AccountDataTransformation>(); User user = new User(); Account account = new Account(); accountDataTransformation.EmailAddress = accountDataTransformation.EmailAddress.ToLower(); try { _accountManagementDataService.OpenConnection(_connectionStrings.PrimaryDatabaseConnectionString); _accountManagementDataService.BeginTransaction((int)IsolationLevel.Serializable); AccountBusinessRules <AccountDataTransformation> userBusinessRules = new AccountBusinessRules <AccountDataTransformation>(accountDataTransformation, _accountManagementDataService); ValidationResult validationResult = await userBusinessRules.Validate(); if (validationResult.ValidationStatus == false) { _accountManagementDataService.RollbackTransaction(); returnResponse.ReturnMessage = validationResult.ValidationMessages; returnResponse.ReturnStatus = validationResult.ValidationStatus; return(returnResponse); } user.FirstName = accountDataTransformation.FirstName; user.LastName = accountDataTransformation.LastName; user.EmailAddress = accountDataTransformation.EmailAddress; user.UserTypeId = UserTypes.Administrator; account.Name = accountDataTransformation.CompanyName; string salt = Hasher.GetSalt(); string hashedPassword = Hasher.GenerateHash(accountDataTransformation.Password + salt); user.Password = hashedPassword; user.PasswordSalt = salt; await _accountManagementDataService.CreateAccount(account); user.AccountId = account.AccountId; await _accountManagementDataService.CreateUser(user); await _accountManagementDataService.UpdateDatabase(); _accountManagementDataService.CommitTransaction(); returnResponse.ReturnStatus = true; } catch (Exception ex) { _accountManagementDataService.RollbackTransaction(); returnResponse.ReturnStatus = false; returnResponse.ReturnMessage.Add(ex.Message); } finally { _accountManagementDataService.CloseConnection(); } accountDataTransformation.UserId = user.UserId; accountDataTransformation.AccountId = user.AccountId; accountDataTransformation.Password = string.Empty; accountDataTransformation.PasswordConfirmation = string.Empty; returnResponse.Entity = accountDataTransformation; return(returnResponse); }