public async Task <ActionResult <ExpenseDto> > CreateExpenseAsync(CreateExpenseDto createExpenseDto)
        {
            Expense expense = new()
            {
                Id            = Guid.NewGuid(),
                Category      = createExpenseDto.Category,
                Price         = createExpenseDto.Price,
                DateOfExpense = DateTimeOffset.UtcNow
            };

            await repository.CreateExpenseAsync(expense);

            return(CreatedAtAction(nameof(CreateExpenseAsync), new { id = expense.Id }, expense.AsDto()));
        }
示例#2
0
        public async Task <ActionResult <ExpenseDto> > CreateExpenseAsync(CreateExpenseDto expenseToCreate)
        {
            var newExpense = new Expense
            {
                Id = Guid.NewGuid(),
                ApplicationUserId = expenseToCreate.ApplicationUserId,
                Price             = expenseToCreate.Price,
                Description       = expenseToCreate.Description,
                DateOfExpense     = DateTimeOffset.UtcNow,
                CategoryId        = expenseToCreate.CategoryId
            };

            await _expensesRepository.CreateExpenseAsync(newExpense);

            return(CreatedAtAction(nameof(CreateExpenseAsync), new { id = newExpense.Id }, newExpense.AsDto()));
        }