本文整理汇总了C#中User.AddRole方法的典型用法代码示例。如果您正苦于以下问题:C# User.AddRole方法的具体用法?C# User.AddRole怎么用?C# User.AddRole使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类User
的用法示例。
在下文中一共展示了User.AddRole方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryUpdateUser
private bool TryUpdateUser(User user, EditViewModel viewModel, bool canEditStatus, bool canEditRoles, bool canEditPassword)
{
if (!user.Username.Equals(viewModel.Username)) {
// verify that the new username is not in use
if (membershipService.UsernameIsInUse(viewModel.Username)) {
ModelState.AddModelErrorFor<EditViewModel>(m => m.Username, "The username is already in use");
return false;
}
user.Username = viewModel.Username;
}
if (!user.Email.Equals(viewModel.Email)) {
// verify that the new email is not in use
if (membershipService.EmailIsInUse(viewModel.Email)) {
ModelState.AddModelErrorFor<EditViewModel>(m => m.Email, "The email address is already in use");
return false;
}
user.Email = viewModel.Email;
}
user.FirstName = viewModel.FirstName;
user.LastName = viewModel.LastName;
if (canEditStatus) {
user.IsApproved = viewModel.IsApproved;
user.IsLocked = viewModel.IsLocked;
}
if (canEditRoles) {
user.RemoveAllRoles();
if (null != viewModel.Roles && viewModel.Roles.Length > 0) {
foreach (int roleId in viewModel.Roles) {
user.AddRole(repository.Get<Role>(roleId));
}
}
}
if (canEditPassword && null != viewModel.Password && !string.IsNullOrEmpty(viewModel.Password.Trim())) {
user.Password = membershipService.EncodePassword(viewModel.Password, user.PasswordSalt);
}
return true;
}
示例2: FindExact
public IJinxBotPrincipal FindExact(ChatUser user)
{
if (System.Diagnostics.Debugger.IsAttached)
System.Diagnostics.Debugger.Break();
string accountName, gateway;
Match m = m_separator.Match(user.Username);
if (!m.Success)
throw new InvalidDataException("Could not match the user's username into appropriate parts.");
accountName = m.Groups["accountName"].Value;
if (m.Groups["gateway"].Success)
gateway = m.Groups["gateway"].Value;
else
gateway = m_defaultGateway;
User dbUser = (from u in m_users
where u.AccountName.Equals(accountName, StringComparison.OrdinalIgnoreCase) &&
u.Gateway.Equals(gateway, StringComparison.OrdinalIgnoreCase)
select u).FirstOrDefault();
if (dbUser == null)
{
dbUser = new User(accountName, gateway, this);
foreach (Meta meta in m_metas)
{
if (meta.Matcher.IsMatch(accountName))
{
foreach (string role in meta.Roles)
dbUser.AddRole(role);
}
}
m_users.Add(dbUser);
}
return dbUser;
}
示例3: Given
public override void Given()
{
authenticationService.MockPrincipal.Roles = new string[1] { Roles.Officers };
var officer = new User("officer", "test", "test", "test", "test");
officer.SetIdTo(22);
officer.AddRole(officerRole);
authenticationService.MockPrincipal.User = officer;
user.AddRole(officerRole);
}
示例4: EstablishContext
public override void EstablishContext()
{
var repository = new Mock<IRepository>();
authService = AuthHelper.CreateMockAuthenticationService();
controller = new UpdateMatchController(repository.Object, authService);
loggedInUser = new User("admin", "pass", "first", "last", "email");
loggedInUser.SetIdTo(3);
loggedInUser.AddRole(new Role(Roles.Administrators));
authService.MockPrincipal.MockIdentity.IsAuthenticated = true;
authService.MockPrincipal.MockIdentity.Name = loggedInUser.Username;
var season = new Season("test", GameType.EightBall);
var division = new Division("test", DateTime.Parse("1/1/2011"), season);
season.AddDivision(division);
var team1 = new Team("team1", division);
division.AddTeam(team1);
player1 = new User("player1", "test", "player1", "test", "test");
player1.SetIdTo(1);
team1.AddPlayer(player1);
var team2 = new Team("team2", division);
division.AddTeam(team2);
player2 = new User("player2", "test", "player2", "test", "test");
player2.SetIdTo(2);
team2.AddPlayer(player2);
var meet = new Meet(team1, team2, 1);
division.Meets.Add(meet);
match = new Web.Models.Match(meet, new MatchPlayer(player1, team1), new MatchPlayer(player2, team2));
match.SetIdTo(1);
repository.Setup(r => r.Get<Web.Models.Match>(match.Id)).Returns(match);
repository.Setup(r => r.Get<User>(player1.Id)).Returns(player1);
repository.Setup(r => r.Get<User>(player2.Id)).Returns(player2);
var player1Results = new List<MatchResult>();
var player2Results = new List<MatchResult>();
for (int i = 0; i < 4; i++) {
var tempMatch = new Web.Models.Match(meet, new MatchPlayer(player1, team1), new MatchPlayer(player2, team2));
meet.AddMatch(tempMatch);
tempMatch.DatePlayed = DateTime.Parse("8/1/2010").AddDays(i);
tempMatch.IsComplete = true;
var matchResult = new MatchResult(player1, 30, 0, 3);
player1Results.Add(matchResult);
tempMatch.AddResult(matchResult);
matchResult = new MatchResult(player2, 30, 0, 3);
player2Results.Add(matchResult);
tempMatch.AddResult(matchResult);
}
repository.InitAll(new List<User> { player1, player2, loggedInUser }.AsQueryable(),
loggedInUser.Roles.AsQueryable(),
new List<Season> { season }.AsQueryable());
player1.UpdateSkillLevel(GameType.EightBall, repository.Object);
player1SkillLevel = player1.SkillLevels.Where(sl => sl.GameType == GameType.EightBall).First().Value;
player2.UpdateSkillLevel(GameType.EightBall, repository.Object);
player2SkillLevel = player2.SkillLevels.Where(sl => sl.GameType == GameType.EightBall).First().Value;
viewModel = new UpdateMatchViewModel() {
Id = match.Id,
IsForfeit = false,
Player1Id = player1.Id,
Player1Innings = 2,
Player1DefensiveShots = 1,
Player1Wins = 4,
Player2Id = player2.Id,
Player2Innings = 2,
Player2DefensiveShots = 1,
Player2Wins = 4,
Winner = player1.Id,
Date = "1/1/2011",
Time = "06:00 PM"
};
}