private static void AddManyToManyObject()
        {
            var context = new MoviesContext();
            var actor   = new Actor {
                Name = "Engelbert Humperdinck", Birthday = new DateTime(1936, 5, 2), Nationality = "British"
            };
            var movie = context.Movies.Find(6);

            context.Add(actor);
            context.Add(new MovieActor {
                Movie = movie, Actor = actor
            });
            context.SaveChanges();
        }
예제 #2
0
        public async Task <IActionResult> Post([FromBody] Movie movie)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Add(movie);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (MovieExists(movie.Id))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("Get", new { id = movie.Id }, movie));
        }
예제 #3
0
        public ActorDto AddActor(ActorDto actorDto)
        {
            var actor = _context.Add((object)_mapper.Map <Actor>(actorDto)).Entity;

            _context.SaveChanges();
            return(_mapper.Map <ActorDto>(actor));
        }
예제 #4
0
        public MovieDto AddMovie(MovieDto movieDto)
        {
            var movie = _context.Add(_mapper.Map <Movie>(movieDto)).Entity;

            _context.SaveChanges();
            return(_mapper.Map <MovieDto>(movie));
        }
예제 #5
0
        public ActionResult <InputActorViewModel> PostActor(InputActorViewModel inputModel)
        {
            var actor = _context.Add(_mapper.Map <Actor>(inputModel)).Entity;

            _context.SaveChanges();
            return(CreatedAtAction("GetActorById", new { id = actor.Id }, _mapper.Map <InputMovieViewModel>(inputModel)));
        }
예제 #6
0
 public void CreateMovie(Movie movietoCreate)
 {
     if (movietoCreate == null)
     {
         throw new ArgumentNullException(nameof(movietoCreate));
     }
     _context.Add(movietoCreate);
 }
예제 #7
0
        [HttpPost] // POST: api/movies
        public ActionResult <InputMovieViewModel> PostMovie(InputMovieViewModel inputModel)
        {
            var movie = _context.Add(_mapper.Map <Movie>(inputModel)).Entity;

            _context.SaveChanges();

            return(CreatedAtAction("GetById", new { id = movie.Id }, _mapper.Map <InputMovieViewModel>(inputModel)));
        }
예제 #8
0
 public IActionResult Create([Bind("Title,ReleaseDate,Genre,Price")] InputMovieViewModel inputModel)
 {
     if (ModelState.IsValid)
     {
         _context.Add(_mapper.Map <Movie>(inputModel));
         _context.SaveChanges();
     }
     return(View(inputModel));
 }
예제 #9
0
        public void AddMovie(Movie movieToAdd)
        {
            if (movieToAdd == null)
            {
                throw new ArgumentNullException(nameof(movieToAdd));
            }

            _context.Add(movieToAdd);
        }
예제 #10
0
        public async Task <IActionResult> Create([Bind("MovieComingSoonId,ImageUrl,LongDescription,ShortDescription,Title")] MovieComingSoon movieComingSoon)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movieComingSoon);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(movieComingSoon));
        }
        public async Task <IActionResult> Create([Bind("ID,title,release")] Movies movies)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movies);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(movies));
        }
예제 #12
0
        public async Task <IActionResult> Create([Bind("MovieID,Category,Title,Year,Director,Rating,Edited,LentTo,Notes")] Movies movies)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movies);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(EnteredList)));
            }
            return(View(movies));
        }
예제 #13
0
        public async Task <IActionResult> Create([Bind("CineplexId,ImageUrl,Location,LongDescription,ShortDescription")] Cineplex cineplex)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cineplex);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(cineplex));
        }
예제 #14
0
        private static void AddTomato()
        {
            var context = new MoviesContext();
            var movie   = context.Movies.Find(6);
            var tomato  = new TomatoRating {
                MovieId = movie.Id, TomatoMeter = 74, AudienceScore = 95
            };

            context.Add(tomato);
            context.SaveChanges();
        }
예제 #15
0
        public async Task <IActionResult> Create([Bind("Id,Title,Description,Year,Poster")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movie);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(movie));
        }
예제 #16
0
        public async Task <IActionResult> Create([Bind("Id,Title,ReleaseDate,Genre,Price, Rating")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movie);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(movie));
        }
예제 #17
0
        public IActionResult Create([Bind("Id,Name,LastName,Birthday")] InputActorViewModel inputModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(_mapper.Map <InputActorViewModel, Actor>(inputModel));
                _context.SaveChanges();
                return(RedirectToAction(nameof(Index)));
            }

            return(View(inputModel));
        }
