protected override void Context() { Username = "******"; base.Context(); AccountService.Stub( x => x.DeleteAccount(Arg<string>.Is.Equal(Username), Arg<DeleteAccountRequest>.Is.Anything)) .Return(new DeleteAccountResponse{Success = true,}); _accountReturnedFromQuickSearch = Builder<Account>.CreateNew().Build(); _responseFromQuickSearch = new SearchAccountsResponse { Accounts = new List<Account> { _accountReturnedFromQuickSearch, }, Success = true, }; AccountService.Stub( x => x.QuickSearchAccounts(Arg<string>.Is.Equal(Username), Arg<QuickSearchAccountsRequest>.Is.Anything)) .Return(_responseFromQuickSearch); _expectedViewModel = new AccountManagementViewModel(new List<string> {"User deleted successfully"}); _expectedViewModel.AddAccount(new AccountViewModel { Id = _accountReturnedFromQuickSearch.Id, EmailAddress = _accountReturnedFromQuickSearch.EmailAddress, FirstName = _accountReturnedFromQuickSearch.FirstName, LastName = _accountReturnedFromQuickSearch.LastName, UserName = _accountReturnedFromQuickSearch.Username, Role = _accountReturnedFromQuickSearch.Role.ToString(), }); }
public ActionResult AccountManagement() { try { SearchAccountsResponse response = _accountService.QuickSearchAccounts(User.Identity.Name, new QuickSearchAccountsRequest { SearchString = string.Empty }); if (!response.Success) { var failureViewModel = new AccountManagementViewModel(response.Errors); return View("AccountManagement", failureViewModel); } var successViewModel = new AccountManagementViewModel(); if (TempData["Message"] != null) { successViewModel.AddMessage(TempData["Message"].ToString()); } foreach (Account account in response.Accounts) { if (account.Username != "admin") { successViewModel.AddAccount(new AccountViewModel { FirstName = account.FirstName, LastName = account.LastName, UserName = account.Username, EmailAddress = account.EmailAddress, Role = account.Role.ToString(), Id = account.Id, }); } } return View("AccountManagement", successViewModel); } catch (Exception e) { _logger.LogException(e); return RedirectToAction("Generic", "Error"); } }
private AccountManagementViewModel CreateAccountManagementViewModel() { SearchAccountsResponse response = _accountService.QuickSearchAccounts(User.Identity.Name, new QuickSearchAccountsRequest {SearchString = string.Empty,}); var viewModel = new AccountManagementViewModel(); foreach (Account account in response.Accounts) { viewModel.AddAccount(Mapper.Map<Account, AccountViewModel>(account)); } return viewModel; }
public ActionResult ProcessQuickSearchInput(string searchString) { try { SearchAccountsResponse response = _accountService.QuickSearchAccounts(User.Identity.Name, new QuickSearchAccountsRequest { SearchString = searchString, }); if (!response.Success) { var failureViewModel = new AccountManagementViewModel(response.Errors); return View("AccountManagement", failureViewModel); } var successViewModel = new AccountManagementViewModel(); foreach (Account account in response.Accounts) { if (account.Username != "admin") { successViewModel.AddAccount(Mapper.Map<Account, AccountViewModel>(account)); } } return View("AccountManagement", successViewModel); } catch (Exception e) { _logger.LogException(e); return RedirectToAction("Generic", "Error"); } }