public ActionResult DeleteProjectConfig(string projectName, string name)
        {
            if (string.IsNullOrWhiteSpace(projectName))
            {
                return(View("Error"));
            }

            if (string.IsNullOrWhiteSpace(name))
            {
                return(View("Error"));
            }

            using (var db = new BuildVersioningDataContext())
            {
                var projectConfig = db.ProjectConfigs
                                    .Include(c => c.Project)
                                    .SingleOrDefault(c =>
                                                     string.Compare(c.Project.Name, projectName, StringComparison.OrdinalIgnoreCase) == 0 &&
                                                     string.Compare(c.Name, name, StringComparison.OrdinalIgnoreCase) == 0
                                                     );

                if (null == projectConfig)
                {
                    return(RedirectToRoute("ViewProject", new { name = projectName }));
                }

                db.ProjectConfigs.Remove(projectConfig);
                db.SaveChanges();
            }

            return(RedirectToRoute("ViewProject", new { name = projectName }));
        }
Esempio n. 2
0
		protected virtual void Initialize(string connectionString = null)
		{
			if (string.IsNullOrWhiteSpace(connectionString))
				connectionString = GetConfiguredConnectionString();

			using (var db = new BuildVersioningDataContext(connectionString))
			{
				DeleteTestProjectAndTestProjectConfig(db);

				var project =
					new Project
					{
						Name = TestProjectName,
						BuildNumber = 0,
						DateBuildNumberUpdated = DateTime.Now
					};
				db.Projects.Add(project);
				db.SaveChanges();

				var projectConfig =
					new ProjectConfig
					{
						ProjectId = project.Id,
						Name = TestProjectConfigName,
						GeneratedBuildNumberPosition = 3,
						GeneratedVersionPart1 = 1,
						GeneratedVersionPart2 = 0,
						GeneratedVersionPart3 = 0,
						GeneratedVersionPart4 = 0,
						ProductVersionPart1 = 1,
						ProductVersionPart2 = 0,
						ProductVersionPart3 = 0,
						ProductVersionPart4 = 0,
						ReleaseType = ReleaseType.PreRelease
					};
				db.ProjectConfigs.Add(projectConfig);
				db.SaveChanges();
			}
		}
Esempio n. 3
0
        public ActionResult AddProject(AddProjectModel addProject)
        {
            if (null == addProject)
            {
                return(View("Error"));
            }

            var name = addProject.Name;

            if (string.IsNullOrWhiteSpace(name))
            {
                return(View("Error"));
            }

            var desc = addProject.Description;

            if (string.IsNullOrWhiteSpace(desc))
            {
                desc = null;
            }

            using (var db = new BuildVersioningDataContext())
            {
                if (db.Projects.Any(p => string.Compare(p.Name, name, StringComparison.OrdinalIgnoreCase) == 0))
                {
                    return(View("Error"));                    // <-- A project with the same name already exists.
                }
                var project =
                    new Project
                {
                    Name                   = name,
                    Description            = desc,
                    BuildNumber            = 0,
                    DateBuildNumberUpdated = DateTime.Now
                };

                db.Projects.Add(project);
                db.SaveChanges();
            }

            return(RedirectToRoute("ListProjects"));
        }
