Esempio n. 1
0
        public IActionResult Add(WatchlistVM model)
        {
            WatchList watchList = new WatchList();

            watchList.MovieID = model.movieid;
            watchList.UserID  = Convert.ToInt32(TempData["ID"]);

            UserPageVM user = new UserPageVM();

            user.UserWatch = _context.WatchLists.Include(x => x.Movie).Where(q => q.UserID == Convert.ToInt32(TempData["ID"])).ToList().ToPagedList();

            int counter = 0;

            foreach (var item in user.UserWatch)
            {
                if (model.movieid == item.MovieID)
                {
                    counter++;
                }
            }


            if (counter == 0)
            {
                _context.WatchLists.Add(watchList);
                _context.SaveChanges();

                return(Redirect("/watchlist"));
            }

            return(Redirect("/watchlist"));
        }
Esempio n. 2
0
        public async Task <IActionResult> Delete(string userId, string movieId)
        {
            WatchlistShowVM item;
            WatchlistVM     watchlistItem = new WatchlistVM();
            MovieVM         movie         = await getMovie(Int32.Parse(movieId));

            IEnumerable <WatchlistVM> items;
            var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost:55169/api/Users/" + userId + "/watchlist");

            request.Headers.Add("Accept", "application/json");

            var client   = _httpClientFactory.CreateClient();
            var response = await client.SendAsync(request).ConfigureAwait(false);

            if (response.IsSuccessStatusCode)
            {
                using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);

                items = await JsonSerializer.DeserializeAsync <IEnumerable <WatchlistVM> >(responseStream);
            }
            else
            {
                items = Array.Empty <WatchlistVM>();
            }

            foreach (WatchlistVM watchListItem in items)
            {
                if (watchListItem.UserId == userId && watchListItem.MovieId == Int32.Parse(movieId))
                {
                    watchlistItem = watchListItem;
                }
            }

            item = new WatchlistShowVM()
            {
                UserId    = userId,
                MovieId   = Int32.Parse(movieId),
                MovieName = movie.Name,
                Image     = movie.Image,
                Status    = watchlistItem.Status,
                Score     = watchlistItem.Score
            };
            return(View(item));
        }
Esempio n. 3
0
        public async Task <IActionResult> Update(string userId, string movieId, WatchlistShowVM watchlistShow)
        {
            WatchlistVM watchlistUpdate = new WatchlistVM()
            {
                UserId  = userId,
                MovieId = Int32.Parse(movieId),
                Status  = watchlistShow.Status,
                Score   = watchlistShow.Score
            };
            var client      = _httpClientFactory.CreateClient();
            var itemContent = new StringContent(JsonSerializer.Serialize(watchlistUpdate), Encoding.UTF8, "application/json");

            HttpResponseMessage httpResponseMessage = await client.PutAsync(new Uri("http://localhost:55169/api/Users/" + userId + "/watchlist"), itemContent).ConfigureAwait(false);

            if (httpResponseMessage.IsSuccessStatusCode)
            {
                return(RedirectToAction(nameof(Index), new { id = userId }));
            }
            return(RedirectToAction(nameof(Index), new { id = userId }));
        }
Esempio n. 4
0
        public async Task <IActionResult> Add(string userId, string movieId, WatchlistShowVM watchlistShow)
        {
            WatchlistVM watchlistItem = new WatchlistVM()
            {
                UserId  = userId,
                MovieId = Int32.Parse(movieId),
                Score   = 0,
                Status  = "PlanToWatch"
            };
            UserVM currentUser = await getCurrentUser(userId);

            UserPutVM userPut = new UserPutVM()
            {
                Id            = userId,
                Username      = currentUser.Username,
                Name          = currentUser.Name,
                LastName      = currentUser.LastName,
                Email         = currentUser.Email,
                Birthday      = currentUser.Birthday,
                About         = currentUser.About,
                Image         = currentUser.Image,
                WatchListDTOs = currentUser.WatchListDTOs
            };

            userPut.WatchListDTOs.Add(watchlistItem);

            var client      = _httpClientFactory.CreateClient();
            var userContent = new StringContent(JsonSerializer.Serialize(userPut), Encoding.UTF8, "application/json");

            HttpResponseMessage httpResponseMessage = await client.PutAsync(new Uri("http://localhost:55169/api/Users/" + userId), userContent).ConfigureAwait(false);

            if (httpResponseMessage.IsSuccessStatusCode)
            {
                HttpContext.Session.Remove("watchlist");
                HttpContext.Session.SetString("watchlist", JsonSerializer.Serialize(userPut.WatchListDTOs));
                return(RedirectToAction(nameof(Index), new { id = userId }));
            }
            return(RedirectToAction(nameof(Index), new { id = userId }));
        }