Beispiel #1
0
        public IHttpActionResult PostMovieShowings(MovieShowingDTO movieShowings) // ADD NEW MOVIE SHOWING
        {
            MoviesManager  mvmgr                = new MoviesManager();
            BookingManager bmgr                 = new BookingManager();
            TextResult     httpResponse         = new TextResult("", msg);
            DateTime       convertedShowingDate = new DateTime();


            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            convertedShowingDate = bmgr.DateTimeConverter(movieShowings.MovieShowingTime);
            int?showingExists = mvmgr.CheckIfMovieShowingExists(convertedShowingDate);  // Checks if movieshowing already exists

            if (showingExists != 0)
            {
                httpResponse.ChangeHTTPMessage("Showing already exists on that date!", msg); // http response
                return(httpResponse);
            }
            int?movieId = mvmgr.CheckIfMovieExists(movieShowings.MovieName);

            var movieShowingEntity = mvmgr.AddNewMovieShowing(convertedShowingDate, movieId, movieShowings.LoungeId); // creates movieshowing entity

            try
            {
                db.MovieShowings.Add(movieShowingEntity);
                db.SaveChanges();
            }
            catch
            {
                httpResponse.ChangeHTTPMessage("Movieshowing could not be added!", msg);
                return(httpResponse);
            }

            httpResponse.ChangeHTTPMessage("Movieshowing added!", msg);
            return(httpResponse);
        }
Beispiel #2
0
        public IHttpActionResult DeleteMovies(MovieNameDTO movie) // Deletes movie from db and any related movieshowings
        {
            MoviesManager mmgr        = new MoviesManager();
            int           movieId     = mmgr.CheckIfMovieExists(movie.MovieName);
            Movies        movieEntity = db.Movies.Find(movieId);

            if (movieEntity is null)
            {
                return(NotFound());
            }
            try
            {
                db.MovieShowings.RemoveRange(db.MovieShowings.Where(x => x.movieId == movieId));
                db.Movies.Remove(movieEntity);
                db.SaveChanges();
            } catch
            {
                return(Ok());
            }
            TextResult couldNotDeleteMovieAndShowings = new TextResult("Could not delete movie!", msg);

            return(couldNotDeleteMovieAndShowings);
        }
Beispiel #3
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);
        }