コード例 #1
0
        public ActionResult GetSubscribersAfter(int id)
        {
            if (!ModelState.IsValid && !Request.IsAjaxRequest())
            {
                return(RedirectToAction("Index"));
            }

            var youtubePage = _context.Youtubes.Where(yt => yt.Id == id).SingleOrDefault();

            if (youtubePage == null)
            {
                return(HttpNotFound());
            }

            var request = _youtubeService.Channels.List("statistics");

            request.Id = youtubePage.YoutubeUsername;


            var channel = request.Execute().Items[0];

            var numberOfLikes = channel.Statistics.SubscriberCount;

            if (numberOfLikes == null)
            {
                ViewBag.text = "This page is broken. Please skip it.";
                return(PartialView("Message"));
            }


            if (numberOfLikes > UInt64.Parse(TempData["numberOfSubscribers"].ToString()))
            {
                var idUser       = User.Identity.GetUserId();
                var userWhoLiked = _context.Users.Where(u => u.Id == idUser).Single();

                if (userWhoLiked != null)
                {
                    userWhoLiked.Points        = userWhoLiked.Points + youtubePage.Cpc - 1;
                    youtubePage.User.Points    = youtubePage.User.Points - youtubePage.Cpc;
                    youtubePage.NumberOfClicks = youtubePage.NumberOfClicks + 1;
                    var ytSubscribe = new YoutubeSubscribtion()
                    {
                        YoutubePageId = youtubePage.Id, UserId = userWhoLiked.Id
                    };
                    userWhoLiked.ClicksToday += 1;
                    _context.YtSubscribes.Add(ytSubscribe);
                    _context.SaveChanges();
                    ViewBag.text   = "You succesfully like " + youtubePage.Name;
                    ViewBag.points = userWhoLiked.Points;
                    ViewBag.pageid = youtubePage.Id;
                }
                return(PartialView("_TextConfirmation", youtubePage));
            }
            else
            {
                TempData["numberOfLikes"] = "9999999";
                ViewBag.text = "You didn't subscribe this channel.";
                return(PartialView("Message"));
            }
        }
コード例 #2
0
 public ActionResult Skip(int id)
 {
     if (ModelState.IsValid)
     {
         var userId      = User.Identity.GetUserId();
         var ytSubscribe = new YoutubeSubscribtion()
         {
             YoutubePageId = id,
             UserId        = userId
         };
         _context.YtSubscribes.Add(ytSubscribe);
         _context.SaveChanges();
     }
     ViewBag.text = "You skipped";
     return(PartialView("Message"));
 }