本文整理汇总了C#中IUserRepository.Add方法的典型用法代码示例。如果您正苦于以下问题:C# IUserRepository.Add方法的具体用法?C# IUserRepository.Add怎么用?C# IUserRepository.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IUserRepository
的用法示例。
在下文中一共展示了IUserRepository.Add方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddAdminUserIfNoUserFound
private static void AddAdminUserIfNoUserFound(IUserRepository userRepository)
{
if (!userRepository.HasAdminUser)
{
userRepository.Add(new User { Name = "spiel", Password = "gamer", IsAdmin = true });
}
}
示例2: CreateInitialData
protected override void CreateInitialData()
{
_userRepository = Locator.GetService<IUserRepository>();
var passwordSalt = PasswordMethods.CreateSalt();
var users = new[]
{
new User
{
Login = "Test1",
Email = "[email protected]",
CreatedDate = DateTime.Now,
PasswordSalt = passwordSalt,
Password = PasswordMethods.CreatePasswordHash("testtest", passwordSalt),
IsActivated = true,
IsLockedOut = false,
LastLockedOutDate = null,
LastLoginDate = null,
},
new User
{
Login = "Test2",
Email = "[email protected]",
CreatedDate = DateTime.Now,
PasswordSalt = passwordSalt,
Password = PasswordMethods.CreatePasswordHash("testtest", passwordSalt),
IsActivated = true,
IsLockedOut = false,
LastLockedOutDate = null,
LastLoginDate = null,
}
};
foreach (var obj in users)
{
_userRepository.Add(obj);
}
_roleRepository = Locator.GetService<IRoleRepository>();
var roles = new[]
{
new Role
{
RoleName = "admin"
},
new Role
{
RoleName = "user"
}
};
foreach (var obj in roles)
{
_roleRepository.Add(obj);
}
}
示例3: AddUserAndCopyAccess
public static void AddUserAndCopyAccess(IUserRepository userRepository, INetworkRepository networkRepository, INetworkGuestRepository networkGuestRepository, string username, string password, string referenceUsername)
{
var user = User.Create(string.Join(":", "internal", username));
user.Secret = Web.Persistence.Helpers.Secrets.BCryptSecret.FromPassword(password);
userRepository.Add(user);
var referenceUser = userRepository.Get(string.Join(":", "internal", referenceUsername));
var networks = networkRepository.Get(referenceUser);
foreach (var network in networks)
{
networkGuestRepository.Add(network, user);
}
}
示例4: AdminModule
//.........这里部分代码省略.........
var client = new WebClient();
var suggestions = GetSuggestions(client, Request.Form.channel, Request.Form.forumid, Request.Form.apikey, Request.Form.trusted);
foreach (var s in suggestions)
{
string title = s.title;
//If the idea exists, skip it
if (ideas.FindBy(i => i.Title == title).Any())
continue;
string date = s.created_at;
var idea = new Idea
{
Title = title,
Description = s.text,
Time = DateTime.Parse(date.Substring(0, date.Length - 5)),
};
string status = string.Empty;
switch ((string)s.state)
{
case "approved":
status = "Active";
break;
case "closed" :
if (s.status.key == "completed")
status = "Completed";
else
status = "Declined";
break;
default:
status = "New";
break;
}
idea.Status = status;
//Get the author, or create
string name = s.creator.name;
var existing = users.FindBy(u => u.UserName == name).FirstOrDefault();
if (existing != null)
idea.Author = existing;
else
{
idea.Author = NewUser(s.creator);
users.Add(idea.Author);
}
ideas.Add(idea);
//Process all comments
var comments = GetComments(client, (string)s.id, Request.Form.channel, Request.Form.forumid, Request.Form.apikey, Request.Form.trusted);
List<Activity> ideaComments = new List<Activity>();
foreach (var c in comments)
{
string commentdate = c.created_at;
var comment = new Comment
{
Time = DateTime.Parse(commentdate),
Text = c.text
};
string commentname = c.creator.name;
existing = users.FindBy(u => u.UserName == commentname).FirstOrDefault();
if (existing != null)
comment.User = existing;
else
{
comment.User = NewUser(c.creator);
users.Add(comment.User);
}
activities.Add(idea.Id, comment);
}
//Process all votes
var votes = GetVotes(client, (string)s.id, Request.Form.channel, Request.Form.forumid, Request.Form.apikey, Request.Form.trusted);
foreach (var v in votes)
{
string votername = v.user.name;
string votesfor = v.votes_for;
int vote;
if (Int32.TryParse(votesfor, out vote))
{
existing = users.FindBy(u => u.UserName == votername).FirstOrDefault();
if (existing != null)
ideas.Vote(idea.Id, existing.Id, vote);
else
{
var author = NewUser(v.user);
users.Add(author);
ideas.Vote(idea.Id, author.Id, vote);
}
}
}
}
return Response.AsRedirect("/admin");
};
}
示例5: LoginModule
public LoginModule(IUserRepository userRepository)
{
_user = userRepository;
Post["/login/token"] = x =>
{
if (string.IsNullOrWhiteSpace(Request.Form.token))
return
View["Login/Error",
new
{
Title = "Login Error",
Message = "Bad response from login provider - could not find login token."
}];
var response = new WebClient().DownloadString(string.Format("https://rpxnow.com/api/v2/auth_info?apiKey={0}&token={1}",apikey, Request.Form.token));
if (string.IsNullOrWhiteSpace(response))
return
View["Login/Error",
new
{
Title = "Login Error",
Message = "Bad response from login provider - could not find user."
}];
var j = JsonConvert.DeserializeObject<dynamic>(response);
if (j.stat.ToString() != "ok")
return
View["Login/Error",
new
{
Title = "Login Error",
Message = "Bad response from login provider."
}];
var userIdentity = j.profile.identifier.ToString();
var username = j.profile.preferredUsername.ToString();
string email = string.Empty;
if (j.profile.email != null)
email = j.profile.email.ToString();
var user = _user.GetUserFromUserIdentity(userIdentity);
if (user == null)
{
var u = new User
{
Id = Guid.NewGuid(),
Identity = userIdentity,
UserName = (!string.IsNullOrEmpty(username)) ? username : "New User " + _user.GetAll().Count(),
Email = (!string.IsNullOrEmpty(email)) ? email : "[email protected]",
Github = (!string.IsNullOrEmpty(username)) ? username : "",
IsActive = true,
};
if (!_user.GetAll().Any())
_user.AddRole(u, "Admin");
if (j.profile.photo != null)
u.AvatarUrl = j.profile.photo.ToString();
_user.Add(u);
return this.LoginAndRedirect(u.Id, DateTime.Now.AddDays(1), "/profile/edit");
}
return ModuleExtensions.Login(this, user.Id, DateTime.Now.AddDays(1), "/");
};
Get["/logout/"] = parameters => this.LogoutAndRedirect("/");
}
示例6: ArrangeModelsForTest
private void ArrangeModelsForTest()
{
userRepository = new FakeUserRepository();
userProfileRepository = new FakeUserProfileRepository();
userProfile.Email = EMAIL;
userProfileRepository.Add(userProfile);
userProfileRepository.Save();
user = EntityHelpers.GetValidUser();
user.Username = EMAIL;
user.Password = GrassrootsMembershipService.HashPassword(PASSWORD, null);
user.UserProfile = userProfile;
userRepository.Add(user);
userRepository.Save();
}
示例7: Init
public void Init()
{
var serviceLocator = new RepositoryServiceLocator();
_postRepository = serviceLocator.Locate<IPostRepository>();
_userRepository = serviceLocator.Locate<IUserRepository>();
_blogRepository = serviceLocator.Locate<IBlogRepository>();
// add the needed user
_neededUser = new User
{
DisplayName = "Galilyou",
Email = "[email protected]",
Url = "http://galilyou.blogspot.com",
SignUpDate = DateTime.Now
};
_userRepository.Add(_neededUser);
// add the needed blog
_neededBlog = new Blog {Name = "Programming for Cowards", Author = _neededUser, CreatedDate = DateTime.Now, LastModifiedDate = DateTime.Now};
_blogRepository.Add(_neededBlog);
}