您的位置:首页 > 其它

一个简单的用户信息处理理组件

2009-06-17 09:53 316 查看
用户信息描述类



Code
using System;
using System.Collections.Generic;
using System.Text;
using Smark.Data;
namespace Component.Users
{
public class UserService
{
static object LOCK_ADD = new object();
public UserAccessState Add(User user)
{

lock (LOCK_ADD)
{
user.EntityState._Loaded = false;
user.Save();
return UserAccessState.处理成功;
}
}
public User GetByID(string userid)
{

return GetByExp(User.userID == userid);
}
public User GetByName(string username)
{
return GetByExp(User.userName == username);
}
public User GetByEMail(string email)
{
return GetByExp(User.eMail == email);
}
private User GetByExp(Expression exp)
{
return exp.ListFirst<User>();
}
public IList<User> List(string username, string email, Smark.Data.Region region,out int recordcount)
{
Expression exp = null;
if (!string.IsNullOrEmpty(username))
exp &= User.userName.Like(username + "%");
if (!string.IsNullOrEmpty(email))
exp &= User.eMail.Like(email + "%");
recordcount = exp.Count<User>();
return exp.List<User>(region);
}
public void Enabled(bool enabled, params string[] userid)
{
Expression exp = User.userID == userid;
exp.Edit<User>(
User.enabled.NewValue(enabled));
}
public User Login(string username, string pwd)
{
Expression exp = User.userName == username;
User user = exp.ListFirst<User>();
if (user == null)
return null;
if (user.SysPassWord.ToLower() == pwd.ToLower())
return user;
return null;
}
public UserAccessState ChangePwd(string username, string opwd, string npwd)
{
Expression exp = User.userName == username;
User user = exp.ListFirst<User>();
if (user == null)
return UserAccessState.用户名或密码不正确;
if (user.SysPassWord.ToLower() != opwd.ToLower())
return UserAccessState.用户名或密码不正确;
user.SysPassWord = npwd;
user.Save();

return UserAccessState.处理成功;
}
public void ChangePwd(string npwd,params string[] userid)
{
Expression exp = User.userID == userid;
exp.Edit<User>(
User.sysPassWord.NewValue(npwd));
}

}
public enum UserAccessState
{
处理成功,
用户名已经存,
邮件已经被其他用户使用,
用户名或密码不正确
}
public class UserServiceException : Exception
{
public UserServiceException() { }
public UserServiceException(string err) : base(err) { }
public UserServiceException(string err, Exception baseexc) : base(err, baseexc) { }
}
}

源码项目
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