本文整理汇总了C#中Bonobo.Git.Server.Data.BonoboGitServerContext.SaveChanges方法的典型用法代码示例。如果您正苦于以下问题:C# BonoboGitServerContext.SaveChanges方法的具体用法?C# BonoboGitServerContext.SaveChanges怎么用?C# BonoboGitServerContext.SaveChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bonobo.Git.Server.Data.BonoboGitServerContext
的用法示例。
在下文中一共展示了BonoboGitServerContext.SaveChanges方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例4: 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();
}
}
}
示例5: DeleteUser
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();
}
}
}
示例6: Delete
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: AddUsersToRoles
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: AddUsersToRoles
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();
}
}
示例9: DeleteRole
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;
}
}
示例10: UpdateUser
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();
}
}
}
示例11: Update
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: UpdateUserTeams
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();
}
}
}
示例13: Update
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();
}
}
}