예제 #1
0
        // GET: Admin/Contacts
        public async Task <ActionResult> Index(int?page, string sortOrder)
        {
            if (Session["iduserAdmin"] == null)
            {
                return(RedirectToAction("Login", "HomeAdmin", new { area = "Admin" }));
            }
            else
            {
                //sap xep
                ViewBag.OrderFollowTimeContact  = String.IsNullOrEmpty(sortOrder) ? "time_asc" : "";
                ViewBag.OrderFollowEmailContact = sortOrder == "email_asc" ? "email_desc" : "email_asc";
                ViewBag.OrderFollowNameContact  = sortOrder == "name_asc" ? "name_desc" : "name_asc";

                var contacts = await _contact.GetAllAsync();

                switch (sortOrder)
                {
                case "time_asc":
                    contacts = contacts.OrderBy(x => x.Date);
                    break;

                case "email_desc":
                    contacts = contacts.OrderByDescending(x => x.Email);
                    break;

                case "email_asc":
                    contacts = contacts.OrderBy(x => x.Email);
                    break;

                case "name_desc":
                    contacts = contacts.OrderByDescending(x => x.Name);
                    break;

                case "name_asc":
                    contacts = contacts.OrderBy(x => x.Name);
                    break;

                default:
                    contacts = contacts.OrderByDescending(x => x.Date);
                    break;
                }
                int pageSize   = 10;
                int pageNumber = (page ?? 1);
                return(View(contacts.ToPagedList(pageNumber, pageSize)));
            }
        }
예제 #2
0
 // GET: Admin/Contacts
 public async Task <ActionResult> Index()
 {
     return(View(await _contact.GetAllAsync()));
 }