private static TimeWarpUserState UpdateValuesInDatabase(Account account) { var repository = new TimeWarpUserStateRepository(); TimeWarpUserState timeWarpUserState = repository.GetLatestStateByAccountId(account.Id); return(timeWarpUserState); }
public AccountCreationResponse CreateAccount(QuickCreationInfo quickAccountCreationInfo) { if (!_validator.IsDisplayNameValid(quickAccountCreationInfo.DisplayName)) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest) { ReasonPhrase = "display name is invalid" }); } var randomString = Guid.NewGuid().ToString(); string fakeEmail = string.Empty; string fakePassword = randomString; var account = new Account(0, quickAccountCreationInfo.DisplayName, fakeEmail, AccountType.Quick); var defaultState = TimeWarpUserState.DefaultState(account); var accountPassword = new AccountPassword(account, fakePassword); //save _accountRepository.Add(account); _passwordRepository.Add(accountPassword); _userStateRepository.Add(defaultState); string token = _authenticationManager.AddUser(accountPassword); if (Log.IsDebugEnabled) { Log.DebugFormat("account created for {0}", randomString); } return(new AccountCreationResponse(account.Id, token)); }
public void SaveState(TimeWarpUserState newState) { //this should probably be on a new thread...and exception handling. logging ..etc using (var session = new NHibernateSessionPerRequest <TimeWarpUserStateClassMap>()) { var repository = new TimeWarpUserStateRepository(session.GetCurrentSession()); repository.Add(newState); } }
private static void CreateInitialValuesInDatabase(Account account, TimeWarpUserState state1, TimeWarpUserState state2) { var accountRepository = new AccountRepository(); accountRepository.Add(account); var repository = new TimeWarpUserStateRepository(); repository.Add(state1); repository.Add(state2); }
public AccountCreationResponse CreateAccount(FullAccountCreationInfo fullAccountCreationInfo) { if (!_validator.IsEmailValid(fullAccountCreationInfo.EmailAddress)) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest) { ReasonPhrase = "email address is invalid" }); } if (!_validator.IsDuplicateEmailAddress(fullAccountCreationInfo.EmailAddress)) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest) { ReasonPhrase = "email address is duplicate" }); } if (!_validator.IsDisplayNameValid(fullAccountCreationInfo.DisplayName)) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest) { ReasonPhrase = "display name is invalid" }); } //does email address exist? var account = new Account(0, fullAccountCreationInfo.DisplayName, fullAccountCreationInfo.EmailAddress, AccountType.Full); var defaultState = TimeWarpUserState.DefaultState(account); var accountPassword = new AccountPassword(account, fullAccountCreationInfo.Password); //save _accountRepository.Add(account); _passwordRepository.Add(accountPassword); _userStateRepository.Add(defaultState); string token = _authenticationManager.AddUser(accountPassword); if (Log.IsDebugEnabled) { Log.DebugFormat("account created for {0}", fullAccountCreationInfo.EmailAddress); } return(new AccountCreationResponse(account.Id, token)); }
public void CanUpdateState() { var account = TestHelper.AccountMock(); var state1 = new TimeWarpUserState(account, TimeWarpState.Working, new DateTime(2000, 12, 12, 12, 12, 12), new TimeSpan(1, 30, 2), 3.0, 4); var state2 = new TimeWarpUserState(account, TimeWarpState.Resting, new DateTime(2001, 12, 12, 12, 12, 12), new TimeSpan(1, 30, 2), 3.0, 3); CreateInitialValuesInDatabase(account, state1, state2); var timeWarpUserState = UpdateValuesInDatabase(account); Assert.IsNotNull(timeWarpUserState); Assert.AreEqual(account.Id, timeWarpUserState.Account.Id); Assert.AreEqual(account.Name, timeWarpUserState.Account.Name); Assert.AreEqual(TimeWarpState.Resting, timeWarpUserState.State); Assert.AreEqual(3, timeWarpUserState.AgentType); }
public static UserStateInfoResponse ConvertToPublicV001(this TimeWarpUserState timeWarpUser, DateTime queryTime) { return(new UserStateInfoResponse(timeWarpUser.Account.Id, timeWarpUser.Account.Name, queryTime, timeWarpUser.State.ConvertToPublicV001(), timeWarpUser.PeriodStartTime, timeWarpUser.TimeLeft, timeWarpUser.Progress, timeWarpUser.Account.AccountType == AccountType.Quick, (TimeWarpAgent)timeWarpUser.AgentType)); }
public void SaveState(TimeWarpUserState timeWarpUserState) { //do nothing. }