protected override void OKExecute(object obj) { AccountRelationship accountRelationship = ToAccountRelationship(); m_accountRelationshipService.Create(accountRelationship); m_accountRelationshipId = accountRelationship.AccountRelationshipId; }
public IAccountRelationshipItemViewModel Create(AccountRelationship accountRelationship) { return(new StubAccountRelationshipItemViewModel( new StubAccountLinkViewModelFactory(), accountRelationship )); }
public IAccountRelationshipItemViewModel Create(AccountRelationship accountRelationship) { return(new AccountRelationshipItemViewModel( m_loggerFactory, m_accountLinkViewModelFactory, accountRelationship)); }
public bool AddSecondaryUser(int accountId, string userEmail) { using (var ctx = new ApplicationDbContext()) { if (!OwnsAccount(ctx, accountId)) { return(false); } var secondUser = ctx .Users .SingleOrDefault(u => u.Email == userEmail); if (secondUser == null) { return(false); } var relationship = new AccountRelationship() { AccountId = accountId, UserId = Guid.Parse(secondUser.Id) }; ctx .AccountRelationships .Add(relationship); return(ctx.SaveChanges() == 1); } }
public IAccountRelationshipDetailsViewModel Create(AccountRelationship hint) { return(new AccountRelationshipCreateViewModel( m_loggerFactory, m_accountService, m_accountRelationshipService, hint)); }
internal StubAccountRelationshipItemViewModel( IAccountLinkViewModelFactory accountLinkViewModelFactory, AccountRelationship accountRelationship) { m_accountRelationship = accountRelationship; m_sourceAccount = accountLinkViewModelFactory.Create(m_accountRelationship.SourceAccount); m_destinationAccount = accountLinkViewModelFactory.Create(m_accountRelationship.DestinationAccount); }
public void TestCreateAccountRelationship() { ILoggerFactory loggerFactory = new LoggerFactory(); using (var sqliteMemoryWrapper = new SqliteMemoryWrapper()) { var currencyFactory = new CurrencyFactory(); var usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true); currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity); var accountFactory = new AccountFactory(); Entities.Account incomeAccountEntity = accountFactory.Create(AccountPrefab.Income, usdCurrencyEntity); Entities.Account checkingAccountEntity = accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity); Entities.Account groceriesPrepaymentAccountEntity = accountFactory.Create(AccountPrefab.GroceriesPrepayment, usdCurrencyEntity); Entities.Account rentPrepaymentAccountEntity = accountFactory.Create(AccountPrefab.RentPrepayment, usdCurrencyEntity); accountFactory.Add(sqliteMemoryWrapper.DbContext, incomeAccountEntity); accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity); accountFactory.Add(sqliteMemoryWrapper.DbContext, groceriesPrepaymentAccountEntity); accountFactory.Add(sqliteMemoryWrapper.DbContext, rentPrepaymentAccountEntity); var accountService = new AccountService( loggerFactory, sqliteMemoryWrapper.DbContext ); AccountLink checkingAccountLink = accountService.GetAsLink(checkingAccountEntity.AccountId); AccountLink rentPrepaymentAccountLink = accountService.GetAsLink(rentPrepaymentAccountEntity.AccountId); var accountRelationshipService = new AccountRelationshipService( loggerFactory, sqliteMemoryWrapper.DbContext ); var newRelationship = new AccountRelationship { SourceAccount = checkingAccountLink, DestinationAccount = rentPrepaymentAccountLink, Type = AccountRelationshipType.PhysicalToLogical }; accountRelationshipService.Create(newRelationship); List <Entities.AccountRelationship> accountRelationshipEntities = sqliteMemoryWrapper.DbContext.AccountRelationships.ToList(); Assert.AreEqual(1, accountRelationshipEntities.Count); Assert.AreEqual(AccountRelationshipType.PhysicalToLogical, accountRelationshipEntities[0].Type); Assert.AreEqual(checkingAccountEntity.AccountId, accountRelationshipEntities[0].SourceAccount.AccountId); Assert.AreEqual(checkingAccountEntity.Name, accountRelationshipEntities[0].SourceAccount.Name); Assert.AreEqual(rentPrepaymentAccountEntity.AccountId, accountRelationshipEntities[0].DestinationAccount.AccountId); Assert.AreEqual(rentPrepaymentAccountEntity.Name, accountRelationshipEntities[0].DestinationAccount.Name); } }
public void TestGetAccountRelationship() { ILoggerFactory loggerFactory = new LoggerFactory(); using (var sqliteMemoryWrapper = new SqliteMemoryWrapper()) { var currencyFactory = new CurrencyFactory(); var usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true); currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity); var accountFactory = new AccountFactory(); Entities.Account incomeAccountEntity = accountFactory.Create(AccountPrefab.Income, usdCurrencyEntity); Entities.Account checkingAccountEntity = accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity); Entities.Account groceriesPrepaymentAccountEntity = accountFactory.Create(AccountPrefab.GroceriesPrepayment, usdCurrencyEntity); Entities.Account rentPrepaymentAccountEntity = accountFactory.Create(AccountPrefab.RentPrepayment, usdCurrencyEntity); accountFactory.Add(sqliteMemoryWrapper.DbContext, incomeAccountEntity); accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity); accountFactory.Add(sqliteMemoryWrapper.DbContext, groceriesPrepaymentAccountEntity); accountFactory.Add(sqliteMemoryWrapper.DbContext, rentPrepaymentAccountEntity); var checkingToGroceriesPrepaymentRelationship = new Entities.AccountRelationship { SourceAccount = checkingAccountEntity, DestinationAccount = groceriesPrepaymentAccountEntity, Type = AccountRelationshipType.PhysicalToLogical }; var checkingToRentPrepaymentRelationship = new Entities.AccountRelationship { SourceAccount = checkingAccountEntity, DestinationAccount = rentPrepaymentAccountEntity, Type = AccountRelationshipType.PhysicalToLogical }; sqliteMemoryWrapper.DbContext.AccountRelationships.Add(checkingToGroceriesPrepaymentRelationship); sqliteMemoryWrapper.DbContext.AccountRelationships.Add(checkingToRentPrepaymentRelationship); sqliteMemoryWrapper.DbContext.SaveChanges(); var accountRelationshipService = new AccountRelationshipService(loggerFactory, sqliteMemoryWrapper.DbContext); AccountRelationship accountRelationship = accountRelationshipService.Get( checkingToRentPrepaymentRelationship.AccountRelationshipId); Assert.AreEqual(AccountRelationshipType.PhysicalToLogical, accountRelationship.Type); Assert.AreEqual(checkingAccountEntity.AccountId, accountRelationship.SourceAccount.AccountId); Assert.AreEqual(checkingAccountEntity.Name, accountRelationship.SourceAccount.Name); Assert.AreEqual(rentPrepaymentAccountEntity.AccountId, accountRelationship.DestinationAccount.AccountId); Assert.AreEqual(rentPrepaymentAccountEntity.Name, accountRelationship.DestinationAccount.Name); } }
public AccountRelationshipCreateViewModel( ILoggerFactory loggerFactory, IAccountService accountService, IAccountRelationshipService accountRelationshipService, AccountRelationship hint) : base(accountService, accountRelationshipService, 0) { m_logger = loggerFactory.CreateLogger <AccountRelationshipCreateViewModel>(); SourceAccount = Accounts.Single(a => a.AccountId == hint.SourceAccount.AccountId); DestinationAccount = Accounts.Single(a => a.AccountId == hint.DestinationAccount.AccountId); SelectedType = hint.Type; }
public IActionResult UpsertFollowUser([FromBody] FollowRequest followRequest) { try { AccountRelationship data = _aquariumService.UpsertFollowUser(followRequest.AccountId, followRequest.TargetId); return(new OkObjectResult(data)); } catch (Exception ex) { _logger.LogError($"GET /v1/Profile/Follow endpoint caught exception: { ex.Message } Details: { ex.ToString() }"); return(NotFound()); } }
public AccountRelationshipItemViewModel( ILoggerFactory loggerFactory, IAccountLinkViewModelFactory accountlinkViewModelFactory, AccountRelationship accountRelationship) { m_logger = loggerFactory.CreateLogger <AccountRelationshipItemViewModel>(); m_accountLinkViewModelFactory = accountlinkViewModelFactory; AccountRelationshipId = accountRelationship.AccountRelationshipId; SourceAccount = m_accountLinkViewModelFactory.Create(accountRelationship.SourceAccount); DestinationAccount = m_accountLinkViewModelFactory.Create(accountRelationship.DestinationAccount); Type = accountRelationship.Type; }
public void TestCreateAccountRelationshipsInDbContext() { using (var sqliteMemoryWrapper = new SqliteMemoryWrapper()) { var currencyFactory = new CurrencyFactory(); Entities.Currency usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true); currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity); var accountFactory = new AccountFactory(); Entities.Account checkingAccountEntity = accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity); Entities.Account rentPrepaymentAccountEntity = accountFactory.Create(AccountPrefab.RentPrepayment, usdCurrencyEntity); Entities.Account rentExpenseAccountEntity = accountFactory.Create(AccountPrefab.RentExpense, usdCurrencyEntity); accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity); accountFactory.Add(sqliteMemoryWrapper.DbContext, rentPrepaymentAccountEntity); accountFactory.Add(sqliteMemoryWrapper.DbContext, rentExpenseAccountEntity); var checkingToRentPrepaymentRelationship = new AccountRelationship { SourceAccount = checkingAccountEntity, DestinationAccount = rentPrepaymentAccountEntity, Type = AccountRelationshipType.PhysicalToLogical }; var rentPrepaymentToExpenseRelationship = new AccountRelationship { SourceAccount = rentPrepaymentAccountEntity, DestinationAccount = rentExpenseAccountEntity, Type = AccountRelationshipType.PrepaymentToExpense }; sqliteMemoryWrapper.DbContext.AccountRelationships.Add(checkingToRentPrepaymentRelationship); sqliteMemoryWrapper.DbContext.AccountRelationships.Add(rentPrepaymentToExpenseRelationship); sqliteMemoryWrapper.DbContext.SaveChanges(); List <Account> accounts = sqliteMemoryWrapper.DbContext.Accounts.ToList(); List <AccountRelationship> accountRelationsips = sqliteMemoryWrapper.DbContext.AccountRelationships.ToList(); List <Currency> currencies = sqliteMemoryWrapper.DbContext.Currencies.ToList(); List <Transaction> transactions = sqliteMemoryWrapper.DbContext.Transactions.ToList(); Assert.AreEqual(3, accounts.Count); Assert.AreEqual(2, accountRelationsips.Count); Assert.AreEqual(1, currencies.Count); Assert.AreEqual(0, transactions.Count); Assert.AreEqual(checkingToRentPrepaymentRelationship.SourceAccount.Name, accountRelationsips[0].SourceAccount.Name); Assert.AreEqual(checkingToRentPrepaymentRelationship.DestinationAccount.Name, accountRelationsips[0].DestinationAccount.Name); Assert.AreEqual(rentPrepaymentToExpenseRelationship.SourceAccount.Name, accountRelationsips[1].SourceAccount.Name); Assert.AreEqual(rentPrepaymentToExpenseRelationship.DestinationAccount.Name, accountRelationsips[1].DestinationAccount.Name); } }
public AccountRelationshipEditViewModel( ILoggerFactory loggerFactory, IAccountService accountService, IAccountRelationshipService accountRelationshipService, int accountRelationshipId) : base(accountService, accountRelationshipService, accountRelationshipId) { m_logger = loggerFactory.CreateLogger <AccountRelationshipEditViewModel>(); AccountRelationship accountRelationship = m_accountRelationshipService.Get(accountRelationshipId); SourceAccount = Accounts.Single(a => a.AccountId == accountRelationship.SourceAccount.AccountId); DestinationAccount = Accounts.Single(a => a.AccountId == accountRelationship.DestinationAccount.AccountId); SelectedType = accountRelationship.Type; }
public void TestAccountRelationshipCreateViewModelOK() { ILoggerFactory loggerFactory = new LoggerFactory(); using (var sqliteMemoryWrapper = new SqliteMemoryWrapper()) { var currencyFactory = new CurrencyFactory(); var usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true); currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity); var accountFactory = new AccountFactory(); Entities.Account checkingAccountEntity = accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity); Entities.Account rentPrepaymentAccountEntity = accountFactory.Create(AccountPrefab.RentPrepayment, usdCurrencyEntity); accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity); accountFactory.Add(sqliteMemoryWrapper.DbContext, rentPrepaymentAccountEntity); var accountService = new AccountService( loggerFactory, sqliteMemoryWrapper.DbContext); var accountRelationshipService = new AccountRelationshipService( loggerFactory, sqliteMemoryWrapper.DbContext); var hint = new AccountRelationship { SourceAccount = accountService.GetAsLink(checkingAccountEntity.AccountId), DestinationAccount = accountService.GetAsLink(rentPrepaymentAccountEntity.AccountId), Type = AccountRelationshipType.PrepaymentToExpense }; var viewModel = new AccountRelationshipCreateViewModel( loggerFactory, accountService, accountRelationshipService, hint ); viewModel.SelectedType = AccountRelationshipType.PhysicalToLogical; viewModel.OKCommand.Execute(this); List <AccountRelationship> accountRelationships = accountRelationshipService.GetAll().ToList(); Assert.AreEqual(1, accountRelationships.Count); Assert.AreEqual(checkingAccountEntity.AccountId, accountRelationships[0].SourceAccount.AccountId); Assert.AreEqual(rentPrepaymentAccountEntity.AccountId, accountRelationships[0].DestinationAccount.AccountId); Assert.AreEqual(viewModel.SelectedType, accountRelationships[0].Type); } }
public bool Show(int accountRelationshipId, out AccountRelationship updatedAccountRelationship) { updatedAccountRelationship = null; IAccountRelationshipDetailsViewModel viewModel = m_accountRelationshipDetailsViewModelFactory.Create(accountRelationshipId); var window = new AccountRelationshipDetailsWindow(viewModel); bool?result = window.ShowDialog(); if (result.HasValue) { updatedAccountRelationship = viewModel.ToAccountRelationship(); return(result.Value); } return(false); }
private void CreateExecute(object obj) { AccountRelationship hint = null; IAccountRelationshipItemViewModel hintViewModel = AccountRelationships.FirstOrDefault(); if (AccountRelationships.Any()) { hint = m_accountRelationshipService.Get(AccountRelationships.First().AccountRelationshipId); } AccountRelationship newRelationship; if (m_accountRelationshipCreateViewService.Show(hint, out newRelationship)) { IAccountRelationshipItemViewModel viewModel = m_accountRelationshipItemViewModelFactory.Create(newRelationship); AccountRelationships.Add(viewModel); } }
public bool CreateAccount(AccountCreate model) { var account = new Account() { AccountBalance = model.AccountBalance, AccountType = model.AccountType }; if (model.AccountBalance < 0) { return(false); } using (var ctx = new ApplicationDbContext()) { ctx .Accounts .Add(account); if (ctx.SaveChanges() != 1) { return(false); } var relationship = new AccountRelationship() { AccountId = account.AccountId, UserId = _userId }; ctx .AccountRelationships .Add(relationship); return(ctx.SaveChanges() == 1); } }
public void TestCreateBudgetInDbContext() { using (var sqliteMemoryWrapper = new SqliteMemoryWrapper()) { var currencyFactory = new CurrencyFactory(); Entities.Currency usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true); currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity); var accountFactory = new AccountFactory(); Entities.Account incomeAccountEntity = accountFactory.Create(AccountPrefab.Income, usdCurrencyEntity); Entities.Account checkingAccountEntity = accountFactory.Create(AccountPrefab.Checking, usdCurrencyEntity); Entities.Account savingsAccountEntity = accountFactory.Create(AccountPrefab.Savings, usdCurrencyEntity); Entities.Account rentPrepaymentAccountEntity = accountFactory.Create(AccountPrefab.RentPrepayment, usdCurrencyEntity); Entities.Account rentExpenseAccountEntity = accountFactory.Create(AccountPrefab.RentExpense, usdCurrencyEntity); Entities.Account groceriesPrepaymentAccountEntity = accountFactory.Create(AccountPrefab.GroceriesPrepayment, usdCurrencyEntity); Entities.Account groceriesExpenseAccountEntity = accountFactory.Create(AccountPrefab.GroceriesExpense, usdCurrencyEntity); accountFactory.Add(sqliteMemoryWrapper.DbContext, incomeAccountEntity); accountFactory.Add(sqliteMemoryWrapper.DbContext, checkingAccountEntity); accountFactory.Add(sqliteMemoryWrapper.DbContext, savingsAccountEntity); accountFactory.Add(sqliteMemoryWrapper.DbContext, rentPrepaymentAccountEntity); accountFactory.Add(sqliteMemoryWrapper.DbContext, rentExpenseAccountEntity); accountFactory.Add(sqliteMemoryWrapper.DbContext, groceriesPrepaymentAccountEntity); accountFactory.Add(sqliteMemoryWrapper.DbContext, groceriesExpenseAccountEntity); var checkingToRentPrepaymentRelationship = new AccountRelationship { SourceAccount = checkingAccountEntity, DestinationAccount = rentPrepaymentAccountEntity, Type = AccountRelationshipType.PhysicalToLogical }; var checkingToGroceriesPrepaymentRelationship = new AccountRelationship { SourceAccount = checkingAccountEntity, DestinationAccount = groceriesPrepaymentAccountEntity, Type = AccountRelationshipType.PhysicalToLogical }; var rentPrepaymentToExpenseRelationship = new AccountRelationship { SourceAccount = rentPrepaymentAccountEntity, DestinationAccount = rentExpenseAccountEntity, Type = AccountRelationshipType.PrepaymentToExpense }; var groceriesPrepaymentToExpenseRelationship = new AccountRelationship { SourceAccount = groceriesPrepaymentAccountEntity, DestinationAccount = groceriesExpenseAccountEntity, Type = AccountRelationshipType.PrepaymentToExpense }; sqliteMemoryWrapper.DbContext.AccountRelationships.Add(checkingToRentPrepaymentRelationship); sqliteMemoryWrapper.DbContext.AccountRelationships.Add(checkingToGroceriesPrepaymentRelationship); sqliteMemoryWrapper.DbContext.AccountRelationships.Add(rentPrepaymentToExpenseRelationship); sqliteMemoryWrapper.DbContext.AccountRelationships.Add(groceriesPrepaymentToExpenseRelationship); sqliteMemoryWrapper.DbContext.SaveChanges(); var budget = new Budget { Name = "Budget", Period = BudgetPeriod.Fortnightly }; sqliteMemoryWrapper.DbContext.Budgets.Add(budget); sqliteMemoryWrapper.DbContext.SaveChanges(); var initialTransaction = new BudgetTransaction { CreditAccount = incomeAccountEntity, DebitAccount = checkingAccountEntity, Amount = 200m, IsInitial = true, Budget = budget }; var rentTransaction = new BudgetTransaction { CreditAccount = checkingAccountEntity, DebitAccount = rentPrepaymentAccountEntity, Amount = 100m, Budget = budget }; var groceriesTransaction = new BudgetTransaction { CreditAccount = checkingAccountEntity, DebitAccount = groceriesPrepaymentAccountEntity, Amount = 50m, Budget = budget }; var surplusTransaction = new BudgetTransaction { CreditAccount = checkingAccountEntity, DebitAccount = groceriesPrepaymentAccountEntity, IsSurplus = true, Budget = budget }; sqliteMemoryWrapper.DbContext.BudgetTransactions.Add(initialTransaction); sqliteMemoryWrapper.DbContext.BudgetTransactions.Add(rentTransaction); sqliteMemoryWrapper.DbContext.BudgetTransactions.Add(groceriesTransaction); sqliteMemoryWrapper.DbContext.BudgetTransactions.Add(surplusTransaction); sqliteMemoryWrapper.DbContext.SaveChanges(); List <Account> accounts = sqliteMemoryWrapper.DbContext.Accounts.ToList(); List <AccountRelationship> accountRelationsips = sqliteMemoryWrapper.DbContext.AccountRelationships.ToList(); List <Budget> budgets = sqliteMemoryWrapper.DbContext.Budgets.ToList(); List <BudgetTransaction> budgetTransactions = sqliteMemoryWrapper.DbContext.BudgetTransactions.ToList(); List <Currency> currencies = sqliteMemoryWrapper.DbContext.Currencies.ToList(); List <Transaction> transactions = sqliteMemoryWrapper.DbContext.Transactions.ToList(); Assert.AreEqual(7, accounts.Count); Assert.AreEqual(4, accountRelationsips.Count); Assert.AreEqual(1, budgets.Count); Assert.AreEqual(4, budgetTransactions.Count); Assert.AreEqual(1, currencies.Count); Assert.AreEqual(0, transactions.Count); Assert.AreEqual(budget.Name, budgets[0].Name); Assert.AreEqual(budget.Period, budgets[0].Period); Assert.AreEqual(budgetTransactions.Count, budgets[0].Transactions.Count); } }