本文整理汇总了C#中Bonobo.Git.Server.Data.BonoboGitServerContext类的典型用法代码示例。如果您正苦于以下问题:C# BonoboGitServerContext类的具体用法?C# BonoboGitServerContext怎么用?C# BonoboGitServerContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BonoboGitServerContext类属于Bonobo.Git.Server.Data命名空间,在下文中一共展示了BonoboGitServerContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
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: GetAllRepositories
public IList<RepositoryModel> GetAllRepositories()
{
using (var db = new BonoboGitServerContext())
{
var dbrepos = db.Repositories.Select(repo => new
{
Name = repo.Name,
Group = repo.Group,
Description = repo.Description,
AnonymousAccess = repo.Anonymous,
Users = repo.Users.Select(i => i.Username),
Teams = repo.Teams.Select(i => i.Name),
Administrators = repo.Administrators.Select(i => i.Username),
AuditPushUser = repo.AuditPushUser,
Logo = repo.Logo
}).ToList();
return dbrepos.Select(repo => new RepositoryModel
{
Name = repo.Name,
Group = repo.Group,
Description = repo.Description,
AnonymousAccess = repo.AnonymousAccess,
Users = repo.Users.ToArray(),
Teams = repo.Teams.ToArray(),
Administrators = repo.Administrators.ToArray(),
AuditPushUser = repo.AuditPushUser,
Logo = repo.Logo
}).ToList();
}
}
示例3: Create
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: CreateUser
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;
}
示例5: GetAllRoles
public override string[] GetAllRoles()
{
using (var database = new BonoboGitServerContext())
{
return database.Roles.Select(i => i.Name).ToArray();
}
}
示例6: AllowsAnonymous
public bool AllowsAnonymous(string project)
{
using (var database = new BonoboGitServerContext())
{
var repo = database.Repositories.FirstOrDefault(i => i.Name == project);
return (repo != null && repo.Anonymous);
}
}
示例7: AllowsAnonymous
public bool AllowsAnonymous(string project)
{
using (var database = new BonoboGitServerContext())
{
var isAllowsAnonymous = database.Repositories.Any(repo => repo.Name == project && repo.Anonymous);
return isAllowsAnonymous;
}
}
示例8: GetRepository
public RepositoryModel GetRepository(string name)
{
if (name == null) throw new ArgumentException("name");
using (var db = new BonoboGitServerContext())
{
return ConvertToModel(db.Repositories.FirstOrDefault(i => i.Name == name));
}
}
示例9: CreateRole
public override void CreateRole(string roleName)
{
using (var database = new BonoboGitServerContext())
{
database.Roles.Add(new Role
{
Name = roleName,
});
}
}
示例10: FindUsersInRole
public override string[] FindUsersInRole(string roleName, string usernameToMatch)
{
using (var database = new BonoboGitServerContext())
{
var users = database.Users
.Where(us => us.Username.Contains(usernameToMatch) && us.Roles.Any(role => role.Name == roleName))
.Select(us => us.Username)
.ToArray();
return users;
}
}
示例11: GetAllRepositories
public IList<Models.RepositoryModel> GetAllRepositories()
{
using (var db = new BonoboGitServerContext())
{
var result = new List<RepositoryModel>();
foreach (var item in db.Repositories)
{
result.Add(ConvertToModel(item));
}
return result;
}
}
示例12: GetAllUsers
public IList<UserModel> GetAllUsers()
{
using (var db = new BonoboGitServerContext())
{
return db.Users.Include("Roles").ToList().Select(item => new UserModel
{
Username = item.Username,
Name = item.Name,
Surname = item.Surname,
Email = item.Email,
Roles = item.Roles.Select(i => i.Name).ToArray(),
}).ToList();
}
}
示例13: IsRepositoryAdministrator
public bool IsRepositoryAdministrator(string username, string project)
{
using (var database = new BonoboGitServerContext())
{
username = username.ToLowerInvariant();
var isRepoAdmin =
database.Users.Where(us => us.Username == username)
.Any(
us =>
(us.Roles.Any(role => role.Name == Definitions.Roles.Administrator) ||
us.AdministratedRepositories.Any(ar => ar.Name == project)));
return isRepoAdmin;
}
}
示例14: GetTeam
public TeamModel GetTeam(string name)
{
if (name == null) throw new ArgumentException("name");
using (var db = new BonoboGitServerContext())
{
var team = db.Teams.FirstOrDefault(i => i.Name == name);
return team == null ? null : new TeamModel
{
Name = team.Name,
Description = team.Description,
Members = team.Users.Select(m => m.Username).ToArray(),
};
}
}
示例15: Delete
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();
}
}
}