示例#1
0
文件: DBRepo.cs 项目: hsloki/HG
 public static List<UserRole> GetRolesOfUser(int UserID)
 {
     UsersDBEntities db = new UsersDBEntities();
     List<int> roleIDs = (List<int>)(from urMap in db.UsersRolesMappings
                             where urMap.UserID == UserID
                         select urMap.UserRoleID);
     //List<UserRole> allRoles = (from roles in db.UserRoles
     //                           where roles.UserRoleID == roleIDs
     //                           select roles).ToList<UserRole>();
     return new List<UserRole>();
 }
示例#2
0
文件: DBRepo.cs 项目: hsloki/HG
 public static int AddUserRole(UserRole role)
 {
     try
     {
         UsersDBEntities db = new UsersDBEntities();
         db.UserRoles.Add(role);
         return db.SaveChanges();
     }
     catch (Exception ex)
     {
         return -2;
     }
 }
示例#3
0
文件: DBRepo.cs 项目: hsloki/HG
 public static int AddUser(User user)
 {
     try
     {
         UsersDBEntities db = new UsersDBEntities();
         db.Users.Add(user);
         return db.SaveChanges();
     }
     catch (Exception ex)
     {
         return -2;
     }
 }
示例#4
0
文件: DBRepo.cs 项目: hsloki/HG
 public static User GetUserByID(int UserID)
 {
     try
     {
         UsersDBEntities db = new UsersDBEntities();
         var u = (from user in db.Users
                  where user.UserID == UserID
                  select user);
         return (User)u;
     }
     catch (Exception ex)
     {
         return null;
     }
 }
示例#5
0
文件: DBRepo.cs 项目: hsloki/HG
 public static int AssignRoleToUser(int UserID, int RoleID)
 {
     try
     {
         UsersDBEntities db = new UsersDBEntities();
         UsersRolesMapping mapTableObj = new UsersRolesMapping()
         {
             UserID = UserID,
             UserRoleID = RoleID,
         };
         db.UsersRolesMappings.Add(mapTableObj);
         return db.SaveChanges();
     }
     catch (Exception ex)
     {
         return -2;
     }
 }
示例#6
0
文件: DBRepo.cs 项目: hsloki/HG
 public static int DeleteRole(int id)
 {
     try
     {
         using (UsersDBEntities db = new UsersDBEntities())
         {
             UserRole r = db.UserRoles.Single(role => role.UserRoleID == id);
             if (r != null)
             {
                 db.UserRoles.Remove(r);
                 return db.SaveChanges();
             }
             else
                 return 0;
         }
     }
     catch (Exception ex)
     {
         return -2;
     }
 }
示例#7
0
文件: DBRepo.cs 项目: hsloki/HG
 public static User UserUserByUserName(string  UserName)
 {
     try
     {
         UsersDBEntities db = new UsersDBEntities();
         var u = (from user in db.Users
                  where user.UserName == UserName
                  select user);
         return (User)u;
     }
     catch (Exception ex)
     {
         return null;
     }
 }
示例#8
0
文件: DBRepo.cs 项目: hsloki/HG
 public static int UpdateUser(User UpdatedUser)
 {
     UsersDBEntities db = new UsersDBEntities();
     User u = (User)(from user in db.Users
              where user.UserID == UpdatedUser.UserID
              select user);
     if (u != null)
     {
         u.FirstName = UpdatedUser.FirstName;
         u.LastName = UpdatedUser.LastName;
         u.Password = UpdatedUser.Password;
         u.UserName = UpdatedUser.UserName;
         u.EmailAddress = UpdatedUser.EmailAddress;
         return db.SaveChanges();
     }
     else
         return 0;
 }
示例#9
0
文件: DBRepo.cs 项目: hsloki/HG
 public static List<User> GetAllUsers()
 {
     using (UsersDBEntities db = new UsersDBEntities())
     {
         return (from users in db.Users
                 select users).ToList<User>();
     }
 }
示例#10
0
文件: DBRepo.cs 项目: hsloki/HG
 public static int UpdateUser(User UpdatedUser)
 {
     using (UsersDBEntities db = new UsersDBEntities())
     {
         User u = db.Users.Single(user => user.UserID == UpdatedUser.UserID);
         if (u != null)
         {
             u.FirstName = UpdatedUser.FirstName;
             u.LastName = UpdatedUser.LastName;
             u.Password = UpdatedUser.Password;
             u.UserName = UpdatedUser.UserName;
             u.EmailAddress = UpdatedUser.EmailAddress;
             return db.SaveChanges();
         }
         else
             return 0;
     }
 }
