예제 #1
0
 public bool CheckLogin(string username, string password)
 {
     using (MyDbContent ctx = new MyDbContent())
     {
         User user = ctx.Users.SingleOrDefault(u => u.UserName == username);
         if (user == null)
         {
             return(false);
         }
         return(user.UserPass == MD5Helper.Md5(password));
     }
 }
예제 #2
0
 public UserDTO GetUserName(string username)
 {
     using (MyDbContent ctx = new MyDbContent())
     {
         User user = ctx.Users.SingleOrDefault(u => u.UserName == username);
         if (user == null)
         {
             return(null);
         }
         return(ToDTO(user));
     }
 }
예제 #3
0
 public void AddNew(string username, string password)
 {
     using (MyDbContent ctx = new MyDbContent())
     {
         if (ctx.Users.Any(u => u.UserName == username))
         {
             throw new ApplicationException("账号已存在");
         }
         User user = new User();
         user.UserName  = username;
         user.UserPass  = MD5Helper.Md5(password);
         user.IsDeleted = false;
         ctx.Add(user);
         ctx.SaveChanges();
     }
 }