protected override void Context() { base.Context(); _deleteAccountRequest = new DeleteAccountRequest { AccountId = 8, }; AuthorizationService.Stub( x => x.CanExecute(Arg<string>.Is.Equal(Username), Arg<Type>.Is.Equal(typeof(DeleteAccountRequest)))). Return(true); AccountRepository.Stub( x => x.Delete(Arg<DeleteAccountRequest>.Is.Equal(_deleteAccountRequest))) .WhenCalled(x => _deleteAccountRequestPassedToRepository = x.Arguments[0] as DeleteAccountRequest); _expectedDeleteAccountResponse = new DeleteAccountResponse { Success = true, }; _expectedDeleteAccountRequest = new DeleteAccountRequest { AccountId = 8, }; }
//todo: need to either use PRG pattern or ajax so don't try to delete multiple times public void Delete(DeleteAccountRequest deleteAccountRequest) { using (var context = new PRToolsEntities()) { Account accountEntity = context.Accounts.SingleOrDefault(x => x.AccountId == deleteAccountRequest.AccountId); if (accountEntity != null) { context.Accounts.DeleteObject(accountEntity); context.SaveChanges(); } } }
public DeleteAccountResponse DeleteAccount(string username, DeleteAccountRequest deleteAccountRequest) { if (!_authorizationService.CanExecute(username, "DeleteAccounts")) return new DeleteAccountResponse { Success = false, Errors = new List<string> { "User is not authorized to Delete Accounts.", }, }; _accountRepository.Delete(deleteAccountRequest); return new DeleteAccountResponse { Success = true, }; }