本文整理汇总了C#中UserService.Save方法的典型用法代码示例。如果您正苦于以下问题:C# UserService.Save方法的具体用法?C# UserService.Save怎么用?C# UserService.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserService
的用法示例。
在下文中一共展示了UserService.Save方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
/// <summary>
/// Job that updates the JobPulse setting with the current date/time.
/// This will allow us to notify an admin if the jobs stop running.
///
/// Called by the <see cref="IScheduler" /> when a
/// <see cref="ITrigger" /> fires that is associated with
/// the <see cref="IJob" />.
/// </summary>
public virtual void Execute(IJobExecutionContext context)
{
// get the job map
JobDataMap dataMap = context.JobDetail.JobDataMap;
// delete accounts that have not been confirmed in X hours
int userExpireHours = Int32.Parse( dataMap.GetString( "HoursKeepUnconfirmedAccounts" ) );
DateTime userAccountExpireDate = DateTime.Now.Add( new TimeSpan( userExpireHours * -1,0,0 ) );
UserService userService = new UserService();
foreach (var user in userService.Queryable().Where(u => u.IsConfirmed == false && u.CreationDate < userAccountExpireDate))
{
userService.Delete( user, null );
}
userService.Save( null, null );
// purge exception log
int exceptionExpireDays = Int32.Parse( dataMap.GetString( "DaysKeepExceptions" ) );
DateTime exceptionExpireDate = DateTime.Now.Add( new TimeSpan( userExpireHours * -1, 0, 0 ) );
ExceptionLogService exceptionLogService = new ExceptionLogService();
foreach ( var exception in exceptionLogService.Queryable().Where( e => e.ExceptionDate < exceptionExpireDate ) )
{
exceptionLogService.Delete( exception, null );
}
exceptionLogService.Save( null, null );
}
示例2: ToggleFavorite
public ActionResult ToggleFavorite(int id)
{
var userService = new UserService();
var snippet = _snippetService.GetById(id);
var user = userService.GetByUsername(User.Identity.Name);
var favorite = user.Favorites.SingleOrDefault(s => s.Snippet.SnippetId == snippet.SnippetId);
if (favorite != null) {
snippet.Favorited--;
user.Favorites.Remove(favorite);
}
else {
snippet.Favorited++;
user.Favorites.Add(new Favorite {
DateCreated = DateTime.Now,
Snippet = snippet,
User = user
});
}
userService.Save();
if (Request.IsAjaxRequest())
return Json(new {success = true });
return Redirect(snippet.Link);
}
示例3: SaveNewUser_UserSaved
public void SaveNewUser_UserSaved()
{
Bootstrap.Initilize();
using (var unitOfWork = Factory.Current.Create<IUnitOfWork>())
{
var userRepository = new MemoryRepository<User>(unitOfWork);
var service = new UserService(userRepository);
var user = new User
{
Name = "some.user",
FullName = "Some user",
Email = "[email protected]",
Password = "mypassword"
};
service.Save(user);
unitOfWork.Commit();
Assert.IsFalse(user.IsTransient);
}
}
示例4: Authenticate
/// <summary>
/// Authenticates the specified user name.
/// </summary>
/// <param name="user">The user.</param>
/// <param name="password">The password.</param>
/// <returns></returns>
public override Boolean Authenticate( User user, string password )
{
byte[] bytes = ConvertToByteArray( user.Password );
string encodedPassword = EncodePassword( user, password );
bool valid = encodedPassword == Convert.ToBase64String( bytes );
bool convert = false;
if ( valid && Boolean.TryParse( AttributeValue( "ConvertToDatabaseLogin" ), out convert ) && convert )
{
// Convert to database type
var service = new UserService();
var rockUser = service.GetByUserName( user.UserName );
if ( rockUser != null )
{
rockUser.Password = DatabaseEncodePassword( password );
rockUser.ServiceName = "Rock.Security.Authentication.Database";
service.Save( rockUser, null );
}
}
return valid;
}
示例5: LoginWithTwitter
public User LoginWithTwitter(string userName, string token, string tokenSecret)
{
// check to see if we already have the screen name in the userauth table.
var userAuthService = new UserAuthenticationProfileService();
var userAuth = userAuthService.UserAuthorizationByServiceScreenNameAndPlatform(userName, "Mobile", AuthenticationServices.TWITTER);
//Yes, there is a Mobile Auth record
if (userAuth != null)
{
userAuth.Token = token;
userAuth.TokenSecret = tokenSecret;
userAuthService.Save(userAuth);
var user = userAuth.Users.FirstOrDefault();
if (user != null)
{
return user;
}
}
else
{
//There is no auth record, this must be a login from Twitter or a new twitter connection to an existing user or an existing mobile user with no Mobile account.
//Before we create a new user, make sure there isn't a Web token.
userAuth = userAuthService.UserAuthorizationByServiceScreenNameAndPlatform(userName, "Web", AuthenticationServices.TWITTER);
if (userAuth == null)
{
//This is a new user, create an account.
var us = new UserService();
//This is a new login, create the user
var theNewUser = new User()
{
CreatedDate = DateTime.UtcNow,
IsActive = true,
RoleID = 2,
Username = userName + "twitter",
Password = " ",
EmailAddress = " "
};
us.Save(theNewUser);
userAuth = new UserAuthenticationProfile
{
UserID = theNewUser.ID,
Platform = "Mobile",
Service = AuthenticationServices.TWITTER.ToString(),
ServiceUsername = userName,
Token = token,
TokenSecret = tokenSecret
};
userAuthService.Save(userAuth);
return theNewUser;
}
//They have an account already, it was create on Web. Now add the Mobile token.
var userAuth2 = new UserAuthenticationProfile
{
UserID = userAuth.UserID,
Platform = "Mobile",
Service = AuthenticationServices.TWITTER.ToString(),
ServiceUsername = userName,
Token = token,
TokenSecret = tokenSecret
};
userAuthService.Save(userAuth2);
var user = userAuth.Users.FirstOrDefault();
return user;
}
return null;
}
示例6: Register
public void Register(HttpContext context)
{
ZwJson zwJson=new ZwJson();
ISession session = SessionFactory.GetCurrentSession();
UserService user = new UserService(session);
context.Session["UserName"] = context.Request.Params["username"];
user.Save(new User() {
Id = Guid.NewGuid().ToString(),
CreateDt = DateTime.Now,
Name = context.Request.Params["username"],
Password = context.Request.Params["pass"],
Sex = context.Request.Params["sex"],
BriefIntroduction = context.Request.Params["introduction"]
});
zwJson.IsSuccess = true;
zwJson.JsExecuteMethod = "ajax_SaveUser";
context.Response.Write(_jss.Serialize(zwJson));
}