Esempio n. 4
0
        public ActionResult DeleteProject(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                return(View("Error", new ErrorInfo("Project", "DeleteProject", "The project name is null, empty or contains only whitespace which is not allowed.")));
            }

            using (var db = new BuildVersioningDataContext())
            {
                var project = db.Projects
                              .Include(p => p.ProjectConfigs)
                              .SingleOrDefault(p =>
                                               string.Compare(p.Name, name, StringComparison.OrdinalIgnoreCase) == 0
                                               );

                if (null == project)
                {
                    return(RedirectToRoute("ListProjects"));
                }

                var projectConfigIds = project.ProjectConfigs.Select(c => c.Id).ToList();

                // Delete all child project configs.
                foreach (var projectConfigId in projectConfigIds)
                {
                    var projectConfig = db.ProjectConfigs.SingleOrDefault(c => c.Id == projectConfigId);
                    if (null != projectConfig)
                    {
                        db.ProjectConfigs.Remove(projectConfig);
                    }
                }

                // Delete the project.
                db.Projects.Remove(project);
                db.SaveChanges();
            }

            return(RedirectToRoute("ListProjects"));
        }
        public ActionResult AddProjectConfig(AddProjectConfigModel addProjectConfig)
        {
            if (null == addProjectConfig)
            {
                return(View("Error"));
            }

            // Validate ParentProjectId
            var parentProjectId = addProjectConfig.ParentProjectId;

            if (parentProjectId < 1)
            {
                return(View("Error"));
            }

            // Validate ParentProjectName
            var parentProjectName = addProjectConfig.ParentProjectName;

            if (string.IsNullOrWhiteSpace(parentProjectName))
            {
                return(View("Error"));
            }

            // Validate Name
            var name = addProjectConfig.Name;

            if (string.IsNullOrWhiteSpace(name))
            {
                return(View("Error"));
            }

            var desc = addProjectConfig.Description;

            if (string.IsNullOrWhiteSpace(desc))
            {
                desc = null;
            }

            var buildNumberPostion = (int)addProjectConfig.BuildNumberPosition;

            if (buildNumberPostion < 3 || buildNumberPostion > 4)
            {
                return(View("Error"));
            }

            // Force the GeneratedVersion part that corresponds to the build number position to a value of zero.
            switch (buildNumberPostion)
            {
            case 3:
                addProjectConfig.GeneratedVersionPart3 = 0;
                break;

            case 4:
                addProjectConfig.GeneratedVersionPart4 = 0;
                break;
            }

            using (var db = new BuildVersioningDataContext())
            {
                if (db.ProjectConfigs
                    .Include(c => c.Project)
                    .Any(c =>
                         c.Project.Id == parentProjectId &&
                         string.Compare(c.Name, name, StringComparison.OrdinalIgnoreCase) == 0
                         ))
                {
                    return(View("Error"));                    // <-- A ProjectConfig with the same parent Project and the same name already exists.
                }
                var projectConfig =
                    new ProjectConfig
                {
                    Description = desc,
                    GeneratedBuildNumberPosition = buildNumberPostion,
                    GeneratedVersionPart1        = addProjectConfig.GeneratedVersionPart1,
                    GeneratedVersionPart2        = addProjectConfig.GeneratedVersionPart2,
                    GeneratedVersionPart3        = addProjectConfig.GeneratedVersionPart3,
                    GeneratedVersionPart4        = addProjectConfig.GeneratedVersionPart4,
                    Name = name,
                    ProductVersionPart1 = addProjectConfig.ProductVersionPart1,
                    ProductVersionPart2 = addProjectConfig.ProductVersionPart2,
                    ProductVersionPart3 = addProjectConfig.ProductVersionPart3,
                    ProductVersionPart4 = addProjectConfig.ProductVersionPart4,
                    ProjectId           = parentProjectId,
                    ReleaseType         = addProjectConfig.ReleaseType
                };

                db.ProjectConfigs.Add(projectConfig);
                db.SaveChanges();
            }

            return(RedirectToRoute("ViewProject", new { name = parentProjectName }));
        }
        public ActionResult EditProjectConfig(string projectName, string name, EditProjectConfigModel editProjectConfig)
        {
            if (null == editProjectConfig)
            {
                return(View("Error"));
            }

            // Validate id (the ProjectConfig.Id to be edited)
            var id = editProjectConfig.Id;

            if (id < 1)
            {
                return(View("Error"));
            }

            // Validate ParentProjectId
            var parentProjectId = editProjectConfig.ParentProjectId;

            if (parentProjectId < 1)
            {
                return(View("Error"));
            }

            // Validate ParentProjectName
            var parentProjectName = editProjectConfig.ParentProjectName;

            if (string.IsNullOrWhiteSpace(parentProjectName))
            {
                return(View("Error"));
            }

            // Validate Name
            var newName = editProjectConfig.Name;

            if (string.IsNullOrWhiteSpace(name))
            {
                return(View("Error"));
            }

            var desc = editProjectConfig.Description;

            if (string.IsNullOrWhiteSpace(desc))
            {
                desc = null;
            }

            var buildNumberPostion = (int)editProjectConfig.BuildNumberPosition;

            if (buildNumberPostion < 3 || buildNumberPostion > 4)
            {
                return(View("Error"));
            }

            // Force the GeneratedVersion part that corresponds to the build number position to a value of zero.
            switch (buildNumberPostion)
            {
            case 3:
                editProjectConfig.GeneratedVersionPart3 = 0;
                break;

            case 4:
                editProjectConfig.GeneratedVersionPart4 = 0;
                break;
            }

            using (var db = new BuildVersioningDataContext())
            {
                if (name != newName && db.ProjectConfigs
                    .Include(c => c.Project)
                    .Any(c =>
                         c.Project.Id == parentProjectId &&
                         string.Compare(c.Name, newName, StringComparison.OrdinalIgnoreCase) == 0
                         ))
                {
                    return(View("Error"));                    // <-- A ProjectConfig with the same parent Project and the same name already exists.
                }
                var projectConfig =
                    db.ProjectConfigs
                    .Include(c => c.Project)
                    .SingleOrDefault(c =>
                                     c.Project.Id == parentProjectId &&
                                     c.Id == id
                                     );

                if (null == projectConfig)
                {
                    return(View("Error"));
                }

                projectConfig.Description = desc;
                projectConfig.GeneratedBuildNumberPosition = buildNumberPostion;
                projectConfig.GeneratedVersionPart1        = editProjectConfig.GeneratedVersionPart1;
                projectConfig.GeneratedVersionPart2        = editProjectConfig.GeneratedVersionPart2;
                projectConfig.GeneratedVersionPart3        = editProjectConfig.GeneratedVersionPart3;
                projectConfig.GeneratedVersionPart4        = editProjectConfig.GeneratedVersionPart4;
                projectConfig.Name = newName;
                projectConfig.ProductVersionPart1 = editProjectConfig.ProductVersionPart1;
                projectConfig.ProductVersionPart2 = editProjectConfig.ProductVersionPart2;
                projectConfig.ProductVersionPart3 = editProjectConfig.ProductVersionPart3;
                projectConfig.ProductVersionPart4 = editProjectConfig.ProductVersionPart4;
                projectConfig.ReleaseType         = editProjectConfig.ReleaseType;

                db.SaveChanges();
            }

            return(RedirectToRoute("ViewProjectConfig", new { projectName = parentProjectName, name }));
        }
