コード例 #1
0
        public bool Create(RepositoryModel model)
        {
            if (model == null) throw new ArgumentException("model");
            if (model.Name == null) throw new ArgumentException("name");

            using (var database = new BonoboGitServerContext())
            {
                var repository = new Repository
                {
                    Name = model.Name,
                    Logo = model.Logo,
                    Group = model.Group,
                    Description = model.Description,
                    Anonymous = model.AnonymousAccess,
                    AuditPushUser = model.AuditPushUser,
                };
                database.Repositories.Add(repository);
                AddMembers(model.Users, model.Administrators, model.Teams, repository, database);
                try
                {
                    database.SaveChanges();
                }
                catch (UpdateException)
                {
                    return false;
                }
            }

            return true;
        }
コード例 #2
0
        public bool CreateUser(string username, string password, string name, string surname, string email)
        {
            if (String.IsNullOrEmpty(username)) throw new ArgumentException("Value cannot be null or empty.", "userName");
            if (String.IsNullOrEmpty(password)) throw new ArgumentException("Value cannot be null or empty.", "password");
            if (String.IsNullOrEmpty(name)) throw new ArgumentException("Value cannot be null or empty.", "name");
            if (String.IsNullOrEmpty(surname)) throw new ArgumentException("Value cannot be null or empty.", "surname");
            if (String.IsNullOrEmpty(email)) throw new ArgumentException("Value cannot be null or empty.", "email");

            username = username.ToLowerInvariant();
            using (var database = new BonoboGitServerContext())
            {
                var user = new User
                {
                    Username = username,
                    Password = EncryptPassword(password),
                    Name = name,
                    Surname = surname,
                    Email = email,
                };
                database.Users.Add(user);
                try
                {
                    database.SaveChanges();
                }
                catch (UpdateException)
                {
                    return false;
                }
            }

            return true;
        }
コード例 #3
0
        public bool Create(TeamModel model)
        {
            if (model == null) throw new ArgumentException("team");
            if (model.Name == null) throw new ArgumentException("name");

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

            return true;
        }
コード例 #4
0
 public void DeleteUser(string username)
 {
     using (var database = new BonoboGitServerContext())
     {
         var user = database.Users.FirstOrDefault(i => i.Username == username);
         if (user != null)
         {
             user.AdministratedRepositories.Clear();
             user.Roles.Clear();
             user.Repositories.Clear();
             user.Teams.Clear();
             database.Users.Remove(user);
             database.SaveChanges();
         }
     }
 }
コード例 #5
0
        public void Delete(string name)
        {
            if (name == null) throw new ArgumentException("name");

            using (var db = new BonoboGitServerContext())
            {
                var team = db.Teams.FirstOrDefault(i => i.Name == name);
                if (team != null)
                {
                    team.Repositories.Clear();
                    team.Users.Clear();
                    db.Teams.Remove(team);
                    db.SaveChanges();
                }
            }
        }
コード例 #6
0
        public void Delete(string name)
        {
            if (name == null) throw new ArgumentException("name");

            using (var db = new BonoboGitServerContext())
            {
                var repo = db.Repositories.FirstOrDefault(i => i.Name == name);
                if (repo != null)
                {
                    repo.Administrators.Clear();
                    repo.Users.Clear();
                    repo.Teams.Clear();
                    db.Repositories.Remove(repo);
                    db.SaveChanges();
                }
            }
        }
コード例 #7
0
        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            using (var database = new BonoboGitServerContext())
            {
                var roles = database.Roles.Where(i => roleNames.Contains(i.Name));
                var users = database.Users.Where(i => usernames.Contains(i.Username));

                foreach (var role in roles)
                {
                    foreach (var user in users)
                    {
                        role.Users.Add(user);
                    }
                }

                database.SaveChanges();
            }
        }
コード例 #8
0
        public void Delete(string name)
        {
            if (name == null)
            {
                throw new ArgumentException("name");
            }

            using (var db = new BonoboGitServerContext())
            {
                var team = db.Teams.FirstOrDefault(i => i.Name == name);
                if (team != null)
                {
                    team.Repositories.Clear();
                    team.Users.Clear();
                    db.Teams.Remove(team);
                    db.SaveChanges();
                }
            }
        }
コード例 #9
0
        public void Delete(string name)
        {
            if (name == null)
            {
                throw new ArgumentException("name");
            }

            using (var db = new BonoboGitServerContext())
            {
                var repo = db.Repositories.FirstOrDefault(i => i.Name == name);
                if (repo != null)
                {
                    repo.Administrators.Clear();
                    repo.Users.Clear();
                    repo.Teams.Clear();
                    db.Repositories.Remove(repo);
                    db.SaveChanges();
                }
            }
        }
コード例 #10
0
        public void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            using (var database = new BonoboGitServerContext())
            {
                usernames = usernames.Select(i => i.ToLowerInvariant()).ToArray();

                var roles = database.Roles.Where(i => roleNames.Contains(i.Name)).ToList();
                var users = database.Users.Where(i => usernames.Contains(i.Username)).ToList();

                foreach (var role in roles)
                {
                    foreach (var user in users)
                    {
                        role.Users.Add(user);
                    }
                }

                database.SaveChanges();
            }
        }
