コード例 #1
0
        public ActionResult Create(Movie currMovie)
        {
            try
            {
                var context = new MovieEntities();

                using (context)
                {
                    var director = GetPeople(currMovie, context, Kind.Director);
                    var maleActor = GetPeople(currMovie, context, Kind.MaleActor);
                    var femaleActor = GetPeople(currMovie, context, Kind.FemaleActor);

                    var movieToAdd = new Movies()
                    {
                        title = currMovie.Title,
                        year = currMovie.Year,
                        directorId = director.id,
                        leadingMaleRoleId = maleActor.id,
                        leadingFemaleRoleId = femaleActor.id
                    };

                    context.Movies.Add(movieToAdd);
                    context.SaveChanges();
                }

                return View();
            }
            catch
            {
                return View("Error");
            }
        }
コード例 #2
0
        private Models.Studio AddStudio(ViewModels.Studio studio, MovieEntities context)
        {
            var newStudio = new Models.Studio()
            {
                name = studio.Name,
                address = studio.Address
            };

            context.Studio.Add(newStudio);
            context.SaveChanges();
            return newStudio;
        }
コード例 #3
0
        public ActionResult Delete(int id, Movie movie)
        {
            try
            {
                var context = new MovieEntities();
                using (context)
                {
                    var movieToRemove = context.Movies.Find(id);
                    if (movieToRemove != null)
                    {
                        context.Movies.Remove(movieToRemove);
                        context.SaveChanges();
                    }
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
コード例 #4
0
        private Models.People AddPeople(Movie currMovie, MovieEntities context, Models.People people, Kind kind)
        {
            ViewModels.People currPeople = GetCurrPeople(currMovie, kind);

            var currStudio = context.Studio.FirstOrDefault(x => x.name == currPeople.Studio.Name);

            if (currStudio == null)
            {
                currStudio = AddStudio(currPeople.Studio, context);
            }

            people = new Models.People()
            {
                firstName = currMovie.Director.FirstName,
                lastName = currMovie.Director.LastName,
                age = currMovie.Director.Age,
                studioId = currStudio.id,
                kindId = (int)kind
            };

            context.People.Add(people);
            context.SaveChanges();

            return people;
        }
コード例 #5
0
        public ActionResult Edit(int id, Movie currMovie)
        {
            try
            {
                var context = new MovieEntities();
                using (context)
                {
                    var movieToUpdate = context.Movies.Find(id);

                    if (movieToUpdate != null)
                    {
                        var director = GetPeople(currMovie, context, Kind.Director);
                        var maleActor = GetPeople(currMovie, context, Kind.MaleActor);
                        var femaleActor = GetPeople(currMovie, context, Kind.FemaleActor);

                        movieToUpdate.title = currMovie.Title;
                        movieToUpdate.year = currMovie.Year;
                        movieToUpdate.leadingMaleRoleId = maleActor.id;
                        movieToUpdate.leadingFemaleRoleId = femaleActor.id;
                        movieToUpdate.directorId = director.id;

                        context.SaveChanges();
                    }
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View("Error");
            }
        }