public async Task <IActionResult> PutArticle([FromRoute] int id, [FromBody] ViewModel.Article article) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != article.Id) { return(BadRequest()); } Article temp = _context.Articles.FirstOrDefault(a => a.Id == article.Id); temp.Content = article.Content; temp.Title = article.Title; foreach (var item in article.Images) { _context.SetOfImages.Add(new SetOfImages { Image = item, Article = new Article { Id = temp.Id } }); } try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ArticleExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PostArticle([FromBody] ViewModel.Article article) { Article temp = _context.Articles.Add(new Article { Content = article.Content, Title = article.Title }).Entity; foreach (var item in article.Images) { _context.SetOfImages.Add(new SetOfImages { Image = item, Article = new Article { Id = temp.Id } }); } await _context.SaveChangesAsync(); return(CreatedAtAction("GetArticle", new { id = article.Id }, article)); }