Example #1
0
        [Route("MoviesAPI/Movies/Delete-Movie/{MovieID}")] //accept any entered 'id' then check if int
        public ActionResult <Movie> DeleteById([FromRoute] int MovieID)
        {
            if (!Validation.ValidateID(MovieID))
            {
                return(BadRequest(new { message = "invalid MovieID, please provide ID greater than 0" }));
            }

            Console.WriteLine($"user requested deletion of movie with MovieID: {MovieID}");
            try
            {
                //    if (result == 1)
                //    {
                //        Console.WriteLine("movie successfully deleted");
                //        return Ok(result);
                //    }
                //    else
                //    {
                //        Console.WriteLine("user requested movie does not exist");
                //        return NotFound(new { message = "Movie not found" });
                //    }

                //}
                Console.WriteLine("movie successfully deleted");
                List <Movie> res = movieRepository.DeleteMovieFromDB(MovieID);
                return(Ok(res));
            }
            catch (SqlException error)
            {
                Console.WriteLine("something went wrong");
                return(StatusCode(500, error.ToString()));
            }
        }