コード例 #1
0
        // GET api/<controller>
        public List<UserRole> Get()
        {
            UserRoleManager roleManager = new UserRoleManager();
            int roleId  =roleManager.GetRoleID();

            //string query = "select * from roles;";
            //DataSet aDataSet = aGateway.Select(query);
            //List<UserRole> userRoles = new List<UserRole>();
            //foreach (DataRow dataRow in aDataSet.Tables[0].Rows)
            //{
            //    UserRole aUserRole = new UserRole();
            //    aUserRole.Id = Convert.ToInt32(dataRow["ID"].ToString());
            //    aUserRole.RoleName = dataRow["RoleName"].ToString();
            //    aUserRole.ParentRoleName = dataRow["ParentRoleName"].ToString();
            //    userRoles.Add(aUserRole);
            //}

            List<UserRole> userRolesFinal = roleManager.GetRoleLevels(roleId);

            return userRolesFinal;
        }
コード例 #2
0
        // [ApiAuthorize]
        // GET api/customers
        public PagedResult<UserInfo> Get(int pageNo = 1, int pageSize = 50, [FromUri] string[] sort = null, string search = null)
        {
            TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;
            // search = textInfo.ToTitleCase(search);
            // Determine the number of records to skip
            int skip = (pageNo - 1) * pageSize;
            UserRoleManager aRoleManager=new UserRoleManager();
            int roleId=aRoleManager.GetRoleID();
            List<UserRole> rolesList=new List<UserRole>();
            rolesList=aRoleManager.GetRoleLevels(roleId);
            string inClause =string.Empty;
            int i =1;
            int j = rolesList.Count;
            foreach (UserRole aRole in rolesList)
            {
                if (i < j)
                {
                    inClause += aRole.Id + ",";
                }
                else { inClause += aRole.Id; }
                i++;
            }

            string query = "SELECT * FROM `userInfo` LIMIT 1000;";
            string query1 = "select * from userInfo where userID in (select id from users where userroleid in ("+inClause+"))";
            DataSet aSet = aGateway.Select(query1);
            //IQueryable<Customer> queryable;
            List<UserInfo> aUsersList = new List<UserInfo>();
            //UserInfo aUserInfo = new UserInfo();
            foreach (DataRow dataRow in aSet.Tables[0].Rows)
            {

                UserInfo aUserInfo = new UserInfo();
                aUserInfo.Id = Convert.ToInt32(dataRow["ID"].ToString());
                aUserInfo.UserId = Convert.ToInt32(dataRow["UserID"].ToString());
                aUserInfo.UserName = dataRow["UserName"].ToString();
                aUserInfo.FullName = dataRow["FullName"].ToString();
                aUserInfo.FatherName = dataRow["FatherName"].ToString();
                aUserInfo.MotherName = dataRow["MotherName"].ToString();
                aUserInfo.PhoneNumber = dataRow["CellNumber"].ToString();
                aUserInfo.BirthDate = (DateTime)dataRow["BirthDay"];
                aUserInfo.CurrentAddress = dataRow["CurrentAddress"].ToString();
                aUserInfo.PermanentAddress = dataRow["PermanentAddress"].ToString();
                aUserInfo.BirthCertificateID = dataRow["BirthCertificateID"].ToString();

                aUsersList.Add(aUserInfo);

            }
            IQueryable<UserInfo> queryable = aUsersList.AsQueryable();

            // Apply the search
            if (!String.IsNullOrEmpty(search))
            {
                string[] searchElements = search.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string searchElement in searchElements)
                {
                    string element = searchElement;
                    queryable = queryable.Where(c => c.UserName.ToLower().Contains(element.ToLower()) || c.FullName.ToLower().Contains(element.ToLower()) || c.FatherName.ToLower().Contains(element.ToLower()) || c.MotherName.ToLower().Contains(element.ToLower()) || c.PhoneNumber.ToLower().Contains(element.ToLower()));
                }
                pageNo = 1;
            }

            // Add the sorting
            if (sort != null)
            {
                queryable = queryable.ApplySorting(sort);
                pageNo = 1;
            }
            else
                queryable = queryable.OrderBy(c => c.Id);
            List<UserInfo> aList = new List<UserInfo>();
            // Get the total number of records
            int totalItemCount = queryable.Count();
            var users = aList;
            // Retrieve the customers for the specified page
            if (String.IsNullOrEmpty(search))
            {
                users = queryable
                    .Skip(skip)
                    .Take(pageSize)
                    .ToList();
            }
            else
            {
                users = queryable
                    //.Skip(0)
                    //.Take(pageSize)
                .ToList();
                if (users.Count >= skip)
                {
                    users = users.Skip(skip).Take(pageSize).ToList();
                }
                else { users = users.Skip(0).Take(pageSize).ToList(); }

            }

            // Return the paged results
            return new PagedResult<UserInfo>(users, pageNo, pageSize, totalItemCount);
        }