Ejemplo n.º 1
0
        public async Task <IActionResult> PostArticle([FromBody] ArticlePostDto dto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var article = dto.Adapt <Article>();

            article.LastEdited = DateTime.UtcNow;

            await _articleSvc.AddAsync(article, User.GetId());

            return(CreatedAtAction("GetArticle", new { id = article.Id }, article));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PutArticle([FromRoute] int id, [FromBody] ArticlePostDto dto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var article = dto.Adapt <Article>();

            article.Id = id;

            var result = await _articleSvc.UpdateAsync(article, User.GetId());

            if (result.Success)
            {
                return(NoContent());
            }

            return(BadRequest(result.Msg));
        }