Exemplo n.º 1
0
        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));
            }
        }
Exemplo n.º 2
0
        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."));
        }
Exemplo n.º 3
0
 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));
         }
     }
 }
Exemplo n.º 4
0
        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());
            }
        }