コード例 #1
0
        // GET: Watched

        public ActionResult Index()
        {
            WatchedList model       = new WatchedList();
            int         currentUser = (int)Session["userId"];

            var watchedMovies = db.Watched.Where(u => u.UserId == currentUser).ToList();

            return(View(watchedMovies.ToList()));
        }
コード例 #2
0
        public static async Task <IDataResult <IdentityResult> > WatchedListAsync(this UserManager <VesizleUser> userManager, ClaimsPrincipal userClaims, WatchedList watchedList)
        {
            IDataResult <IdentityResult> result;
            var userId = userClaims.FindFirst(ClaimTypes.NameIdentifier).Value;
            var user   = await userManager.Users.Include(vesizleUser => vesizleUser.WatchedLists)
                         .FirstOrDefaultAsync(vesizleUser => vesizleUser.Id == userId);

            var userWatched = user.WatchedLists.FirstOrDefault(watch => watch.MovieId == watchedList.MovieId);

            if (userWatched == null)
            {
                user.WatchedLists.Add(watchedList);
                result = new SuccessDataResult <IdentityResult>(Messages.AddWatchedListSuccess, await userManager.UpdateAsync(user));
            }
            else
            {
                user.WatchedLists.Remove(userWatched);
                result = new SuccessDataResult <IdentityResult>(Messages.RemoveWatchedListSuccess, await userManager.UpdateAsync(user));
            }

            return(result);
        }