public async Task <IActionResult> PutComment([FromRoute] int id, [FromBody] Comment comment) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != comment.CommentId) { return(BadRequest()); } _context.Entry(comment).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CommentExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Edit(int id, [Bind("ArticleId,Header,Summery,Content,HomeImageUrl,CategoryId,Location,IsShowMap")] Article article) { if (id != article.ArticleId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Articles.Attach(article); _context.Entry(article).Property(x => x.Content).IsModified = true; _context.Entry(article).Property(x => x.Header).IsModified = true; _context.Entry(article).Property(x => x.Summery).IsModified = true; _context.Entry(article).Property(x => x.HomeImageUrl).IsModified = true; _context.Entry(article).Property(x => x.CategoryId).IsModified = true; _context.Entry(article).Property(x => x.Location).IsModified = true; _context.Entry(article).Property(x => x.IsShowMap).IsModified = true; await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ArticleExists(article.ArticleId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(article)); }
public IQueryable <Article> GetFeatured(Category category) { return(_context.Entry(category).Collection(p => p.Articles).Query().Take(4)); }