Пример #1
0
        public IHttpActionResult Get(int id)
        {
            Movie movie = MovieRepoStub.ReadById(id);

            if (movie == null)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(movie));
            }
        }
Пример #2
0
        public IHttpActionResult Delete(int id)
        {
            Movie m = MovieRepoStub.ReadById(id);

            if (m == null)
            {
                return(NotFound());
            }

            MovieRepoStub.Delete(m.Id);

            return(Ok());
        }
Пример #3
0
        public IHttpActionResult Add(CreateMovieRequest req)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Movie m = new Movie
            {
                Title  = req.Title,
                Rating = req.Rating
            };

            MovieRepoStub.Create(m);

            return(Created($"movies/get/{m.Id}", m));
        }
Пример #4
0
        public IHttpActionResult Update(UpdateMovieRequest req)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Movie m = MovieRepoStub.ReadById(req.Id);

            if (m == null)
            {
                return(NotFound());
            }

            m.Title  = req.Title;
            m.Rating = req.Rating;
            MovieRepoStub.Update(m);

            return(Ok(m));
        }
Пример #5
0
 public IHttpActionResult All()
 {
     return(Ok(MovieRepoStub.ReadAll()));
 }