You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							62 lines
						
					
					
						
							1.9 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							62 lines
						
					
					
						
							1.9 KiB
						
					
					
				| using System; | |
| using PetaPoco; | |
| using Pingchuan.BeijingSafeguard.Model; | |
| 
 | |
| namespace Pingchuan.BeijingSafeguard.DAL | |
| { | |
|     public class UserDAL : BaseDAL | |
|     { | |
|         public static User Get(string name, string password) | |
|         { | |
|             string sql = @"SELECT * FROM users WHERE login_name = @0 AND login_password = @1"; | |
| 
 | |
|             return db.SingleOrDefault<User>(sql, name, password); | |
|         } | |
| 
 | |
|         public static User Get(string realName) | |
|         { | |
|             string sql = @"SELECT id FROM users WHERE real_name = @0"; | |
| 
 | |
|             return db.SingleOrDefault<User>(sql, realName); | |
|         } | |
| 
 | |
|         public static int Add(User user) | |
|         { | |
|             object id = db.Insert(user); | |
|             return int.Parse(id.ToString()); | |
|         } | |
| 
 | |
|         public static int Update(User user) | |
|         { | |
|             return db.Update(user); | |
|         } | |
| 
 | |
|         public static int UpdatePassword(int id, string newPassword) | |
|         { | |
|             string sql = $@"update users set login_password = @0 where id = @1"; | |
|             return db.Execute(sql, newPassword, id); | |
|         } | |
| 
 | |
|         public static int Delete(int id) | |
|         { | |
|             return db.Delete<User>(id); | |
|         } | |
| 
 | |
|         public static int Enable(int id, int enable) | |
|         { | |
|             string sql = $@"update users set enable = {enable} where id = {id}"; | |
|             return db.Execute(sql); | |
|         } | |
| 
 | |
|         public static Pagination<UserDTO> Query(int orgId, int pageIndex, int pageSize) | |
|         { | |
|             string condition = orgId == 0 ? string.Empty : $"and u.org_id = {orgId}"; | |
|             string sql = $@"select u.*, o.name org_name from users u  | |
|                             left join orgs o on o.id = u.org_id  | |
|                             where is_sa <> 1 {condition}  | |
|                             order by u.create_time desc"; | |
|             Page<UserDTO> users = db.Page<UserDTO>(pageIndex, pageSize, sql); | |
|             return Pagination<UserDTO>.FromPage(users); | |
|         } | |
|     } | |
| } |