public async Task <Department> UpdateDepartment(Department department) { _dbContext.Entry(department).State = EntityState.Modified; await _dbContext.SaveChangesAsync(); return(department); }
public ActionResult Edit([Bind(Include = "Id,Title,Description,State,Author,Assignee,Date,Tags")] Issue issue, string returnTo = "Index") { if (!UserAuthorizedToEdit(issue)) { this.AddNotification("You're not authorized to edit this issue! Please log in.", NotificationType.Error); return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized, "You're not authorized to edit others' issues")); } var oldIssue = db.Issues.First(a => a.Id == issue.Id); if (UserCreatedIssue(oldIssue) || UserIsAdmin(issue)) { oldIssue.Title = issue.Title; oldIssue.Description = issue.Description; } else { issue.Title = oldIssue.Title; issue.Description = oldIssue.Description; } oldIssue.State = issue.State; issue = oldIssue; ViewBag.IsOwnIssue = UserCreatedIssue(issue); ModelState["Author"].Errors.Clear(); ModelState["Tags"].Errors.Clear(); TryValidateModel(issue); if (ModelState.IsValid) { db.Entry(issue).State = EntityState.Modified; db.SaveChanges(); this.AddNotification("Edited issue!", NotificationType.Success); return(RedirectToAction(returnTo)); } return(View(issue)); }