public async Task <IActionResult> PutCommentModel(int id, [FromBody] CommentModel commentModel) { if (id != commentModel.Id) { return(BadRequest()); } _context.Entry(commentModel).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CommentModelExists(id)) { return(NotFound()); } return(BadRequest()); } return(NoContent()); }
public async Task <TEntity> GetAsNoTrackingAsync(Expression <Func <TEntity, bool> > predicate, params string[] includes) { var entity = await AttachIncludes(includes).AsNoTracking().FirstOrDefaultAsync(predicate); Context.Entry(entity).State = EntityState.Detached; return(entity); }
public async Task <Comment> UpdateCommentAsync(Comment comment) { context.Entry(comment).State = EntityState.Modified; await context.SaveChangesAsync(); return(comment); }
/// <summary> /// Updates the user asynchronous. /// </summary> /// <param name="user">The user.</param> /// <returns>A <see cref="Task{User}"/></returns> public async Task <User> UpdateUserAsync(User user) { context.Entry(user).State = EntityState.Modified; await context.SaveChangesAsync(); return(user); }
public async Task <Article> UpdateArticleAsync(Article article) { context.Entry(article).State = EntityState.Modified; await context.SaveChangesAsync(); return(article); }
public async Task <ArticleCategory> UpdateArticleCategoryAsync(ArticleCategory articleCategory) { context.Entry(articleCategory).State = EntityState.Modified; await context.SaveChangesAsync(); return(articleCategory); }
public ActionResult Edit([Bind(Include = "Id,Name")] Category category) { if (ModelState.IsValid) { db.Entry(category).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Edit([Bind(Include = "Id,Title,Content,Date,CategoryId,UserId")] Article article) { if (ModelState.IsValid) { if (article.UserId == User.Identity.GetUserId() || User.IsInRole("Administrator")) { db.Entry(article).State = EntityState.Modified; db.SaveChanges(); TempData["message"] = "Article modified."; } else { TempData["message"] = "Warning: You do not own this article!"; } return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", article.CategoryId); return(View(article)); }
public ActionResult Edit(Comment comment) { if (ModelState.IsValid) { if (comment.UserId == User.Identity.GetUserId()) { db.Entry(comment).State = EntityState.Modified; db.SaveChanges(); TempData["message"] = "Comment modified."; } else { TempData["message"] = "Warning: You do not own this comment!"; } return(RedirectToAction("Details", "Articles", new { id = comment.ArticleId })); } return(View(comment)); }