コード例 #1
0
        public IActionResult Update([FromBody] Noticias noticia, [FromRoute] int id)
        {
            Claim  userIdClaim = User.Claims.FirstOrDefault(x => x.Type.Contains("nameIdentifier"));
            string userId      = userIdClaim.Value;

            try
            {
                noticiasCore = new NoticiasCore(db);
                ResponseApiError responseApiError = noticiasCore.Update(noticia, id, userId);

                if (responseApiError != null)
                {
                    return(StatusCode(responseApiError.HttpStatusCode, responseApiError));
                }

                return(Ok(new ResponseApiSuccess {
                    Code = 1, Message = "Noticia modificada"
                }));
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                return(StatusCode((int)HttpStatusCode.InternalServerError, new ResponseApiError {
                    Code = 1001, Message = ex.Message
                }));
            }
        }
コード例 #2
0
        public IActionResult Get()
        {
            noticiasCore = new NoticiasCore(db);
            List <Noticias> noticias = noticiasCore.GetAll();

            return(Ok(noticias));
        }
コード例 #3
0
        public IActionResult GetNoticiasUsuario([FromRoute] string username)
        {
            noticiasCore = new NoticiasCore(db);
            List <NoticiasUsuarioView> noticias = noticiasCore.GetNoticiasUsuario(username);

            return(Ok(noticias));
        }
コード例 #4
0
        public IActionResult GetNoticiasComentario([FromRoute] int id)
        {
            noticiasCore = new NoticiasCore(db);
            List <NoticiasComentarioView> comentarios = noticiasCore.GetNoticiasComentarios(id);

            return(Ok(comentarios));
        }
コード例 #5
0
        public IActionResult Delete([FromRoute] int id)
        {
            try
            {
                noticiasCore = new NoticiasCore(db);
                ResponseApiError responseApiError = noticiasCore.Delete(id);

                if (responseApiError != null)
                {
                    return(StatusCode(responseApiError.HttpStatusCode, responseApiError));
                }

                return(Ok(new ResponseApiSuccess {
                    Code = 1, Message = "Noticia Eliminada"
                }));
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                return(StatusCode((int)HttpStatusCode.InternalServerError, new ResponseApiError {
                    Code = 1001, Message = ex.Message
                }));
            }
        }