예제 #1
0
        public async Task <IActionResult> Detail(int?id)
        {
            Show show = await showService.GetShowDetails(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(show.ID));

                isInList = myListShow == null ? false : true;
            }

            var vm = new DetailShowViewModel()
            {
                Show       = show,
                MyListShow = myListShow,
                IsLoggedIn = isLoggedIn,
                IsInList   = isInList
            };

            return(View(vm));
        }
예제 #2
0
        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"));
        }