public ActionResult DoAddProject(Project project) { var errors = GetProjectValidationErrors(project); if (errors.Count > 0) { return View("InvalidProject", errors); } context.Projects.Add(project); context.SaveChanges(); return View("ProjectAdded"); }
public ActionResult DoEditProject(Project project) { var errors = GetProjectValidationErrors(project); if (errors.Count > 0) { return View("InvalidProject", errors); } Project entity = context.Projects .Where(p => p.ProjectId == project.ProjectId).FirstOrDefault(); entity.Name = project.Name; entity.Description = project.Description; context.SaveChanges(); return View("ProjectEdited"); }
private List<string> GetProjectValidationErrors(Project project) { List<string> errors = new List<string>(); if (string.IsNullOrEmpty(project.Name) || string.IsNullOrWhiteSpace(project.Name)) { errors.Add("The project name should not be empty"); } if (string.IsNullOrEmpty(project.Description) || string.IsNullOrWhiteSpace(project.Description)) { errors.Add("The description should not be empty"); } return errors; }
public ActionResult Create(Project Project) { db.Projects.Add(Project); db.SaveChanges(); return RedirectToAction("Index", "Admin"); }