public ActionResult <bool> Delete(int id) { try { return(Ok(_repository.Delete(id))); } catch (Exception ex) { _logger.LogError($"Error: Controller exception on Delete(int id)"); return(StatusCode((int)HttpStatusCode.InternalServerError, new { Error = ex.Message })); } }
public async Task <bool> DeleteVehicle(int id) { try { var deleted = await vehicleRepository.Delete(id); return(deleted); } catch (Exception ex) { logger.LogError(ex, ex.Message); } return(false); }
public async Task <Unit> Handle(Data request, CancellationToken cancellationToken) { var vehicle = _vehiclesRepository.GetSingle(request.Id); if (vehicle == null) { throw new Exception("no record found"); } _vehiclesRepository.Delete(vehicle); var result = await _vehiclesRepository.Commit(); if (result > 0) { return(Unit.Value); } throw new Exception("Records were not saved"); }
public async Task <IActionResult> DeleteVehicleAsync(int id) { var domainVehicle = await _vehiclesRepository.GetAsync(id); if (domainVehicle == null) { ModelState.AddModelError("Id", $"Vehicle with Id = {id} not found!"); } if (ModelState.ErrorCount > 0) { return(BadRequest(ModelState)); } try { // ReSharper disable once AssignNullToNotNullAttribute _vehiclesRepository.Delete(domainVehicle); await _unitOfWork.CompeleteAsync(); return(Ok(id)); } catch (Exception e) { return(StatusCode(500, e.InnerException?.Message ?? e.Message)); } }
public Vehicle Delete(long id) { return(vehiclesRepository.Delete(id)); }