Пример #1
0
        public List <Models.ListItem> GetMaintenanceList(string search, int start, int length, string sortColumn, bool ascending, out int count, out int filteredCount)
        {
            NLogHelper.WriteEvent(NLog.LogLevel.Info, "Listitem - MaintenaceList -->> started");

            int resultCount = 0, resultFilteredCount = 0;
            List <Models.ListItem> result = Execute(cx =>
            {
                search     = search.ToLower();
                sortColumn = string.Format("{0} {1}", sortColumn, ascending ? "ASC" : "DESC");
                IQueryable <Data.ListItem> res1 = cx.ListItems.Where(li => li.ParentId.HasValue);
                resultCount = res1.Count();
                if (!string.IsNullOrEmpty(search))
                {
                    res1 = res1.Where(li => li.Parent.Name.ToLower().Contains(search) || li.Name.ToLower().Contains(search) || li.Description.ToLower().Contains(search) || li.Code.ToLower().Contains(search));
                }
                resultFilteredCount = res1.Count();

                NLogHelper.WriteEvent(NLog.LogLevel.Info, "Listitem - MaintenaceList -->> filtered result count completed.");

                IQueryable <Data.ListItem> res2;
                if (sortColumn == "ListName ASC")
                {
                    res2 = res1.OrderBy(li => li.Parent.Name).ThenBy(li => li.Name);
                }
                else if (sortColumn == "ListName DESC")
                {
                    res2 = res1.OrderByDescending(li => li.Parent.Name).ThenBy(li => li.Name);
                }
                else
                {
                    res2 = res1.OrderBy(sortColumn);
                }

                var x = res2.Skip(start).Take(length);

                NLogHelper.WriteEvent(NLog.LogLevel.Info, "Listitem - MaintenaceList -->> skip and take completed.");

                try
                {
                    return(res2.Skip(start).Take(length).ToList().Select(li => new Models.ListItem(li)).ToList());
                }
                finally
                {
                    NLogHelper.WriteEvent(NLog.LogLevel.Info, "Listitem - MaintenaceList -->> ended");
                }
            });

            count         = resultCount;
            filteredCount = resultFilteredCount;
            return(result);
        }