public async Task <IActionResult> Edit(int id, [Bind("Id,Tag")] ContentTag contentTag) { if (id != contentTag.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(contentTag); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContentTagExists(contentTag.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(contentTag)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Title,ReleaseDate,Content")] Article article) { if (id != article.Id) { return(NotFound()); } if (ModelState.IsValid) { try { List <ContentTag> contentTags = await _context.ContentTags.ToListAsync(); foreach (var item in contentTags) { string isChecked = Request.Form[item.Tag]; if (isChecked == "false") { ArticleHasTag removedTag = await _context.ArticleHasTags.FindAsync(article.Id, item.Id); if (removedTag != null) { _context.ArticleHasTags.Remove(removedTag); } } else { ArticleHasTag addTag = await _context.ArticleHasTags.FindAsync(article.Id, item.Id); if (addTag == null) { addTag = new ArticleHasTag() { Article = article, ArticleId = article.Id, ContentTag = item, ContentTagId = item.Id }; _context.ArticleHasTags.Add(addTag); } } } _context.Update(article); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ArticleExists(article.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(article)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Email,Password,IsAdmin")] User user) { if (id != user.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(user); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(user.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(user)); }