Ejemplo n.º 1
0
 public static MovieDetailsView GetFromModel(Movie m)
 {
     return new MovieDetailsView
     {
         Id = m.Id,
         Title = m.Title,
         Year = m.Year,
         DirectorId = m.DirectorId,
         DirectorName = m.Director.FirstName + " " + m.Director.LastName,
         LeadingFemaleRoleId = (int)m.LeadingFemaleRoleId,
         LeadingFemaleRoleName = $"{m.LeadingFemaleRole.FirstName} {m.LeadingFemaleRole.LastName}",
         LeadingMaleRoleId = (int)m.LeadingMaleRoleId,
         LeadingMaleRoleName = $"{m.LeadingMaleRole.FirstName} {m.LeadingMaleRole.LastName}",
         StudioName = m.Studio.Name
     };
 }
Ejemplo n.º 2
0
        public ActionResult Create(MovieViewModel movieVM)
        {
            if (ModelState.IsValid && movieVM != null)
            {
                var actorId = Convert.ToInt32(movieVM.LandingMaleRoleName);
                var actressId = Convert.ToInt32(movieVM.LandingFemaleRoleName);
                Actor leadingActress = new Actor();
                Actor leadingActor = new Actor();

                if (actorId > 0)
                {
                    leadingActor = db.Actors.Find(actorId);
                    if (leadingActor == null)
                    {
                        throw new ArgumentException("Actor does not exists!");
                    }
                }

                if (actressId > 0)
                {
                    leadingActress = db.Actors.Find(actressId);
                    if (leadingActress == null)
                    {
                        throw new ArgumentException("Actress does not exists!");
                    }
                }

                Movie movie = new Movie()
                {
                    Title = movieVM.Title,
                    Year = movieVM.Year,
                    LandingFemaleRole = leadingActress,
                    LandingMaleRole = leadingActor
                };

                db.Movies.Add(movie);
                db.SaveChanges();
                return Content("");
            }

            return PartialView("_CreateMovie", movieVM);
        }
Ejemplo n.º 3
0
        public Movie Update(Movie model)
        {
            var movie = this.GetById(model.Id);

            movie.Title = model.Title;
            movie.Year = model.Year;

            foreach (PropertyInfo prop in model.GetType().GetProperties())
            {
                if (prop != null && prop.Name != "Id")
                {
                    typeof(Movie)
                        .GetProperty(prop.Name)
                        .SetValue(movie, prop.GetValue(model));
                }
            }

            //this.movies.Update(model);
            this.movies.SaveChanges();
            return this.movies.GetById(model.Id);
        }