public async Task <IActionResult> Delete(int id) { var location = GetControllerActionNames(); try { _logger.LogInfo($"{location}: delete Attempted on record with id: {id}"); if (id < 1) { _logger.LogWarn($"{location}:Delete failed with bad data - id: {id}"); return(BadRequest()); } var isExists = await _toyRepository.isExists(id); if (!isExists) { _logger.LogWarn($"{location}: Failed to retrieve record with id: {id}"); return(NotFound()); } var toy = await _toyRepository.FindById(id); var isSuccess = await _toyRepository.Delete(toy); if (!isSuccess) { return(internalError($"{location}: Delete failed for record with id: {id}")); } _logger.LogInfo($"{location} : Record with id: {id} successfully deleted"); return(NoContent()); } catch (Exception e) { return(internalError($"{location}: {e.Message} - {e.InnerException}")); } }
public async Task <ActionResult> Delete(int id) { try { await _repository.Delete(id); return(Ok()); } catch (ArgumentException e) { return(NotFound(e.Message)); } }
public void DeleteToy(Toy toy) { _toyRepository.Delete(toy.ToyId); _toyRepository.Save(); }