Пример #1
0
        public async Task <IActionResult> PutComment([FromRoute] int id, [FromBody] Comment comment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != comment.Id)
            {
                return(BadRequest());
            }

            _context.Entry(comment).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #2
0
        public async Task <IActionResult> PutCategory(int id, Category category)
        {
            if (id != category.Id)
            {
                return(BadRequest());
            }

            _context.Entry(category).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #3
0
        public async Task <IActionResult> PutArticle(int id, Article article)
        {
            Article firstArticle = _context.Article.Find(id);

            firstArticle.Title          = article.Title;
            firstArticle.ContentSummary = article.ContentSummary;
            firstArticle.ContentMain    = article.ContentMain;
            firstArticle.CategoryId     = article.Category.Id;
            firstArticle.Picture        = article.Picture;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ArticleExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }