protected override TeamModel AddTeam()
 {
     EFTeamRepository teams = new EFTeamRepository { CreateContext = GetContext };
     var newTeam = new TeamModel { Name="Team1" };
     teams.Create(newTeam);
     return newTeam;
 }
 protected override TeamModel CreateTeam()
 {
     var newTeam = new TeamModel { Name = "Team1", Id = Guid.NewGuid() };
     newTeam.Members = new UserModel[0];
     ADBackend.Instance.Teams.Add(newTeam);
     return newTeam;
 }
        public bool Create(TeamModel model)
        {
            if (model == null) throw new ArgumentException("team");
            if (model.Name == null) throw new ArgumentException("name");

            using (var database = new DataEntities())
            {
                var team = new Team
                {
                    Name = model.Name,
                    Description = model.Description
                };
                database.AddToTeam(team);
                if (model.Members != null)
                {
                    AddMembers(model.Members, team, database);
                }
                try
                {
                    database.SaveChanges();
                }
                catch (UpdateException)
                {
                    return false;
                }
            }

            return true;
        }
        public void DeletingMissingTeamIsSilentlyIgnored()
        {
            var team1 = new TeamModel { Name = "Team1", Description = "Test Team" };
            CreateTeam(team1);

            _repo.Delete(Guid.NewGuid());

            Assert.AreEqual("Team1", _repo.GetAllTeams().Single().Name);
        }
        public void TeamCanBeDeleted()
        {
            var team1 = new TeamModel { Name = "Team1", Description = "Test Team" };
            CreateTeam(team1);
            var team2 = new TeamModel { Name = "Team2", Description = "Test Team" };
            CreateTeam(team2);

            _repo.Delete(team1.Id);

            Assert.AreEqual("Team2", _repo.GetAllTeams().Single().Name);
        }
        public void EnsureCollectionsAreValid()
        {
            if (Administrators == null)
            {
                Administrators = new UserModel[0];
            }

            if (Users == null)
            {
                Users = new UserModel[0];
            }

            if (Teams == null)
            {
                Teams = new TeamModel[0];
            }
        }
        public bool Create(TeamModel model)
        {
            if (model == null) throw new ArgumentException("team");
            if (model.Name == null) throw new ArgumentException("name");

            using (var database = CreateContext())
            {
                // Write this into the model so that the caller knows the ID of the new itel
                model.Id = Guid.NewGuid();
                var team = new Team
                {
                    Id = model.Id,
                    Name = model.Name,
                    Description = model.Description
                };
                database.Teams.Add(team);
                if (model.Members != null)
                {
                    AddMembers(model.Members.Select(x => x.Id), team, database);
                }
                try
                {
                    database.SaveChanges();
                }
                catch (DbUpdateException)
                {
                    return false;
                }
                catch (UpdateException)
                {
                    // Not sure when this exception happens - DbUpdateException is what you get for adding a duplicate teamname
                    return false;
                }
            }

            return true;
        }
 protected override void UpdateTeam(TeamModel team)
 {
     ADBackend.Instance.Teams.AddOrUpdate(team);
 }
 private TeamDetailModel ConvertTeamModel(TeamModel model)
 {
     return model == null ? null : new TeamDetailModel
     {
         Name = model.Name,
         Description = model.Description,
         Members = model.Members,
         Repositories = RepositoryRepository.GetPermittedRepositories(null, new[] { model.Name }).Select(x => x.Name).ToArray(),
         IsReadOnly = MembershipService.IsReadOnly()
     };
 }
 protected override void UpdateTeam(TeamModel team)
 {
     _teams.Update(team);
 }
 public bool Create(TeamModel team)
 {
     throw new NotImplementedException();
 }
 private TeamEditModel ConvertEditTeamModel(TeamModel model)
 {
     return model == null ? null : new TeamEditModel
     {
         Id = model.Id,
         Name = model.Name,
         Description = model.Description,
         AllUsers = MembershipService.GetAllUsers().ToArray(),
         SelectedUsers = model.Members.ToArray(),
     };
 }
 private TeamModel CreateTeam()
 {
     EFTeamRepository teams = new EFTeamRepository { CreateContext = GetContext };
     var newTeam = new TeamModel { Name = "Team1" };
     teams.Create(newTeam);
     return newTeam;
 }
 protected override TeamModel CreateTeam()
 {
     var newTeam = new TeamModel { Name = "Team1" };
     _teams.Create(newTeam);
     return newTeam;
 }
Esempio n. 15
0
        private void UpdateTeams()
        {
            foreach (string team in Teams.Select(x => x.Name).Where(x => !ActiveDirectorySettings.TeamNameToGroupNameMapping.Keys.Contains(x, StringComparer.OrdinalIgnoreCase)))
            {
                Teams.Remove(team);
            }

            using (PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, ActiveDirectorySettings.DefaultDomain))
            {
                foreach (string teamName in ActiveDirectorySettings.TeamNameToGroupNameMapping.Keys)
                {
                    try
                    {
                        using (GroupPrincipal group = GroupPrincipal.FindByIdentity(principalContext, IdentityType.Name, ActiveDirectorySettings.TeamNameToGroupNameMapping[teamName]))
                        {
                            TeamModel teamModel = new TeamModel() { Description = group.Description, Name = teamName, Members = group.GetMembers(true).Select(x => x.UserPrincipalName).ToArray() };
                            if (teamModel != null)
                            {
                                Teams.AddOrUpdate(teamModel);
                            }
                        }
                    }
                    catch
                    {
                    }
                }
            }
        }
        public void TeamCanBeUpdatedToIncludeAUser()
        {
            var team1 = new TeamModel { Name = "Team1", Description = "Test Team" };
            CreateTeam(team1);

            var newUser = AddUserFred();

            _repo.UpdateUserTeams(newUser.Id, new List<string> { "Team1"});

            Assert.AreEqual(1, _repo.GetTeams(newUser.Id).Count);
            CollectionAssert.AreEqual(new[] { newUser.Id }, _repo.GetTeam(team1.Id).Members.Select(member => member.Id).ToArray());
        }
 protected override bool CreateTeam(TeamModel team)
 {
     return _repo.Create(team);
 }
Esempio n. 18
0
        private void UpdateTeams()
        {
            foreach (var team in Teams.Select(x => new { x.Id, Name = x.Name }).Where(x => !ActiveDirectorySettings.TeamNameToGroupNameMapping.Keys.Contains(x.Name, StringComparer.OrdinalIgnoreCase)))
            {
                Teams.Remove(team.Id);
            }

            if(MembershipService == null)
                MembershipService = new ADMembershipService();

            using (PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, ActiveDirectorySettings.DefaultDomain))
            {
                foreach (string teamName in ActiveDirectorySettings.TeamNameToGroupNameMapping.Keys)
                {
                    try
                    {
                        using (GroupPrincipal group = GroupPrincipal.FindByIdentity(principalContext, IdentityType.Name, ActiveDirectorySettings.TeamNameToGroupNameMapping[teamName]))
                        {
                            TeamModel teamModel = new TeamModel() {
                                Id = group.Guid.Value,
                                Description = group.Description,
                                Name = teamName,
                                Members = group.GetMembers(true).Select(x => MembershipService.GetUserModel(x.Guid.Value)).ToArray()
                            };
                            if (teamModel != null)
                            {
                                Teams.AddOrUpdate(teamModel);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        LogException(ex);
                    }
                }
            }
        }
        public void TeamCanBeUpdatedToChangeName()
        {
            var teamModel = new TeamModel { Name = "Team1", Description = "Test Team" };
            CreateTeam(teamModel);

            teamModel.Name = "SonOfTeam1";
            _repo.Update(teamModel);

            Assert.AreEqual("SonOfTeam1", _repo.GetAllTeams().Single().Name);
        }
 protected abstract void UpdateTeam(TeamModel team);
 protected override bool CreateTeam(TeamModel team)
 {
     team.Id = Guid.NewGuid();
     ADBackend.Instance.Teams.Add(team);
     return true;
 }
        public void Update(TeamModel model)
        {
            if (model == null) throw new ArgumentException("team");
            if (model.Name == null) throw new ArgumentException("name");

            using (var db = CreateContext())
            {
                var team = db.Teams.FirstOrDefault(i => i.Id == model.Id);
                if (team != null)
                {
                    team.Name = model.Name;
                    team.Description = model.Description;
                    team.Users.Clear();
                    if (model.Members != null)
                    {
                        AddMembers(model.Members.Select(x => x.Id), team, db);
                    }
                    db.SaveChanges();
                }
            }
        }
 private TeamDetailModel ConvertTeamModel(TeamModel model)
 {
     return model == null ? null : new TeamDetailModel
     {
         Name = model.Name,
         Description = model.Description,
         Members = model.Members,
         Repositories = model.Repositories,
     };
 }
 private void AddTeamToRepo(Guid repoId, TeamModel team)
 {
     UpdateRepo(repoId, repo => repo.Teams = new[] { team });
 }
 protected abstract bool CreateTeam(TeamModel team);
        public void Update(TeamModel model)
        {
            if (model == null) throw new ArgumentException("team");
            if (model.Name == null) throw new ArgumentException("name");

            using (var db = new DataEntities())
            {
                var team = db.Team.FirstOrDefault(i => i.Name == model.Name);
                if (team != null)
                {
                    team.Description = model.Description;
                    team.Members.Clear();
                    if (model.Members != null)
                    {
                        AddMembers(model.Members, team, db);
                    }
                    db.SaveChanges();
                }
            }
        }
 private TeamDetailModel ConvertDetailTeamModel(TeamModel model)
 {
     return model == null ? null : new TeamDetailModel
     {
         Id = model.Id,
         Name = model.Name,
         Description = model.Description,
         Members = model.Members.ToArray(),
         Repositories = RepositoryRepository.GetTeamRepositories(new[] { model.Id }).ToArray(),
         IsReadOnly = MembershipService.IsReadOnly()
     };
 }
 protected override TeamModel AddTeam()
 {
     var newTeam = new TeamModel { Name = "Team1"};
     ADBackend.Instance.Teams.Add(newTeam);
     return newTeam;
 }
 public void Update(TeamModel team)
 {
     throw new NotImplementedException();
 }