public async Task <JsonResult> HasLikedPageAsync(string contentLink,
                                                         bool increasePointsIfLiked = false)
        {
            FacebookPostPage content     = context.FacebookPostPages.SingleOrDefault(c => c.Link == contentLink);
            string           accessToken = CurrentUser.AccessTokens.First(a => a.Provider == "Facebook").AccessTokenValue;
            List <string>    likers      = await content.GetLikersAsync(accessToken);

            bool hasLiked = likers.Any(liked => liked == content.PageId);

            if (hasLiked && increasePointsIfLiked)
            {
                lock (CurrentUser)
                {
                    CurrentUser.Points += 10;
                }
                await context.SaveChangesAsync();
            }
            return(Json(hasLiked, JsonRequestBehavior.AllowGet));
        }
        public async Task <JsonResult> GetNumberOfLikes(string link, int numberOfPrevLikes = 0, bool increasePoints = false)
        {
            FacebookPostPage page = context.FacebookPostPages
                                    .FirstOrDefault(c => c.Link == link);
            int count = await page.GetNumberOfLikes();

            if (increasePoints)
            {
                if (count > numberOfPrevLikes)
                {
                    lock (CurrentUser)
                    {
                        CurrentUser.Points += 10;
                        context.SaveChangesAsync();
                    }
                }
            }
            return(Json(count, JsonRequestBehavior.AllowGet));
        }
        public async Task <ActionResult> AddPageAsync(FacebookPostPage page, FormCollection form)
        {
            page.ApplicationUser = CurrentUser;
            if (page.ApplicationUser.Points - page.Points < 0)
            {
                ModelState.AddModelError("points", "You do not have enough points, Please earn points");
            }
            if (ModelState.IsValid)
            {
                context.FacebookPostPages.Add(page);
                lock (page.ApplicationUser) {
                    page.ApplicationUser.Points -= (int)page.Points;
                }
                await context.SaveChangesAsync();

                return(RedirectToAction("Pages"));
            }

            return(View(page));
        }