public async Task <ServiceResult> DeleteExpenseByIdAsync(Guid carId, Guid expenseId, Guid userId) { var expense = await _expenseRepository.GetExpenseByIdAsync(expenseId); if (expense == null) { return(FailedResult("Expense doesn't exists!", 404)); } var userHasCar = expense.Car.UserCars.FirstOrDefault(u => u.UserId == userId); if (userHasCar == null) { return(FailedResult("User has no permission to do that!", 401)); } if (expense.CarId != carId) { return(FailedResult("This is not this car expense", 400)); } if (await _expenseRepository.DeleteExpenseAsync(expense)) { return(SuccessResult(new DeleteExpenseResponse { Message = "Expense deleted" }, 200)); } return(FailedResult("Something went wrong", 500)); }
public async Task <IActionResult> DeleteExpense([FromRoute] int expenseEntryId) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var expense = await _expenseRepository.DeleteExpenseAsync(expenseEntryId); if (expense == null) { return(NotFound()); } return(Ok(expense)); }
public async Task <ActionResult> DeleteExpense(int id) { try { var status = await _ExpenseRepository.DeleteExpenseAsync(id); if (!status) { return(BadRequest(new ApiGeneralResponse { Status = false })); } return(Ok(new ApiGeneralResponse { Status = true, id = id })); } catch (Exception exp) { _Logger.LogError(exp.Message); return(BadRequest(new ApiGeneralResponse { Status = false })); } }