Пример #1
0
        public ActionResult <int> Put([FromBody] ArticleDto articleDto)
        {
            var userId  = GetUser().Id;
            var article = Context.Articles.Where(_ => _.UserId == userId && _.ArticleId == articleDto.Id).FirstOrDefault();

            if (article == null)
            {
                return(NotFound());
            }

            article.Title       = articleDto.Title;
            article.Content     = articleDto.Content;
            article.State       = articleDto.State;
            article.VisibleFrom = articleDto.VisibleFrom;

            Context.SaveChanges();

            return(article.ArticleId);
        }
Пример #2
0
        public ActionResult <ArticleDto> Post(ArticleDto articleDto)
        {
            var article = new Article
            {
                UserId      = GetUser().Id,
                Title       = articleDto.Title,
                Content     = articleDto.Content,
                State       = articleDto.State,
                VisibleFrom = articleDto.VisibleFrom
            };

            Context.Articles.Add(article);
            Context.SaveChanges();

            return(new ArticleDto
            {
                Id = article.ArticleId,
                Title = article.Title,
                Content = article.Content,
                State = article.State
            });
        }