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; }
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"); 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; }
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, Description = model.Description, Anonymous = model.AnonymousAccess, }; database.Repositories.Add(repository); AddMembers(model.Users, model.Administrators, model.Teams, repository, database); try { database.SaveChanges(); } catch (UpdateException) { return false; } } return true; }
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(); } } }
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(); } } }
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(); } } }
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(); } }
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(); } }
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); } }
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; } }
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(); } } }
public void UpdateUser(string username, string name, string surname, string email, string password) { using (var database = new BonoboGitServerContext()) { 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(); } } }
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.Description = model.Description; repo.Anonymous = model.AnonymousAccess; repo.Users.Clear(); repo.Teams.Clear(); repo.Administrators.Clear(); AddMembers(model.Users, model.Administrators, model.Teams, repo, db); db.SaveChanges(); } } }