Exemple #1
0
 public async Task HandleAsync(CreateBankAccount command)
 {
     await _bankAccountService.CreateNewBankAccountAsync(command.userId, command.BankAccountName, command.InitialBalance, command.Currency, command.HexColor);
 }
        public async Task SeedAsync()
        {
            _logger.Trace("Initialiazing data...");

            _logger.Debug("Creating users");
            await RegisterUsersAsync();
            await RegisterAdminsAsync();

            _logger.Debug("Getting users");

            var users = await _userRepository.GetAllUsersAsync();

            var usr = await _userRepository.GetAsync(16);

            var usr2 = await _userRepository.GetAsync(16);

            _logger.Debug("Creating bank accounts and Categories");


            foreach (var user in users)
            {
                try
                {
                    await _bankAccountService.CreateNewBankAccountAsync(user.UserId, $"Bank", 100m, "PLN", "#FFF");

                    await _bankAccountService.CreateNewBankAccountAsync(user.UserId, $"Cash", 10m, "PLN", "#FFF");

                    await _categoryService.AddCategoryAsync("category1", user.UserId, "test-icon", "#FFF");

                    await _categoryService.AddCategoryAsync("category2", user.UserId, "test-icon", "#FFF");
                }
                catch (Exception ex)
                {
                    _logger.Error(ex.Message);
                    _logger.Error(ex.StackTrace);
                }
            }

            _logger.Debug("Creating transactions");
            try
            {
                foreach (var user in users)
                {
                    foreach (var bank in user.BankAccounts)
                    {
                        foreach (var category in user.Categories)
                        {
                            await _transactionService.AddTransactionAsync($"transaction of user: {user.Username}", category.CategoryId, -30.23m, DateTime.UtcNow, bank.BanAccountId, user.UserId);

                            await _transactionService.AddTransactionAsync($"transaction of user: {user.Username}", category.CategoryId, -0.99m, DateTime.UtcNow, bank.BanAccountId, user.UserId);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message + ex.StackTrace);
                throw;
            }


            _logger.Debug("Test Debuggera");
            _logger.Trace("Data was initilized");
        }
        public async Task <IActionResult> CreateBankAccount([FromBody] BankAccountRequestDTO requestDTO)
        {
            var result = await _bankAccountService.CreateNewBankAccountAsync(requestDTO);

            return(new OkObjectResult(new { Id = result }));
        }