Exemple #1
0
        public MovieModel Create(Movie movie)
        {
            StringBuilder sbArtists = new StringBuilder();

            var movieModel = new MovieModel()
            {
                Id = movie.Id,
                Title = movie.Title,
                ImagePath = movie.ImagePath,
                Genre = movie.Genre,
                ReleaseDate = movie.ReleaseDate,
                Tags = movie.Tags
            };

            if (movie.Artists != null)
            {
                movieModel.Hero = movie.GetArtistName(ArtistRole.Hero);
                movieModel.Heroin = movie.GetArtistName(ArtistRole.Heroin);
                movieModel.CharacterArtists = movie.GetArtistName(ArtistRole.CharacterArtist);

                movieModel.Director = movie.GetArtistName(ArtistRole.Director);
                movieModel.MusicDirector = movie.GetArtistName(ArtistRole.MusicDirector);
                movieModel.Producer = movie.GetArtistName(ArtistRole.Producer);
            }

            if (movie.Reviews != null)
            {
                movieModel.Reviews = new List<ReviewModel>();
                movie.Reviews.ToList().ForEach(mr =>
                {
                    movieModel.Reviews.Add(Create(mr));
                });
            }
            return movieModel;
        }
Exemple #2
0
 public Movie Parse(Movie movie, MovieModel movieModel, IUnitOfWork _unitOfWork)
 {
     movie.Title = movieModel.Title;
     movie.Genre = movieModel.Genre;
     movie.ReleaseDate = movieModel.ReleaseDate;
     movie.ImagePath = movieModel.ImagePath;
     movie.Tags = movieModel.Tags;
     movie.Artists = ParseArtists(movie, movieModel, _unitOfWork);
     return movie;
 }
        public ActionResult Edit(int id, MovieModel movieModel)
        {
            if (ModelState.IsValid)
            {
                Movie movie;
                bool hasNewImage = false;
                string oldImagePath = string.Empty;

                if (Request.Files["Image"] != null)
                {
                    HttpPostedFileBase image = Request.Files["Image"];
                    if (image.ContentLength > 0)
                    {
                        movieModel.ImagePath = movieModel.Title + "_" + image.FileName;
                        image.SaveAs(Server.MapPath(_PATH) + "\\" + movieModel.ImagePath);
                        hasNewImage = true;
                    }
                }

                if (id == default(int))
                {
                    movie = ModelFactoryInstance.Parse(new Movie(), movieModel, _unitOfWork);
                    movie.State = ObjectState.Added;
                    _movieRepo.InsertGraph(movie);
                }
                else
                {
                    movie = _movieRepo.GetMovieById(id, includeArtists: true);
                    if (hasNewImage)
                    {
                        oldImagePath = Server.MapPath(_PATH) + "\\" + movie.ImagePath;
                    }
                    movie = ModelFactoryInstance.Parse(movie, movieModel, _unitOfWork);
                    movie.State = ObjectState.Modified;
                    _movieRepo.Update(movie);
                }
                _unitOfWork.Save();

                if (hasNewImage)
                {
                    if (!string.IsNullOrEmpty(oldImagePath) && System.IO.File.Exists(oldImagePath))
                    {
                        System.IO.File.Delete(oldImagePath);
                    }
                    return RedirectToAction("Crop", new { id = movie.Id, path = movie.ImagePath });
                }
                return RedirectToAction("Index");
            }

            return View(movieModel);
        }
Exemple #4
0
        private ICollection<MovieArtist> ParseArtists(Movie movie, MovieModel movieModel, IUnitOfWork _unitOfWork)
        {
            MovieArtist movieArtist;
            ArtistRole[] roles = { ArtistRole.Hero, ArtistRole.Heroin, ArtistRole.Director, ArtistRole.Producer, ArtistRole.MusicDirector };
            string artistName;

            if (movie.Artists == null)
            {
                movie.Artists = new List<MovieArtist>();
            }

            foreach (var role in roles)
            {
                artistName = movieModel.GetNameByRole(role);

                if (!string.IsNullOrEmpty(artistName))
                {
                    var artist = _unitOfWork.Repository<Artist>().Query().Filter(a => string.Equals(artistName, a.Name)).FirstOrDefault();

                    if (artist == null)
                    {
                        artist = new Artist() { Name = artistName, PrimaryRole = role, State = ObjectState.Added };
                    }

                    if (string.IsNullOrEmpty(movie.GetArtistName(role)))
                    {
                        movieArtist = new MovieArtist() { Artist = artist, Movie = movie, Role = role, State = ObjectState.Added };
                        movie.Artists.Add(movieArtist);
                    }
                    else if (movie.GetArtistName(role) != artistName)
                    {
                        movieArtist = movie.Artists.Where(ma => ma.Role == role).FirstOrDefault();
                        movieArtist.Artist = artist;
                        movieArtist.State = ObjectState.Modified;
                    }
                }
                else if (!string.IsNullOrEmpty(movie.GetArtistName(role)))
                {
                    movieArtist = movie.Artists.Where(ma => ma.Role == role).FirstOrDefault();
                    movieArtist.State = ObjectState.Deleted;
                }
            }
            return movie.Artists;
        }
        public ActionResult Edit(int? id)
        {
            MovieModel movieModel = null;

            if (id != null)
            {
                var movie = _movieRepo.GetMovieById((int) id, true, true);

                if (movie != null)
                {
                    movieModel = ModelFactoryInstance.Create(movie);
                }
            }

            if(movieModel == null)
            {
                movieModel = new MovieModel();
                movieModel.ReleaseDate = DateTime.Now;
            }

            return View(movieModel);
        }