public ActionResult Edit(Movie_Users movie_user, List<string> Storage)
        {
            Movie_Users movieuserHelp = storeDb.Movie_Users.Find(movie_user.IdRelMovie_User);
            if (ModelState.IsValid)
            {
                foreach (var item in movieuserHelp.MovieUser_TypeStorage.ToList())
                {
                    storeDb.MovieUser_TypeStorage.Remove(item);
                }
                movieuserHelp.MovieUser_TypeStorage = new List<MovieUser_TypeStorage>();
                Storage.ForEach(a =>
                {
                    var type_storage = storeDb.TypeStorages.FirstOrDefault(store => store.TypeStorage1 == a);
                    movieuserHelp.MovieUser_TypeStorage.Add(new MovieUser_TypeStorage
                    {
                        TypeStorage = type_storage
                    });
                });

                movieuserHelp.PersonalScore = movie_user.PersonalScore;
                movieuserHelp.Seen = movie_user.Seen;
                movieuserHelp.Favorite = movie_user.Favorite;

                storeDb.SaveChanges();
                storeDb.Entry(movieuserHelp).State = System.Data.Entity.EntityState.Modified;
                storeDb.SaveChanges();
                return RedirectToAction("Index");
            }
               return View(movie_user);
        }
        public ActionResult AddMovie(Movie_Users _movieUser, string nameDirector, string nameActor, string nameCountry, string nameGenre, List<string> Storage)
        {
            var id_User = (Session["LogedUserId"]);
            var logedUser = Convert.ToInt32(id_User);

                if (ModelState.IsValid)
                {

                 var auxMovie = storeDb.Movies1.FirstOrDefault(movie => movie.Title == _movieUser.Movies1.Title);
                 _movieUser.idUser = logedUser;
                if(auxMovie==null)
                  {

                 _movieUser.Movies1.Movie_Director = new List<Movie_Director>();
                nameDirector.Split(',').ToList().ForEach(a =>
                {
                    var director = storeDb.Directors.FirstOrDefault(direc => direc.nameDirector == a.Trim());
                    if(director==null)
                    {
                        director = new Director();
                        director.nameDirector = a.Trim();
                    }
                    _movieUser.Movies1.Movie_Director.Add(new Movie_Director
                    {
                        Director = director
                    });
                });

                _movieUser.Movies1.Movie_Actors = new List<Movie_Actors>();
                nameActor.Split(',').ToList().ForEach(a =>
                {
                    var actor = storeDb.Actors.FirstOrDefault(_actor => _actor.Name == a.Trim());
                    if (actor==null)
                    {
                        actor = new Actor();
                        actor.Name = a.Trim();
                    }
                    _movieUser.Movies1.Movie_Actors.Add(new Movie_Actors
                    {
                        Actor=actor
                    });
                });

                _movieUser.Movies1.Movie_Country = new List<Movie_Country>();

                    nameCountry.Split(',').ToList().ForEach(a =>
                {
                    var country = storeDb.Countries.FirstOrDefault(_country => _country.Name == a.Trim());
                    if (country==null)
                    {
                        country = new Country();
                        country.Name = a.Trim();
                    }
                    _movieUser.Movies1.Movie_Country.Add(new Movie_Country
                    {
                         Country = country
                    });
                });

                _movieUser.Movies1.Movies_Genres = new List<Movies_Genres>();
                nameGenre.Split(',').ToList().ForEach(a =>
                {
                    var genre = storeDb.Genres.FirstOrDefault(_country => _country.Name == a.Trim());
                    if (genre == null)
                    {
                        genre = new Genre();
                        genre.Name = a.Trim();
                    }
                    _movieUser.Movies1.Movies_Genres.Add(new Movies_Genres
                    {
                        Genre= genre
                    });
                });
                  }
                _movieUser.MovieUser_TypeStorage = new List<MovieUser_TypeStorage>();
                Storage.ForEach(a =>{
                    var type_storage = storeDb.TypeStorages.FirstOrDefault(store => store.TypeStorage1 == a);
                    _movieUser.MovieUser_TypeStorage.Add(new MovieUser_TypeStorage
                    {
                        TypeStorage=type_storage
                    });
                });

                storeDb.Movie_Users.Add(_movieUser);
                try {
                storeDb.SaveChanges();
                    }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Debug.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                            eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                    throw;
                }
                return RedirectToAction("Index");

            };
            ViewBag.storageId = new SelectList(storeDb.TypeStorages, "IdTypeStorage", "TypeStorage1");
            return View();
        }
        public ActionResult BrowseByYear(int year)
        {
            var id_User = (Session["LogedUserId"]);
            var logedUser = Convert.ToInt32(id_User);

            // Retrieve Movies by year from database
            var moviesByYear = from p in storeDb.Movies1
                               where p.Year == year
                               select p;

            var moviesByUserYear = from p in storeDb.Movie_Users
                                   where p.Movies1.Year== year
                                   select p;

            List<Movie_Users> moviesHelp = new List <Movie_Users>();
            Movie_Users movieUser= new Movie_Users();

            foreach (var k in moviesByUserYear)
            {
                if (k.idUser == logedUser)
                {moviesHelp.Add(k);}

            }

            ViewBag.logedUser = logedUser;
            ViewBag.year = year;
            return View(moviesHelp);
        }