public ActionResult AddProject(AddEditProjectsViewModel formData) { if (!ModelState.IsValid) { return(View()); } var userId = User.Identity.GetUserId(); var project = new Project(); project.Name = formData.Name; Context.Projects.Add(project); Context.SaveChanges(); return(RedirectToAction(nameof(ProjectsController.IndexAllProjects))); }
public ActionResult EditProject(int?id) { if (!id.HasValue) { return(RedirectToAction(nameof(ProjectsController.IndexAllProjects))); } var project = Context.Projects.FirstOrDefault(p => p.Id == id.Value); if (project == null) { return(RedirectToAction(nameof(ProjectsController.IndexAllProjects))); } var model = new AddEditProjectsViewModel(); model.Name = project.Name; return(View(model)); }
public ActionResult EditProject(int?id, AddEditProjectsViewModel model) { if (!id.HasValue) { return(RedirectToAction(nameof(ProjectsController.IndexAllProjects))); } if (!ModelState.IsValid) { return(View()); } var project = Context.Projects.FirstOrDefault(p => p.Id == id.Value); project.Name = model.Name; project.DateUpdated = DateTime.Now; Context.SaveChanges(); return(RedirectToAction(nameof(ProjectsController.IndexAllProjects))); }