コード例 #11
0
        public void Update(RepositoryModel model)
        {
            if (model == null)
            {
                throw new ArgumentException("model");
            }
            if (model.Name == null)
            {
                throw new ArgumentException("name");
            }

            using (var db = new BonoboGitServerContext())
            {
                var repo = db.Repositories.FirstOrDefault(i => i.Name == model.Name);
                if (repo != null)
                {
                    repo.Group         = model.Group;
                    repo.Description   = model.Description;
                    repo.Anonymous     = model.AnonymousAccess;
                    repo.AuditPushUser = model.AuditPushUser;

                    if (model.Logo != null)
                    {
                        repo.Logo = model.Logo;
                    }

                    if (model.RemoveLogo)
                    {
                        repo.Logo = null;
                    }

                    repo.Users.Clear();
                    repo.Teams.Clear();
                    repo.Administrators.Clear();

                    AddMembers(model.Users, model.Administrators, model.Teams, repo, db);

                    db.SaveChanges();
                }
            }
        }
コード例 #12
0
        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            using (var database = new BonoboGitServerContext())
            {
                var role = database.Roles.FirstOrDefault(i => i.Name == roleName);
                if (role != null)
                {
                    if (throwOnPopulatedRole)
                    {
                        if (role.Users.Count > 0)
                        {
                            throw new InvalidOperationException("Can't delete role with members.");
                        }
                    }

                    database.Roles.Remove(role);
                    database.SaveChanges();
                    return true;
                }

                return false;
            }
        }
コード例 #13
0
        public bool Create(RepositoryModel model)
        {
            if (model == null)
            {
                throw new ArgumentException("model");
            }
            if (model.Name == null)
            {
                throw new ArgumentException("name");
            }

            using (var database = new BonoboGitServerContext())
            {
                var repository = new Repository
                {
                    Name          = model.Name,
                    Logo          = model.Logo,
                    Group         = model.Group,
                    Description   = model.Description,
                    Anonymous     = model.AnonymousAccess,
                    AuditPushUser = model.AuditPushUser,
                };
                database.Repositories.Add(repository);
                AddMembers(model.Users, model.Administrators, model.Teams, repository, database);
                try
                {
                    database.SaveChanges();
                }
                catch (UpdateException)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #14
0
 public void UpdateUser(string username, string name, string surname, string email, string password)
 {
     using (var database = new BonoboGitServerContext())
     {
         username = username.ToLowerInvariant();
         var user = database.Users.FirstOrDefault(i => i.Username == username);
         if (user != null)
         {
             user.Name = name ?? user.Name;
             user.Surname = surname ?? user.Surname;
             user.Email = email ?? user.Email;
             user.Password = password != null ? EncryptPassword(password) : user.Password;
             database.SaveChanges();
         }
     }
 }
コード例 #15
0
        public void Update(RepositoryModel model)
        {
            if (model == null) throw new ArgumentException("model");
            if (model.Name == null) throw new ArgumentException("name");

            using (var db = new BonoboGitServerContext())
            {
                var repo = db.Repositories.FirstOrDefault(i => i.Name == model.Name);
                if (repo != null)
                {
                    repo.Group = model.Group;
                    repo.Description = model.Description;
                    repo.Anonymous = model.AnonymousAccess;
                    repo.AuditPushUser = model.AuditPushUser;

                    if (model.Logo != null)
                        repo.Logo = model.Logo;

                    if (model.RemoveLogo)
                        repo.Logo = null;

                    repo.Users.Clear();
                    repo.Teams.Clear();
                    repo.Administrators.Clear();

                    AddMembers(model.Users, model.Administrators, model.Teams, repo, db);

                    db.SaveChanges();
                }
            }
        }
コード例 #16
0
        public void UpdateUserTeams(string userName, List<string> newTeams)
        {
            if (string.IsNullOrEmpty(userName)) throw new ArgumentException("userName");
            if (newTeams == null) throw new ArgumentException("newTeams");

            using (var db = new BonoboGitServerContext())
            {
                var user = db.Users.FirstOrDefault(u => u.Username == userName.ToLower());
                if (user != null)
                {
                    user.Teams.Clear();
                    var teams = db.Teams.Where(t => newTeams.Contains(t.Name));
                    foreach (var team in teams)
                    {
                        user.Teams.Add(team);
                    }
                    db.SaveChanges();
                }
            }
        }
コード例 #17
0
        public void Update(TeamModel model)
        {
            if (model == null) throw new ArgumentException("team");
            if (model.Name == null) throw new ArgumentException("name");

            using (var db = new BonoboGitServerContext())
            {
                var team = db.Teams.FirstOrDefault(i => i.Name == model.Name);
                if (team != null)
                {
                    team.Description = model.Description;
                    team.Users.Clear();
                    if (model.Members != null)
                    {
                        AddMembers(model.Members, team, db);
                    }
                    db.SaveChanges();
                }
            }
        }