Ejemplo n.º 1
0
 public void SignUP(string Account, string Password)
 {
     try
     {
         using (var db = new AccountContext())
         {
             var u = db.SysUsers.Where(a => a.UserAccount.Equals(Account)).FirstOrDefault();  //查账户
             if (u != null)
             {
                 throw new Exception("用户名已存在!");
             }
             else
             {
                 db.SysUsers.Add(new SysUser {
                     UserAccount = Account, UserPassword = Password
                 });                                                                               //增加新账户
                 db.SaveChanges();
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public SysUser GetUser(string Account, string Password)
 {
     try
     {
         using (var db = new AccountContext())                                                                                  //数据库上下文联动
         {
             var u = db.SysUsers.Where(a => a.UserAccount.Equals(Account) && a.UserPassword.Equals(Password)).FirstOrDefault(); //判断账户密码是否相等,取相等的,否则返回空值
             return(u);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 3
0
 public void Change(string Account, string OldPassword, string Password)
 {
     try
     {
         using (var db = new AccountContext())
         {
             var u = db.SysUsers.Where(a => a.UserAccount.Equals(Account) && a.UserPassword.Equals(OldPassword)).FirstOrDefault();  //查此账号
             if (u == null)
             {
                 throw new Exception("用户名或密码错误!");
             }
             else
             {
                 u.UserAccount  = Account;
                 u.UserPassword = Password;
                 db.SaveChanges();        //修改
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }