Пример #1
0
        public async Task <IActionResult> PostExpense([FromBody] Expense expense)
        {
            if (string.IsNullOrEmpty(expense.Title))
            {
                return(BadRequest());
            }

            var expenseEntryId = await _expenseRepository.AddExpenseAsync(expense);

            return(CreatedAtAction("GetExpense", new { expenseEntryId }, expense));
        }
        public async Task <ShallowExpenseDto> Handle(CreateExpenseCommand request, CancellationToken cancellationToken)
        {
            var expense = _mapper.Map <Expense>(request.Expense);

            expense.Owner = await _userRepo.GetUserByIdAsync(request.OwnerId);

            expense = await _expenseRepo.AddExpenseAsync(expense);

            if (0 == await _expenseRepo.SaveChangesAsync())
            {
                return(null);
            }

            return(_mapper.Map <ShallowExpenseDto>(expense));
        }
Пример #3
0
 public async Task <bool> AddExpenseAsync(Expense expense)
 {
     return(await _expenseRepository.AddExpenseAsync(expense));
 }