public List <LoginUser> GetAllLoginUsers() { using (DBService dbservice = new BLL.DBService()) { using (DataTable dt = new DataTable()) { SessionService ss = new BLL.SessionService(); string selectQuery = ""; if (ss.CurrentUser.ProfileName == "IT administrator") { selectQuery = @"SELECT L.* , d.DeptName,p.ProfileName FROM ((LoginUser L inner join Department d on L.DeptID=d.ID) inner join UserProfile p on L.UserProfileId=p.ID);"; } else { selectQuery = @"SELECT L.* , d.DeptName,p.ProfileName FROM ((LoginUser L inner join Department d on L.DeptID=d.ID) inner join UserProfile p on L.UserProfileId=p.ID ) where p.ProfileName <> 'IT administrator';"; } // // // selects all content from table and adds it to datatable binded to datagridview using (OleDbDataAdapter adapter = new OleDbDataAdapter(selectQuery, dbservice.conn)) { adapter.Fill(dt); } List <LoginUser> lstLoginUsers = null; if (dt != null) { lstLoginUsers = new List <LoginUser>(); foreach (DataRow dr in dt.Rows) { LoginUser usr = new LoginUser(); usr.DeptId = dr["DeptID"] != null?Convert.ToInt32(dr["DeptID"]) : -1; usr.DeptName = dr["DeptName"].ToString(); usr.UserCode = dr["UserCode"].ToString(); usr.UserProfileId = dr["UserProfileId"] != null?Convert.ToInt32(dr["UserProfileId"]) : -1; usr.ProfileName = dr["ProfileName"].ToString(); usr.Id = dr["ID"] != null?Convert.ToInt32(dr["ID"]) : -1; usr.Password = dr["Password"].ToString(); lstLoginUsers.Add(usr); } } return(lstLoginUsers); } } }
public List <LoginUser> GetAllLoginUsers() { using (AppContext ctx = new AppContext()) { SessionService ss = new BLL.SessionService(); if (ss.CurrentUser.Profile.ProfileName == "IT administrator") { return(ctx.LoginUsers.Include(a => a.Department).Include(a => a.Profile).ToList()); } else { var ret = ctx.LoginUsers.Include(a => a.Department).Include(a => a.Profile).Where(a => a.Profile.ProfileName != "IT administrator").ToList(); return(ret); } } }