public bool AddUser(string userName, string pwd, string ChineseName, bool isLock, bool isAdmin, string loginPc, string memo) { using (AuthorizeEntities context = new AuthorizeEntities()) { try { var userAdd = new User(); userAdd.UserID = Guid.NewGuid(); userAdd.UserName = userName; userAdd.Pwd = pwd; userAdd.ChineseName = ChineseName; userAdd.IsLock = isLock; userAdd.IsAdmin = isAdmin; userAdd.LoginPC = loginPc; userAdd.Memo = memo; context.AddToUser(userAdd); context.SaveChanges(); return true; } catch (Exception e) { throw e; } } }
public bool ValidateUser(string userName, string password) { 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"); using (AuthorizeEntities context = new AuthorizeEntities()) { try { var adduser = new User(); adduser.UserID = Guid.NewGuid(); adduser.UserName = userName; adduser.Pwd = EncryptPassword(password); adduser.IsLock = false; adduser.IsAdmin = false; var user = context.User.FirstOrDefault(i => i.UserName == userName); if (user == null) { context.AddToUser(adduser); context.SaveChanges(); } return user != null && ComparePassword(password, user.Pwd); } catch (Exception e) { throw e; } } }
/// <summary> /// 用于向 User EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet<T> 属性的 .Add 方法。 /// </summary> public void AddToUser(User user) { base.AddObject("User", user); }
/// <summary> /// 创建新的 User 对象。 /// </summary> /// <param name="userID">UserID 属性的初始值。</param> /// <param name="userName">UserName 属性的初始值。</param> /// <param name="pwd">Pwd 属性的初始值。</param> /// <param name="isLock">IsLock 属性的初始值。</param> /// <param name="isAdmin">IsAdmin 属性的初始值。</param> public static User CreateUser(global::System.Guid userID, global::System.String userName, global::System.String pwd, global::System.Boolean isLock, global::System.Boolean isAdmin) { User user = new User(); user.UserID = userID; user.UserName = userName; user.Pwd = pwd; user.IsLock = isLock; user.IsAdmin = isAdmin; return user; }