예제 #1
0
        //GET: Movies/Details
        public ActionResult Details(int id)
        {
            var movie = _context.Movies.SingleOrDefault(m => m.Id == id);

            if (movie == null)
            {
                return(HttpNotFound());
            }

            var listActorsJoin = _context.MovieActors.Where(m => m.MovieId == id).ToList();
            var listOfActors   = new List <Actor>();

            foreach (var actorId in listActorsJoin)
            {
                var actor = _context.Actors.Where(a => a.id == actorId.ActorId).SingleOrDefault();
                listOfActors.Add(actor);
            }


            var viewModel = new AddActorViewModel
            {
                Movie  = movie,
                Actors = listOfActors
            };


            return(View(viewModel));
        }
예제 #2
0
        // GET: Movies/Random
        public ActionResult Random()
        {
            //get last id and choose random number between 1 and last id.
            var    lastId = _context.Movies.OrderByDescending(m => m.Id).First().Id;
            Random r      = new Random();
            int    id     = r.Next(1, lastId);

            var movie = _context.Movies.SingleOrDefault(m => m.Id == id);

            if (movie == null)
            {
                return(HttpNotFound());
            }

            var listActorsJoin = _context.MovieActors.Where(m => m.MovieId == id).ToList();
            var listOfActors   = new List <Actor>();

            foreach (var actorId in listActorsJoin)
            {
                var actor = _context.Actors.Where(a => a.id == actorId.ActorId).SingleOrDefault();
                listOfActors.Add(actor);
            }

            var viewModel = new AddActorViewModel
            {
                Movie  = movie,
                Actors = listOfActors
            };


            return(View(viewModel));
        }
예제 #3
0
        //GET: Movies/AddActors
        public ActionResult AddActors(int id)
        {
            var movie = _context.Movies.SingleOrDefault(m => m.Id == id);

            if (movie == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new AddActorViewModel
            {
                Movie  = movie,
                Actors = _context.Actors.ToList()
            };

            return(View(viewModel));
        }
예제 #4
0
        public IActionResult AddActor(AddActorViewModel vM)
        {
            if (!this.ModelState.IsValid)
            {
                return(View());
            }

            var actors = this.actorsService.GetAll().ToList();

            foreach (var actor in actors)
            {
                if (actor.FirstName.Equals(vM.FirstName, StringComparison.InvariantCultureIgnoreCase) && actor.LastName.Equals(vM.LastName, StringComparison.InvariantCultureIgnoreCase))
                {
                    ViewData["ActorExists"] = "An actor with this name already exists!";
                    return(View(vM));
                }
            }

            this.actorsService.AddActor(vM.FirstName, vM.LastName, vM.Age);

            return(RedirectToAction("Actors", "ManageActors"));
        }
예제 #5
0
 public AddActor()
 {
     InitializeComponent();
     DataContext = new AddActorViewModel(this);
 }