Esempio n. 7
0
        public ActionResult EditProject(string name, EditProjectModel editProject)
        {
            if (null == editProject)
            {
                return(View("Error", new ErrorInfo("Project", "EditProject", "The editProject model is null which is not allowed.")));
            }

            var id = editProject.Id;

            if (id < 1)
            {
                return(View("Error", new ErrorInfo("Project", "EditProject", "The project id is not valid.")));
            }

            var newName = editProject.Name;

            if (string.IsNullOrWhiteSpace(newName))
            {
                return(View("Error", new ErrorInfo("Project", "EditProject", "The new project name is null, empty or contains only whitespace which is not allowed.")));
            }

            var desc = editProject.Description;

            if (string.IsNullOrWhiteSpace(desc))
            {
                desc = null;
            }

            var buildNumber = editProject.BuildNumber;

            if (buildNumber < 0)
            {
                buildNumber = 0;
            }

            using (var db = new BuildVersioningDataContext())
            {
                if (name != newName && db.Projects.Any(p => string.Compare(p.Name, newName, StringComparison.OrdinalIgnoreCase) == 0))
                {
                    return(View("Error", new ErrorInfo("Project", "EditProject", "A project with the specified new name already exists.")));
                }

                var project = db.Projects.SingleOrDefault(p => p.Id == id);
                if (null == project)
                {
                    return(View("Error", new ErrorInfo("Project", "EditProject", "The specified project id of the project to be edited does not exist.")));
                }

                project.Name        = newName;
                project.Description = desc;

                if (project.BuildNumber != buildNumber)
                {
                    project.BuildNumber            = buildNumber;
                    project.DateBuildNumberUpdated = DateTime.Now;
                }

                db.SaveChanges();
            }

            return(RedirectToRoute("ViewProject", new { name }));
        }