Esempio n. 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");
            }
        }
Esempio n. 2
0
        public JsonResult All()
        {
            var context = new MovieEntities();
            var movies = context.Movies.ToList();

            var movieModels = new List<Movie>();

            foreach (var movie in movies)
            {
                movieModels.Add(this.GenerateMovieModel(movie));
            }

            return Json(movieModels, JsonRequestBehavior.AllowGet);
        }
Esempio n. 3
0
        //
        // GET: /Movies/Details/5
        public ActionResult Details(int id)
        {
            var context = new MovieEntities();
            var movie = context.Movies.Find(id);

            if (movie == null)
            {
                return View("NotFound");
            }

            var movieModel = this.GenerateMovieModel(movie);

            return PartialView("_Details", movieModel);
        }
Esempio n. 4
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;
        }
Esempio n. 5
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;
        }
Esempio n. 6
0
        private Models.People GetPeople(Movie currMovie, MovieEntities context, Kind kind)
        {
            ViewModels.People currPeople = GetCurrPeople(currMovie, kind);

            var kindName = Enum.GetName(typeof(Kind), kind);

            var people = context.People.Include("Kinds")
                            .FirstOrDefault(x => x.Kinds.name == kindName &&
                                            x.firstName == currPeople.FirstName &&
                                            x.lastName == currPeople.LastName);

            if (people == null)
            {
                people = this.AddPeople(currMovie, context, people, Kind.Director);
            }

            return people;
        }
Esempio n. 7
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();
            }
        }
Esempio n. 8
0
        //
        // GET: /Movies/Delete/5
        public ActionResult Delete(int id)
        {
            var context = new MovieEntities();
            var movieToRemove = context.Movies.Find(id);
            var movieViewModel = GenerateMovieModel(movieToRemove);

            return PartialView("_Delete", movieViewModel);
        }
Esempio n. 9
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");
            }
        }
Esempio n. 10
0
        //
        // GET: /Movies/Edit/5
        public ActionResult Edit(int id)
        {
            var context = new MovieEntities();
            var movie = context.Movies.FirstOrDefault(m => m.id == id);

            if (movie == null)
            {
                return View("NotFound");
            }

            var movieToEditModel = this.GenerateMovieModel(movie);
            return View("_Edit", movieToEditModel);
        }