コード例 #1
0
 public IActionResult Delete(int id)
 {
     try
     {
         HogarCore hogarCore = new HogarCore(dbContext);
         hogarCore.Delete(id);
         return(Ok("Hogar eliminado correctamente."));
     }
     catch (Exception ex)
     {
         return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message));
     }
 }
コード例 #2
0
 public IActionResult Disable(int id)
 {
     try
     {
         if (!Funciones.Validadores.validaId(id))
         {
             return(BadRequest(Funciones.Constantes.BAD_REQUEST));
         }
         HogarCore hogarCore = new HogarCore(dbContext);
         hogarCore.Hide(id);
         return(Ok("Hogar se ocultó exitosamente. No podrá recibir reservaciones."));
     }
     catch (Exception ex)
     {
         return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message));
     }
 }
コード例 #3
0
        public IActionResult Update([FromBody] Hogar mascota, [FromRoute] int id)
        {
            try
            {
                if (!Funciones.Validadores.validaObjeto(mascota) || !Funciones.Validadores.validaId(id))
                {
                    return(BadRequest(Funciones.Constantes.BAD_REQUEST));
                }

                HogarCore hogarCore = new HogarCore(dbContext);
                hogarCore.Update(mascota, id);
                return(Ok("La información de tu hogar ha sido actualizada exitosamente."));
            }
            catch (Exception ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message));
            }
        }
コード例 #4
0
        public IActionResult Create([FromBody] Hogar hogar)
        {
            try
            {
                if (!Funciones.Validadores.validaObjeto(hogar))
                {
                    return(BadRequest(Funciones.Constantes.BAD_REQUEST));
                }
                HogarCore hogarCore = new HogarCore(dbContext);

                hogarCore.Create(hogar);
                return(Ok("Felicidades! Tu hogar se ha registrado como Hotel para mascotas correctamente. 🐶💗"));
            }
            catch (Exception ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }
コード例 #5
0
        public IActionResult Get()
        {
            try
            {
                HogarCore    hogarCore         = new HogarCore(dbContext);
                List <Hogar> hogaresPublicados = hogarCore.Get();

                if (hogaresPublicados.Count == 0)
                {
                    return(NotFound(Funciones.Constantes.GENERAL_NOT_FOUND));
                }

                return(Ok(hogaresPublicados));
            }
            catch (Exception ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }
コード例 #6
0
        public IActionResult GetAll()
        {
            try
            {
                HogarCore             hogarCore = new HogarCore(dbContext);
                List <HogarViewModel> hogares   = hogarCore.GetAll();

                if (!Funciones.Validadores.validaLista(hogares))
                {
                    return(NotFound(Funciones.Constantes.NOT_FOUND));
                }

                return(Ok(hogares));
            }
            catch (Exception ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }
コード例 #7
0
        public IActionResult Get(int id)
        {
            try
            {
                if (!Funciones.Validadores.validaId(id))
                {
                    return(BadRequest(Funciones.Constantes.BAD_REQUEST));
                }

                HogarCore          hogarCore  = new HogarCore(dbContext);
                IQueryable <Hogar> hogarFound = hogarCore.Get(id);
                if (hogarFound.ToList().Count == 0)
                {
                    return(NotFound(Funciones.Constantes.NOT_FOUND));
                }

                return(Ok(hogarFound));
            }
            catch (Exception ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }
コード例 #8
0
        public IActionResult GetFromCliente(int clienteId)
        {
            try
            {
                if (!Funciones.Validadores.validaId(clienteId))
                {
                    return(BadRequest(Funciones.Constantes.BAD_REQUEST));
                }

                HogarCore hogarCore = new HogarCore(dbContext);

                List <Hogar> hogaresFromCliente = hogarCore.GetFromCliente(clienteId);
                if (!Funciones.Validadores.validaLista(hogaresFromCliente))
                {
                    return(NotFound(Funciones.Constantes.NOT_FOUND));
                }

                return(Ok(hogaresFromCliente));
            }
            catch (Exception ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }