public async Task <ServiceResult> CreateExpenseAsync(Guid carId, Guid userId, Expense expense) { var car = await _carRepository.GetCarByIdAsync(carId); if (car == null) { return(FailedResult("Car doesn't exist", 404)); } if (car.UserCars.FirstOrDefault(u => u.UserId == userId) == null) { return(FailedResult("User can't do that", 401)); } if (!await VerifyExpenseCategory(expense.Category)) { return(FailedResult("Wrong expense category", 400)); } expense.Car = car; expense.UserId = userId; if (!await _expenseRepository.CreateExpenseAsync(expense)) { return(FailedResult("Something went wrong", 500)); } return(SuccessResult(_mapper.Map <ExpenseResponse>(expense), 201)); }