public async Task <SyncedEntityIds> SyncEntitiesAsync(SyncEntities model)
        {
            (var conn, var uowTransaction) = _unitOfWork.StartTransaction();

            var accountIds         = new int[model.Accounts.Count];
            var categoryIds        = new int[model.Categories.Count];
            var transactionIds     = new int[model.Transactions.Count];
            var upcomingExpenseIds = new int[model.UpcomingExpenses.Count];
            var debtIds            = new int[model.Debts.Count];

            for (var i = 0; i < accountIds.Length; i++)
            {
                var account = _mapper.Map <Account>(model.Accounts[i]);
                int id      = await _accountsRepository.CreateAsync(account, conn, uowTransaction);

                accountIds[i] = id;
            }

            for (var i = 0; i < categoryIds.Length; i++)
            {
                var category = _mapper.Map <Category>(model.Categories[i]);
                int id       = await _categoriesRepository.CreateAsync(category, conn, uowTransaction);

                categoryIds[i] = id;
            }

            for (var i = 0; i < transactionIds.Length; i++)
            {
                var transaction = _mapper.Map <Transaction>(model.Transactions[i]);
                int id          = await _transactionsRepository.CreateAsync(transaction, conn, uowTransaction);

                transactionIds[i] = id;
            }

            for (var i = 0; i < upcomingExpenseIds.Length; i++)
            {
                var upcomingExpense = _mapper.Map <UpcomingExpense>(model.UpcomingExpenses[i]);
                int id = await _upcomingExpensesRepository.CreateAsync(upcomingExpense, conn, uowTransaction);

                upcomingExpenseIds[i] = id;
            }

            for (var i = 0; i < debtIds.Length; i++)
            {
                var debt = _mapper.Map <Debt>(model.Debts[i]);
                int id   = await _debtsRepository.CreateAsync(debt, conn, uowTransaction);

                debtIds[i] = id;
            }

            _unitOfWork.CommitTransaction(conn, uowTransaction);

            return(new SyncedEntityIds(accountIds, categoryIds, transactionIds, upcomingExpenseIds, debtIds));
        }
Пример #2
0
        public async Task <Unit> Handle(RegisterAccountCommand command, CancellationToken cancellationToken)
        {
            if (await _accountsRepository.IsExistsByEmailAsync(command.Email))
            {
                throw new BadRequestException($"Email - {command.Email} уже есть в системе.");
            }

            if (await _accountsRepository.IsExistsByPhoneAsync(command.PhoneNumber))
            {
                throw new BadRequestException($"Телефон - {command.PhoneNumber} уже есть в системе.");
            }

            await _accountsRepository.CreateAsync(new Account
            {
                Email          = command.Email,
                PhoneNumber    = command.PhoneNumber,
                IsEmailConfirm = false,
                IsPhoneConfirm = false
            });

            _logger.LogInformation("Успешно создан пользователь с Email - {Email} и номером телефона - {PhoneNumber}", command.Email, command.PhoneNumber);

            return(Unit.Value);
        }
Пример #3
0
        public Task <int> CreateAsync(CreateAccount model)
        {
            var account = _mapper.Map <Account>(model);

            return(_accountsRepository.CreateAsync(account));
        }
Пример #4
0
 public async Task CreateAsync(Hero hero)
 {
     hero.Password = _passwordHasher.Hash(hero.Password);
     await _usersRepository.CreateAsync(hero);
 }