Ejemplo n.º 1
0
        public void OnGet(string searchString, string sortOrder)
        {
            CurrentFilter = searchString;

            if (string.IsNullOrEmpty(sortOrder))
            {
                NameSort = "name_asc";
            }

            NameSort        = sortOrder == "name_asc" ? "name_desc" : "name_asc";
            IpAddressSort   = sortOrder == "ipaddress_asc" ? "ipaddress_desc" : "ipaddress_asc";
            AutoConnectSort = sortOrder == "autoconnect_asc" ? "autoconnect_desc" : "autoconnect_asc";
            StatusSort      = sortOrder == "status_asc" ? "status_desc" : "status_asc";

            IQueryable <Host> hostStateIQ = _viewDataHelper.GetHosts(_manager.GetAllHostStates(), searchString).AsQueryable();

            switch (sortOrder)
            {
            case "name_asc":
                hostStateIQ = hostStateIQ.OrderBy(h => h.Name);
                break;

            case "name_desc":
                hostStateIQ = hostStateIQ.OrderByDescending(h => h.Name);
                break;

            case "ipaddress_asc":
                hostStateIQ = hostStateIQ.OrderBy(h => h.IpAddress);
                break;

            case "ipaddress_desc":
                hostStateIQ = hostStateIQ.OrderByDescending(h => h.IpAddress);
                break;

            case "autoconnect_asc":
                hostStateIQ = hostStateIQ.OrderBy(h => h.AutoConnect);
                break;

            case "autoconnect_desc":
                hostStateIQ = hostStateIQ.OrderByDescending(h => h.AutoConnect);
                break;

            case "status_asc":
                hostStateIQ = hostStateIQ.OrderBy(h => h.Status);
                break;

            case "status_desc":
                hostStateIQ = hostStateIQ.OrderByDescending(h => h.Status);
                break;

            default:
                hostStateIQ = hostStateIQ.OrderBy(h => h.Name);
                break;
            }

            Hosts = hostStateIQ.ToList();
        }