示例#11
0
文件: DBRepo.cs 项目: hsloki/HG
 public static int UpdateRole(UserRole UpdatedRole)
 {
     using (UsersDBEntities db = new UsersDBEntities())
     {
         UserRole r = db.UserRoles.Single(role => role.UserRoleID == UpdatedRole.UserRoleID);
         if (r != null)
         {
             r.UserRoleName = UpdatedRole.UserRoleName;
             r.UserRoleDescription = UpdatedRole.UserRoleDescription;
             return db.SaveChanges();
         }
         else
             return 0;
     }
 }
示例#12
0
文件: DBRepo.cs 项目: hsloki/HG
 public static UserRole GetUserRole(int id)
 {
     try
     {
         using (UsersDBEntities db = new UsersDBEntities())
         {
             UserRole role = db.UserRoles.Single(r => r.UserRoleID == id);
             //var u = (from user in db.Users
             //         where user.UserID == UserID
             //         select user);
             return role;
         }
     }
     catch (Exception ex)
     {
         return null;
     }
 }
示例#13
0
文件: DBRepo.cs 项目: hsloki/HG
 public static User GetUserByID(int UserID)
 {
     try
     {
         using (UsersDBEntities db = new UsersDBEntities())
         {
             User u = db.Users.Single(user => user.UserID == UserID);
             //var u = (from user in db.Users
             //         where user.UserID == UserID
             //         select user);
             return u;
         }
     }
     catch (Exception ex)
     {
         return null;
     }
 }
示例#14
0
文件: DBRepo.cs 项目: hsloki/HG
        public static List<UserRole> GetRolesOfUser(int UserID)
        {
            using (UsersDBEntities db = new UsersDBEntities())
            {
                //List<int> roleIDs = (from urMap in db.UsersRolesMappings
                //                     where urMap.UserID == UserID
                //                     select urMap.UserRoleID).ToList<int>();

                List<UserRole> listofRoles = (from rmap in db.UsersRolesMappings
                                   join usr in db.Users on rmap.UserID equals usr.UserID
                                   join rol in db.UserRoles on rmap.UserRoleID equals rol.UserRoleID

                                   where usr.UserID == UserID
                                   select rol
                                    ).ToList<UserRole>();

                return listofRoles;
            }
        }
示例#15
0
文件: DBRepo.cs 项目: hsloki/HG
 public static List<User> GetAllUsers()
 {
     UsersDBEntities db = new UsersDBEntities();
     return (List<User>)(from users in db.Users
                         select users);
 }
示例#16
0
文件: DBRepo.cs 项目: hsloki/HG
 public static int DeleteUser(int id)
 {
     try
     {
         using (UsersDBEntities db = new UsersDBEntities())
         {
             User u = db.Users.Single(user => user.UserID == id);
             if (u != null)
             {
                 db.Users.Remove(u);
                 return db.SaveChanges();
             }
             else
                 return 0;
         }
     }
     catch (Exception ex)
     {
         return -2;
     }
 }
示例#17
0
文件: DBRepo.cs 项目: hsloki/HG
 public static int UpdateRole(UserRole UpdatedRole)
 {
     UsersDBEntities db = new UsersDBEntities();
     UserRole r = (UserRole)(from user in db.Users
                     where user.UserID == UpdatedRole.UserRoleID
                     select user);
     if (r != null)
     {
         r.UserRoleName = UpdatedRole.UserRoleName;
         r.UserRoleDescription = UpdatedRole.UserRoleDescription;
         return db.SaveChanges();
     }
     else
         return 0;
 }
示例#18
0
文件: DBRepo.cs 项目: hsloki/HG
 public static int RemoveRoleFromUser(int UserID, int RoleID)
 {
     try
     {
         UsersDBEntities db = new UsersDBEntities();
         if (db.UsersRolesMappings.Any(m => m.UserID == UserID & m.UserRoleID == RoleID))
         {
             UsersRolesMapping mapObj = db.UsersRolesMappings.Single(m => m.UserID == UserID & m.UserRoleID == RoleID);
             db.UsersRolesMappings.Remove(mapObj);
             return db.SaveChanges();
         }
         else
             return 0;
     }
     catch (Exception ex)
     {
         return -2;
     }
 }
示例#19
0
文件: DBRepo.cs 项目: hsloki/HG
 public static List<UserRole> GetAllRoles()
 {
     using (UsersDBEntities db = new UsersDBEntities())
     {
         return (from roles in db.UserRoles
                 select roles).ToList<UserRole>();
     }
 }