public async Task <IActionResult> Detail(int?id) { Movie movie = await showService.GetMovieDetails(id, _context, webRequest); var user = await GetCurrentUserAsync(); MyListShows myListShow = null; bool isLoggedIn = true; bool isInList = false; if (user == null) { isLoggedIn = false; myListShow = null; } else { myListShow = await _context.MyListShows .Include(x => x.MyList) .Where(x => x.MyList.User.Id == user.Id) .SingleOrDefaultAsync(x => x.SafeCompareId(movie.ID)); isInList = myListShow == null ? false : true; } var vm = new DetailMovieViewModel() { Movie = movie, MyListShow = myListShow, IsLoggedIn = isLoggedIn, IsInList = isInList }; return(View(vm)); }
public async Task <JsonResult> AddToList(int id, string type) { // Need to add check to make sure the show isn't already in your list Movie movie = null; Show show = null; if (type == "show") { show = _context.Shows.SingleOrDefault(x => x.ID == id); if (show == null) { show = await _serviceHandler.GetShowDetails(id, _context, _webRequest); } } else if (type == "movie") { movie = _context.Movies.SingleOrDefault(x => x.ID == id); if (movie == null) { movie = await _serviceHandler.GetMovieDetails(id, _context, _webRequest); } } else { return(Json("ERROR: unknown type")); } var user = await GetCurrentUserAsync(); if ((type == "show" && show != null) || (type == "movie" && movie != null)) { var myList = _context.MyList .Include(x => x.MyListShows) .FirstOrDefault(x => x.User.Id == user.Id); if (myList.MyListShows == null) { myList.MyListShows = new List <MyListShows>(); } var temp = new MyListShows() { Rating = (int)ShowRating.NOT_RATED, Status = (int)ShowStatus.WANT_TO_WATCH, LastChange = DateTime.Now, MyList = myList }; if (type == "movie") { temp.Movie = movie; temp.MovieId = movie.ID; } else if (type == "show") { temp.Show = show; temp.ShowId = show.ID; } _context.Add(temp); _context.SaveChanges(); } return(Json("Added to list")); }