コード例 #1
0
        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");
        }
コード例 #2
0
        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");
        }
コード例 #3
0
        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;
        }
コード例 #4
0
 public ActionResult Create(Project Project)
 {
     db.Projects.Add(Project);
     db.SaveChanges();
     return RedirectToAction("Index", "Admin");
 }