public object ItemsFromIndex(int requestIndex, int countBefore, int countAfter)
        {
            // Get the user id
            var authenticationToken = Request.Headers.GetValues("authenticationToken").FirstOrDefault();
            var clientSecret = WebConfigurationManager.AppSettings["CLIENT_SECRET"];
            var d = new Dictionary<int, string>();
            d.Add(0, clientSecret);
            var myJWT = new JsonWebToken(authenticationToken, d);
            var user = myJWT.Claims.UserId;


            var startIndex = Math.Max(0, requestIndex - countBefore);
            var takeCount = Math.Max(MIN_ITEMS, Math.Min(MAX_ITEMS - countBefore, countAfter));

            var tasks = _db.Tasks
                .OrderBy(t => t.Id)
                .Skip(startIndex)
                .Take(takeCount).ToList();

            return new {
                items = tasks,
                offset = startIndex,
                totalCount = tasks.Count()
            };

        }
        public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext)
        {
            // Get the Windows Live authentication token from header
            string authenticationToken = null;
            try {
                authenticationToken = actionContext.Request.Headers.GetValues("authenticationToken").FirstOrDefault();
            }
            catch {
                actionContext.Response = new System.Net.Http.HttpResponseMessage(System.Net.HttpStatusCode.Unauthorized);
            }

            // Load client secret from Web.config
            var clientSecret = WebConfigurationManager.AppSettings["CLIENT_SECRET"];
            if (String.IsNullOrWhiteSpace(clientSecret)) {
                throw new Exception("Missing Client Secret for Authentication");
            }

            // Validate token
            var d = new Dictionary<int, string>();
            d.Add(0, clientSecret);
            try {
                var myJWT = new JsonWebToken(authenticationToken, d);
            }
            catch {
                actionContext.Response = new System.Net.Http.HttpResponseMessage(System.Net.HttpStatusCode.Unauthorized);
            }
        }