public ActionResult getToken()
        {
            // get connection from session
            AuthorizationCodeConnection connection = HttpContext.Session["AuthorizationCodeConnection"] as AuthorizationCodeConnection;

            if (connection == null || ((AuthorizationCodeConfiguration)connection.connectionConfiguration).authorizationCode == null)
            {
                //is the connection available in session or is the
                // cached connection expired then lets re-authorize
                return(Authorize());
            }

            try
            {
                connection.connect();

                // connection was successfull
                if (connection.isConnectedIndicator())
                {
                    // so get the worker like we wanted
                    ViewBag.Message = "Successfully connected to ADP API";
                }
            }
            catch (Exception e)
            {
                ViewBag.isError = true;
                ViewBag.Message = e.Message;
            }

            return(View("Index"));
        }
        public ActionResult getUserInfo()
        {
            // get connection from session
            AuthorizationCodeConnection connection = HttpContext.Session["AuthorizationCodeConnection"] as AuthorizationCodeConnection;
            UserInfo user = null;

            if (connection == null || ((AuthorizationCodeConfiguration)connection.connectionConfiguration).authorizationCode == null)
            {
                //is the connection available in session or is the
                // cached connection expired then lets re-authorize
                ViewBag.Message = "Not logged in or no connection available";
            }
            else
            {
                try
                {
                    connection.connect();

                    // connection was successfull
                    if (connection.isConnectedIndicator())
                    {
                        ViewBag.Message = "Successfully connected to ADP API";

                        // so get the worker like we wanted
                        UserInfoHelper helper = new UserInfoHelper(connection);
                        user = helper.getUserInfo();
                    }
                }
                catch (Exception e)
                {
                    ViewBag.isError = true;
                    ViewBag.Message = e.Message;
                }
            }

            ViewBag.user = user;
            return(View("Index", user));
        }
示例#3
0
        public ActionResult getData()
        {
            // get connection from session
            AuthorizationCodeConnection connection = HttpContext.Session["AuthorizationCodeConnection"] as AuthorizationCodeConnection;

            if (connection == null || ((AuthorizationCodeConfiguration)connection.connectionConfiguration).authorizationCode == null)
            {
                //is the connection available in session or is the
                // cached connection expired then lets re-authorize
                ViewBag.Message = "Not logged in or no connection available";
            }
            else
            {
                try
                {
                    connection.connect();

                    // connection was successfull
                    if (connection.isConnectedIndicator())
                    {
                        // so get the worker like we wanted
                        ViewBag.Message = "Successfully connected to ADP API";

                        // get data using Product URL
                        var data = connection.getADPData("https://iat-api.adp.com/core/v1/userinfo");
                        ViewBag.Message = data;
                    }
                }
                catch (Exception e)
                {
                    ViewBag.isError = true;
                    ViewBag.Message = e.Message;
                }
            }
            return(View("Index"));
        }