Ejemplo n.º 1
0
        public async Task <IHttpActionResult> NoticiaGet(NoticiaRequest noticia)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    NoticiaDTO noticiaDTO = Mapper.Map <NoticiaRequest, NoticiaDTO>(noticia);
                    var        resultado  = await informacionnoticia.GetBy_NoticiaDto(noticia.Codigo);

                    if (resultado.Success)
                    {
                        if (resultado.Result != null)
                        {
                            NoticiaResponse datosNoticiaResponse = Mapper.Map <NoticiaDTO, NoticiaResponse>(resultado.Result);
                            return(Ok(datosNoticiaResponse));
                        }
                        else
                        {
                            return(NotFound());
                        }
                    }
                    else
                    {
                        return(BadRequest(resultado.Error.ToString()));
                    }
                }
                return(BadRequest(ModelState));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.ToString()));
            }
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> NoticiaDelete(NoticiaRequest noticia)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    NoticiaDTO noticiaDTO = Mapper.Map <NoticiaRequest, NoticiaDTO>(noticia);
                    var        resultado  = await informacionnoticia.DeleteNoticiaDto(noticiaDTO);

                    if (resultado.Success)
                    {
                        return(Ok(resultado.Result));
                    }
                    else
                    {
                        return(BadRequest(resultado.Error.ToString()));
                    }
                }
                return(BadRequest(ModelState));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.ToString()));
            }
        }