Beispiel #1
0
        private void OrderByAuthor()
        {
            var orderedList = list
                              .OrderBy(x => x.Album.Artist.Name)
                              .Select(t => new
            {
                Artist = t.Album.Artist.Name,
                Title  = t.Name,
                Album  = t.Album.Title
            }).ToList();

            DataGridView.DataSource = orderedList;
        }
        // GET: Contact
        public ActionResult Index(string sortOrder, string CurrentSort, int?page, string searchString, string currentFilter)
        {
            int pageSize  = 10;
            int pageIndex = 1;

            pageIndex           = page.HasValue ? Convert.ToInt32(page) : 1;
            ViewBag.CurrentSort = sortOrder;
            sortOrder           = String.IsNullOrEmpty(sortOrder) ? "FirstName" : sortOrder;
            IPagedList <ContactMaster> contacts = null;

            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            ViewBag.CurrentFilter = searchString;

            var response = _manager.GetAllContacts();

            contacts = response.ToPagedList(pageIndex, pageSize);

            if (!String.IsNullOrEmpty(searchString))
            {
                contacts = contacts.Where(C => C.FirstName.Contains(searchString) || C.LastName.Contains(searchString)).ToPagedList(pageIndex, pageSize);;
            }

            switch (sortOrder)
            {
            case "FirstName":
                if (sortOrder.Equals(CurrentSort))
                {
                    contacts = contacts.OrderByDescending(m => m.FirstName).ToPagedList(pageIndex, pageSize);
                }
                else
                {
                    contacts = contacts.OrderBy(m => m.FirstName).ToPagedList(pageIndex, pageSize);
                }
                break;

            case "LastName":
                if (sortOrder.Equals(CurrentSort))
                {
                    contacts = contacts.OrderByDescending(m => m.LastName).ToPagedList(pageIndex, pageSize);
                }
                else
                {
                    contacts = contacts.OrderBy(m => m.LastName).ToPagedList(pageIndex, pageSize);
                }
                break;

            case "Default":
                contacts = contacts.OrderBy(m => m.FirstName).ToPagedList(pageIndex, pageSize);
                break;
            }

            return(View(contacts));
        }