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);
        }