public async Task<ActionResult> New(Project project) { if (ModelState.IsValid) { Context.Projects.Add(project); if (await Context.SaveChangesAsync() > 0) { return RedirectToAction("Index"); } } ModelState.AddModelError("", "Unable to create project, please try again."); return View(); }
public async Task<ActionResult> Edit(Project project, int projectId) { var existing = await Context.Projects.FindAsync(projectId); if (ModelState.IsValid && TryUpdateModel(existing)) { var result = await Context.SaveChangesAsync(); if (result > 0) { return RedirectToAction("Index"); } } ViewBag.EnableDelete = await Context.Projects.CountAsync() > 1; return View(project); }