public async Task AddTransactionAsync(AddTransaction command)
        {
            var user = await userRepository.GetFirstUserAsync();

            if (command.Type == ExtendedTransactionType.Transfer)
            {
                if (command.Amount > 0)
                {
                    command.Amount *= (-1);
                }
                if (command.TransferAmount < 0)
                {
                    command.TransferAmount *= (-1);
                }
                var transactionExpense = Transaction.Create(command.AccountId, TransactionType.Expense, command.Amount, command.Date, command.Name, command.Comment, user.Id, false, command.CategoryId, command.ExternalId.ToString(), command.Latitude, command.Longitude);
                await transactionRepository.AddTransactionAsync(transactionExpense);

                var transactionIncome = Transaction.Create(command.TransferAccountId.Value, TransactionType.Income, command.TransferAmount, command.TransferDate, command.Name, command.Comment, user.Id, false, command.CategoryId, command.TransferExternalId.ToString(), command.Latitude, command.Longitude);
                await transactionRepository.AddTransactionAsync(transactionIncome);

                var transfer = Transfer.Create(transactionExpense.Id, transactionIncome.Id, command.Rate);
                await transactionRepository.AddTransferAsync(transfer);

                await this.CreateTagsToTransaction(command.Tags, transactionExpense.Id);

                await this.MergeFiles(command.FileGuid, transactionExpense);
            }
            else
            {
                var type = command.Type.ToTransactionType();
                if (type == TransactionType.Expense && command.Amount > 0)
                {
                    command.Amount *= (-1);
                }
                else if (type == TransactionType.Income && command.Amount < 0)
                {
                    command.Amount *= (-1);
                }
                var transaction = Transaction.Create(command.AccountId, type, command.Amount, command.Date, command.Name, command.Comment, user.Id, false, command.CategoryId, command.ExternalId.ToString(), command.Latitude, command.Longitude);
                await this.transactionRepository.AddTransactionAsync(transaction);

                await this.CreateTagsToTransaction(command.Tags, transaction.Id);

                await this.MergeFiles(command.FileGuid, transaction);
            }
        }
예제 #2
0
 public HttpResponseMessage AddTransaction([FromBody] AddTransaction AddTransaction)
 {
     try
     {
         ChitTransaction _NewTransaction = new ChitTransaction();
         _NewTransaction.amount        = AddTransaction.Amount;
         _NewTransaction.Chitid        = AddTransaction.ChitId;
         _NewTransaction.userid        = AddTransaction.UserId;
         _NewTransaction.TermGroupId   = AddTransaction.TermGroupId;
         _NewTransaction.modeofpayment = AddTransaction.ModeOfPayment;
         _NewTransaction.paymentstatus = 1;
         _NewTransaction.Createddate   = DateTime.Now;
         _db.ChitTransactions.Add(_NewTransaction);
         _db.SaveChanges();
         return(Request.CreateResponse(HttpStatusCode.OK, "Success"));
     }
     catch
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Failed Transaction"));
     }
 }
        public async Task SeedAsync()
        {
            var accountGroup = (await this.accountGroupService.GetAccountGroupsAsync()).First();
            var currencies   = await this.currencyService.GetCurriencesAsync();

            var addAccountCommand = new AddAccount
            {
                AccountGroupId    = accountGroup.Id,
                Amount            = 0,
                CurrencyId        = currencies.First().Id,
                IsIncludedInTotal = true,
                Name  = "Test Account",
                Order = 0,
                Type  = AccountType.Account
            };
            await commandDispatcher.DispatchAsync(addAccountCommand);

            var account    = (await accountService.GetAccountsWithBalanceAsync()).First();
            var categories = await categoryService.GetCategoriesAsync();

            Random random = new Random();

            for (int i = 0; i < 5; i++)
            {
                var amount = random.Next(-20, 20);
                var addTransactionCommand = new AddTransaction
                {
                    AccountId  = account.Id,
                    Amount     = amount,
                    Date       = DateTime.UtcNow,
                    Type       = amount < 0 ? ExtendedTransactionType.Expense : ExtendedTransactionType.Income,
                    CategoryId = categories.First().Id,
                    Name       = Guid.NewGuid().ToString()
                };
                await commandDispatcher.DispatchAsync(addTransactionCommand);
            }
        }
예제 #4
0
 public void AddTransaction(AddTransaction command)
 {
     Transactions.Add(new Transaction(command));
     Balance += command.Amount;
 }
예제 #5
0
        public async Task <ActionResult> Add(AddTransaction command)
        {
            await _commandProcessor.ProcessAsync(command);

            return(RedirectToAction("Details", "Home", new GetAccountDetails(command.AccountId)));
        }
예제 #6
0
 public Transaction(AddTransaction command)
 {
     Description = command.Description;
     Amount      = command.Amount;
     AccountId   = command.AccountId;
 }
 public async Task <bool> AddOperationsHistory(AddTransaction message)
 {
     return(await _repository.AddOperationsHistory(message));
 }
 public async Task <IActionResult> PhoneShop([FromBody] AddTransaction command)
 {
     return(Ok());
 }