public ActionResult <Dog> Delete(string id) { if (string.IsNullOrEmpty(id)) { return(BadRequest()); } try { var dogToDelete = Get(id); if (dogToDelete.Value == null) { return(StatusCode(404)); } else { _dogService.DeleteDog(dogToDelete.Value); return(dogToDelete); } } catch (Exception) //Se ha encontrado dos perros con el mismo ID, no debería pasar por la lógica de generación de ID, pero se contempla el posible error { return(StatusCode(500)); } }
public ActionResult Delete(int id) { if (!_dogService.DogFactExists(id)) { return(StatusCode(StatusCodes.Status400BadRequest, "The dog could not be found")); } _dogService.DeleteDog(id); return(StatusCode(StatusCodes.Status200OK, $"The dog has been deleted.")); }
public ActionResult DeleteDog(int?DogID) { if (DogID == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } else { if (dogService.DeleteDog((int)DogID)) { return(Json(true)); } else { return(Json(false)); } } }
public async Task <ActionResult> Delete(int id) { DeleteDogResponse response = await _service.DeleteDog(id, GetUserId()); switch (response) { case DeleteDogResponse.Success: return(Ok()); case DeleteDogResponse.Unauthorized: _logger.LogWarning($"Request user ({GetUserId()}) does not have permission (non-owner) to delete dog id {id}"); return(Unauthorized()); case DeleteDogResponse.Failed: _logger.LogWarning($"Dog delete requested by {GetUserId()} failed for dog id {id}"); return(NotFound()); default: _logger.LogWarning($"Dog delete requested by {GetUserId()} failed for dog id {id}"); return(NotFound()); } }