Example #1
0
        public IHttpActionResult PostMovies(Movies movies) // ADD NEW MOVIE TO DATABASE
        {
            TextResult    httpResponse = new TextResult("Movie added!", msg);
            MoviesManager mvmgr        = new MoviesManager();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            int movieExists = mvmgr.CheckIfMovieExists(movies.movieName); // returns 0 if movie exists

            if (movieExists != 0)
            {
                httpResponse.ChangeHTTPMessage("Movie already exists!", msg);
                return(httpResponse);
            }
            var movieEntity = mvmgr.AddNewMovie(movies.movieName);

            db.Movies.Add(movieEntity);
            db.SaveChanges();

            return(httpResponse);
        }