예제 #18
0
        public async Task <IActionResult> Create([Bind("EnquiryId,Email,Message")] Enquiry enquiry)
        {
            if (ModelState.IsValid)
            {
                _context.Add(enquiry);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(enquiry));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,ReleaseDate,Director,Email,Language,Category")] MovieTble movieTble)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movieTble);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Category"] = new SelectList(_context.CategoryTble, "Code", "Code", movieTble.Category);
            return(View(movieTble));
        }
 public bool AddNewMovie(MovieTable movie)
 {
     try
     {
         _db.Add(movie);
         _db.SaveChanges();
         return(true);
     }
     catch (DbException e)
     {
         return(false);
     }
 }
예제 #21
0
        public async Task <bool> AddAsync(Movie movie)
        {
            if (movie == null)
            {
                return(false);
            }

            context_.Add(movie);

            await context_.SaveChangesAsync();

            return(true);
        }
예제 #22
0
        public async Task <IActionResult> Create([Bind("CineplexId,MovieId,SessionId")] CineplexMovie cineplexMovie)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cineplexMovie);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewData["CineplexId"] = new SelectList(_context.Cineplex, "CineplexId", "Location", cineplexMovie.CineplexId);
            ViewData["MovieId"]    = new SelectList(_context.Movie, "MovieId", "LongDescription", cineplexMovie.MovieId);
            ViewData["SessionId"]  = new SelectList(_context.SessionMovie, "SessionId", "SessionId", cineplexMovie.SessionId);
            return(View(cineplexMovie));
        }
예제 #23
0
        public IActionResult Create([Bind("Title,ReleaseDate,Genre,Price")]
                                    InputMovieViewModel inputModel)
        {
            if (ModelState.IsValid)
            {
                var movie = _mapper.Map <InputMovieViewModel, Movie>(inputModel);
                _context.Add(movie);
                _context.SaveChanges();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(inputModel));
        }
예제 #24
0
        public IActionResult Create([Bind("Name,FirstName,DateOfBirth")] ActorViewModel inputModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(new Actor
                {
                    Name        = inputModel.Name,
                    FirstName   = inputModel.FirstName,
                    DateOfBirth = inputModel.DateOfBirth
                });
                _context.SaveChanges();
                return(RedirectToAction(nameof(Index)));
            }

            return(View(inputModel));
        }
예제 #25
0
        public IActionResult Create([Bind("Name,LastName,BirthDate")] InputActorViewModel inputModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(new Actor
                {
                    Name      = inputModel.Name,
                    LastName  = inputModel.LastName,
                    BirthDate = inputModel.BirthDate
                });
                _context.SaveChanges();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(inputModel));
        }
예제 #26
0
        public IActionResult Create([Bind("Title,ReleaseDate,Genre,Price")] InputMovieViewModel inputModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(new Movie
                {
                    Genre       = inputModel.Genre,
                    Price       = inputModel.Price,
                    Title       = inputModel.Title,
                    ReleaseDate = inputModel.ReleaseDate
                });
                _context.SaveChanges();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(inputModel));
        }
예제 #27
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            using (var db = new MoviesContext())
            {
                // Create
                Console.WriteLine("Inserting a new blog");
                db.Add(new Movie {
                    Name = "The Martian"
                });
                db.SaveChanges();

                // Read
                Console.WriteLine("Querying for a blog");
                var movie = db.Movies
                            .OrderBy(b => b.MovieId)
                            .First();
                Console.WriteLine(movie.Name);


                // Update
                Console.WriteLine("Updating the movie and adding an actor");
                //movie.Name = "The Martian";
                movie.Actors.Add(
                    new Actor
                {
                    Name    = "John",
                    Surname = "Williams"
                });
                db.SaveChanges();

                // Delete
                //Console.WriteLine("Delete the blog");
                //db.Remove(blog);
                //db.SaveChanges();
            }
        }
        public async Task <ActionResult> CreateMovie(CreateMovieDto createMovie)
        {
            var movie = new Movie {
                MovieName = createMovie.Name,
                Year      = createMovie.Year,
                Genre     = createMovie.Genre,
            };

            if (createMovie.ActorIds != null)
            {
                movie.MovieActors = new List <MovieActor>();
                foreach (var actor in createMovie.ActorIds)
                {
                    var actorToAdd = new MovieActor {
                        MovieId = movie.Id, ActorId = actor
                    };
                    movie.MovieActors.Add(actorToAdd);
                }
            }
            context.Add(movie);
            await context.SaveChangesAsync();

            return(CreatedAtAction("GetMovie", new { id = movie.Id }, movie));
        }
예제 #29
0
 public void Add(Movie movie)
 {
     _context.Add(movie);
 }