コード例 #1
0
        /// <summary>
        /// Used to filter data from database for DataTable
        /// </summary>
        /// <param name="filterData"></param>
        /// <param name="loggedInUserRole"></param>
        /// <returns></returns>
        public DataTableFilteredData GetUsersDataTable(UserManagementDataTable filterData, UserRole loggedInUserRole)
        {
            var data = new Data.UserMethods().GetUsersDataTable(loggedInUserRole);

            //Performing filter action
            var userData = (from e in data
                            where (filterData.Search.Value == null ||
                                                 e.Email.Contains(filterData.Search.Value, StringComparison.OrdinalIgnoreCase) ||
                                                 e.UserName.Contains(filterData.Search.Value, StringComparison.OrdinalIgnoreCase)
                                )
                            select e);

            //Sorting
            var sortingData = filterData.Order.FirstOrDefault();

            if (sortingData != null)
                switch (sortingData.Column)
                {
                    case 0:
                        userData = sortingData.Dir == "asc" ? userData.OrderBy(m => m.UserName) : userData.OrderByDescending(m => m.UserName);
                        break;
                    case 1:
                        userData = sortingData.Dir == "asc" ? userData.OrderBy(m => m.Email) : userData.OrderByDescending(m => m.Email);
                        break;
                    case 2:
                        userData = sortingData.Dir == "asc" ? userData.OrderBy(m => m.TimeZoneRecords) : userData.OrderByDescending(m => m.TimeZoneRecords);
                        break;

                }

            var userModelDataTables = userData as UserModelDataTable[] ?? userData.ToArray();
            var userDataFiltering = userModelDataTables.Skip(filterData.Start).Take(filterData.Length);

            //Creating Table Object
            var records = userDataFiltering.Select(dataCurrent => new List<string>
            {
                dataCurrent.UserName, dataCurrent.Email, Convert.ToString(dataCurrent.TimeZoneRecords),Convert.ToString(dataCurrent.UserId)
            }).ToList();

            //

            return new DataTableFilteredData
            {
                draw = filterData.Draw,
                recordsFiltered = userModelDataTables.Count(),
                recordsTotal = data.Count,
                error = "",
                data = records
            };
        }
コード例 #2
0
 /// <summary>
 /// Used to get all the users
 /// </summary>
 /// <returns></returns>
 public List<UserModel> GetAllUsers(int pageNo, int records, UserRole role)
 {
     return new Data.UserMethods().GetAllUsers(pageNo, records, role);
 }