Ejemplo n.º 1
0
 public ActionResult Index()
 {
     ViewBag.counts = "";
     List<Movie> movieliked = new List<Movie>();
     var query = db.movie.ToList().Select(x => new
     {
         movieID = x.ID,
         like_count = x.likes.Count
     }).OrderByDescending(x => x.like_count).Take(5);
     foreach (var movie in query)
     {
         Movie addmv = new Movie();
         addmv = db.movie.FirstOrDefault(m => m.ID == movie.movieID);
         movieliked.Add(addmv);
     }
     IEnumerable<CineChat.MyFilmsAPIModels.inTheater> inTheaters = CineChat.Controllers.MyFilmsApiComingSoonController.apiSearch();
     ViewBag.inTheaters = inTheaters.ToList();
     return View(movieliked);
 }
        public ActionResult Like(string imdbID, string searchValue)
        {
            //add movie to mymovies list
            IEnumerable<FilmesIMDB> imdbmovie = new List<FilmesIMDB>();
            string searchString = imdbID;
            if (!String.IsNullOrEmpty(searchString))
            {
                imdbmovie = apiSearch(searchString, true);

                Movie newmovie = new Movie();
                string currentUserId = User.Identity.GetUserId();
                var currentUser = db.Users.FirstOrDefault(x => x.Id == currentUserId);
                var imdb_movie = imdbmovie.FirstOrDefault();
                var checkmovie = db.movie.FirstOrDefault(m => m.ImdbID == imdb_movie.ImdbID);
                //verify if movie already exists
                if (checkmovie == null)//if not, create new movie on db
                {
                    newmovie.ImdbID = imdb_movie.ImdbID;
                    newmovie.poster = imdb_movie.Poster;
                    newmovie.title = imdb_movie.Title;
                    newmovie.description = imdb_movie.Plot;
                    DateTime tempDate;//convert date of imdb to datetime
                    if (DateTime.TryParse(imdb_movie.Released, out tempDate) == true)
                    {
                        // succeeded ...
                        newmovie.releasedate = tempDate;
                    }
                    else
                    {
                        newmovie.releasedate = DateTime.Now;
                    }
                    //remove min from imdb data 000 min
                    int temptime = 0;
                    int temptime2 = 0;
                    string time = "";

                    for (int i = 0; i < imdb_movie.RunTime.Length; i++)
                    {
                        if (Char.IsDigit(imdb_movie.RunTime[i]))
                            time += imdb_movie.RunTime[i];
                    }

                    //convert data to datetime and sum the minuts
                    if (Int32.TryParse(time, out temptime))
                    {
                        temptime2 = temptime2 + temptime;
                        DateTime dt = DateTime.Now.Date;
                        dt = dt.AddMinutes(temptime2);
                        newmovie.duration = dt;
                    }
                    else
                    {
                        newmovie.duration = DateTime.Now;
                    }
                    //convert string rate to double --- . to , and parse
                    double rate = 0;
                    imdb_movie.imdbRating = imdb_movie.imdbRating.Replace(".", ",");
                    if (double.TryParse(imdb_movie.imdbRating, out rate))
                    {
                        newmovie.ratingImdb = rate;
                    }
                    else
                    {
                        newmovie.ratingImdb = 0;
                    }
                    //create necessary categories in db_ check if already exist
                    List<Category> catlist = new List<Category>();
                    string[] CategoryNames = imdb_movie.Genre.Split(',').Select(sValue => sValue.Trim()).ToArray();
                    foreach (string catn in CategoryNames)
                    {
                        var checkcat = db.categorie.FirstOrDefault(c => c.description == catn);
                        Category newcat = null;
                        if (checkcat == null)
                        {
                            newcat = new Category();
                            newcat.description = catn;
                            db.categorie.Add(newcat);
                        }
                        else
                        {
                            newcat = checkcat;
                        }
                        catlist.Add(newcat);
                    }
                    //add movie to db _ movie does not exist
                    newmovie.categories = catlist;
                    db.movie.Add(newmovie);
                    currentUser.likes.Add(newmovie);

                }
                else
                {
                    //movie exist_ relate with user -- like
                    currentUser.likes.Add(checkmovie);
                }
                db.SaveChanges(); //save db changes
                TempData["successlike"] = imdb_movie.Title + " added with success";
                return RedirectToAction("Search", "FilmesIMDB", new { id = searchValue });//go tlast search
            }
            TempData["successlike"] = "Failed to add movie";
            return RedirectToAction("Search", "FilmesIMDB", new { id = searchValue });//go tlast search
        }
Ejemplo n.º 3
0
 public ActionResult TopRated()
 {
     ViewBag.counts = "";
     List<Movie> movieliked = new List<Movie>();
     var query = db.movie.ToList().Select(x => new
     {
         movieID = x.ID,
         like_count = x.likes.Count
     }).OrderByDescending(x => x.like_count).Take(40);
     foreach (var movie in query)
     {
         Movie addmv = new Movie();
         addmv = db.movie.FirstOrDefault(m => m.ID == movie.movieID);
         movieliked.Add(addmv);
     }
     return View(movieliked);
 }
Ejemplo n.º 4
0
        //---------------Edit POST Controller  modify categories--------------------------------
        private void UpdateMovieCategory(string[] selectedCategories, Movie movieToUpdate)
        {
            if (selectedCategories == null)
            {
                movieToUpdate.categories = new List<Category>();
                return;
            }

            var selectedCategoriesHS = new HashSet<string>(selectedCategories);
            var moviecategory = new HashSet<int>
                (movieToUpdate.categories.Select(c => c.ID));
            foreach (var category in db.categorie)
            {
                if (selectedCategoriesHS.Contains(category.ID.ToString()))
                {
                    if (!moviecategory.Contains(category.ID))
                    {
                        movieToUpdate.categories.Add(category);
                    }
                }
                else
                {
                    if (moviecategory.Contains(category.ID))
                    {
                        movieToUpdate.categories.Remove(category);
                    }
                }
            }
        }
Ejemplo n.º 5
0
 // movie edit get list of categories
 private void PopulateCategoryData(Movie movie)
 {
     var allCategory = db.categorie;
     var moviecategory = new HashSet<int>(movie.categories.Select(c => c.ID));
     var viewModel = new List<AssignedCategoryData>();
     foreach (var category in allCategory)
     {
         viewModel.Add(new AssignedCategoryData
         {
             CategoryID = category.ID,
             Description = category.description,
             Assigned = moviecategory.Contains(category.ID)
         });
     }
     ViewBag.Categories = viewModel;
 }