public async Task <bool> addMoneyToGoal(AddMoneyDTO data) { if (data.moneyToAdd <= await Task.Run(() => _expensesProcessor.getUserMoneyAsync(new UserIdDTO { userId = data.userId }))) { if (data.goalAllocatedMoney + data.moneyToAdd > data.goalRequiredMoney) { await _expensesProcessor.AddExpense(new NewExpenseDTO { userId = data.userId, ownerId = data.userId, expenseName = "Goal: " + data.goalName, moneyUsed = data.goalRequiredMoney - data.goalAllocatedMoney, expenseCategory = CategoryEnum.Goal }); modifyAllocatedMoney(new ModifyAllocatedMoneyDTO { goalId = data.goalId, newAllocatedMoney = data.goalRequiredMoney }); } else { await _expensesProcessor.AddExpense(new NewExpenseDTO { userId = data.userId, ownerId = data.userId, expenseName = "Goal: " + data.goalName, moneyUsed = data.moneyToAdd, expenseCategory = CategoryEnum.Goal }); modifyAllocatedMoney(new ModifyAllocatedMoneyDTO { goalId = data.goalId, newAllocatedMoney = data.goalAllocatedMoney + data.moneyToAdd }); } } return(true); }
public async Task <IActionResult> AddExpense([FromBody] NewExpenseDTO data) { if (await Task.Run(() => dv.isExpenseValidAsync(data))) { if (await Task.Run(() => exp.AddExpense(data))) { return(Ok("Expense added")); } else { BadRequest("Expense not added"); } } return(BadRequest("Expense is too big")); }