public ActionResult CreateProject(ProjectManipulationViewModel newProject) { var project = new Project() { Title = newProject.Title, IsArchived = false }; DbContext.Projects.Add(project); DbContext.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult EditProject(int?projectId) { var project = ProjectHelper.GetProjectById(DbContext, (int)projectId); if (project is null) { return(RedirectToAction("Index")); } var projectViewModel = new ProjectManipulationViewModel() { Title = project.Title, Id = project.Id }; return(View(projectViewModel)); }
public ActionResult EditProject(ProjectManipulationViewModel editedProject) { if (!ModelState.IsValid) { return(RedirectToAction("Index")); } var projectFromDb = ProjectHelper.GetProjectById(DbContext, editedProject.Id); if (projectFromDb is null) { return(RedirectToAction("Index")); } projectFromDb.Title = editedProject.Title; DbContext.SaveChanges(); return(RedirectToAction("Index")); }