//Returns the user's contacts
        //Implements Office 365-side paging
        // GET: /Contact/
        public async Task <ActionResult> Index(int?page)
        {
            var pageNumber = page ?? 1;

            if (page < 1)
            {
                pageNumber = 1;
            }
            //Number of events displayed on one page. Edit pageSize if you like
            int pageSize = 10;

            List <model.ContactItem> contacts = await _contactOperations.GetContactsPageAsync(pageNumber, pageSize);

            //Store these in the ViewBag so you can use them in the Index view
            ViewBag.Page     = pageNumber;
            ViewBag.NextPage = pageNumber + 1;
            ViewBag.PrevPage = pageNumber - 1;
            ViewBag.LastPage = false;

            if ((contacts != null) && (contacts.Count == 0))
            {
                ViewBag.LastPage = true;
            }
            return(View(contacts));
        }
Ejemplo n.º 2
0
        //Returns the user's contacts
        //Implements Office 365-side paging
        // GET: /Contact/
        public async Task <ActionResult> Index(int?page)
        {
            ViewBag.O365ServiceOperationFailed = _O365ServiceOperationFailed;

            if (_O365ServiceOperationFailed)
            {
                _O365ServiceOperationFailed = false;
            }

            var pageNumber = page ?? 1;

            if (page < 1)
            {
                pageNumber = 1;
            }

            //Number of events displayed on one page. Edit pageSize if you like
            int pageSize = 10;

            List <model.ContactItem> contacts = new List <model.ContactItem>();

            try
            {
                contacts = await _contactOperations.GetContactsPageAsync(pageNumber, pageSize);
            }
            catch (AdalException e)
            {
                if (e.ErrorCode == AdalError.FailedToAcquireTokenSilently)
                {
                    //This exception is thrown when either you have a stale access token, or you attempted to access a resource that you don't have permissions to access.
                    throw e;
                }
            }

            //Store these in the ViewBag so you can use them in the Index view
            ViewBag.Page     = pageNumber;
            ViewBag.NextPage = pageNumber + 1;
            ViewBag.PrevPage = pageNumber - 1;
            ViewBag.LastPage = false;

            if ((contacts != null) && (contacts.Count == 0))
            {
                ViewBag.LastPage = true;
            }

            ViewBag.NoItemsinService = false;
            if ((contacts.Count == 0) && (pageNumber == 1))
            {
                ViewBag.NoItemsinService = true;
            }
            return(View(contacts));
        }