示例#1
0
        public async Task <ActionResult> UpdateExpenseAsync(Guid expenseId, UpdateExpenseDto expenseToUpdate)
        {
            var existingExpense = await _expensesRepository.GetExpenseAsync(expenseId);

            if (existingExpense is null)
            {
                return(NotFound());
            }

            Expense updatedExpense = existingExpense;

            updatedExpense.Price       = expenseToUpdate.Price;
            updatedExpense.Description = expenseToUpdate.Description;
            updatedExpense.CategoryId  = expenseToUpdate.CategoryId;

            await _expensesRepository.UpdateExpenseAsync(updatedExpense);

            return(NoContent());
        }
        public async Task <ActionResult> UpdateExpenseAsync(Guid id, UpdateExpenseDto expenseDto)
        {
            //get the expense we want to update
            var existingExpense = await repository.GetExpenseAsync(id);

            //If we did not find the expense return NotFound()
            if (existingExpense is null)
            {
                return(NotFound());
            }

            //Update the expense members
            Expense updatedExpense = existingExpense with
            {
                Category = expenseDto.Category,
                Price    = expenseDto.Price
            };

            //Update the expense in the expense collection
            await repository.UpdateExpenseAsync(updatedExpense);

            //PUT returns no content
            return(NoContent());
        }