示例#1
0
        public Project EditProject(ProjectModel editProject)
        {
            var project           = ProjectUtil.CastToDbo(editProject);
            var environmentsToAdd = project.Environments;

            project.Environments = null;
            var updatedProject = _projectRepository.Edit(project);

            if (environmentsToAdd != null)
            {
                foreach (var env in environmentsToAdd)
                {
                    if (env.EnvironmentId != 0)
                    {
                        env.Machines  = null;
                        env.ProjectId = updatedProject.ProjectId;
                        _environmentInfoRepository.Edit(env);
                    }
                    else
                    {
                        env.ProjectId = updatedProject.ProjectId;
                        _environmentInfoRepository.Create(env);
                    }
                }
            }
            //delete all deleted envinroments
            var envsToSave  = environmentsToAdd.Select(_ => _.EnvironmentId);
            var allEnvIds   = _environmentInfoRepository.GetAllEnvIds(updatedProject.ProjectId);
            var idsToDelete = allEnvIds.Except(envsToSave).ToList();

            foreach (var id in idsToDelete)
            {
                _environmentInfoRepository.Delete(id);
            }

            return(_projectRepository.GetByProjectId(updatedProject.ProjectId));
        }
        public EnvironmentInfo EditEnvironment(EnvironmentInfoModel editEnvironment)
        {
            var Environment = EnvironmentUtil.CastToDbo(editEnvironment);

            return(_EnvironmentRepository.Edit(Environment));
        }