public Movie CreateMovie(ODataActionParameters parameters)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            string title = parameters["Title"] as string;

            Movie movie = new Movie()
            {
                Title = title
            };

            try
            {
                db.Movies.Add(movie);
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
            return movie;
        }
Ejemplo n.º 2
0
        public IHttpActionResult CreateMovie(ODataActionParameters parameters)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            string title = parameters["Title"] as string;

            Movie movie = new Movie()
            {
                Title = title,
                ID = _db.Movies.Count + 1,
            };

            _db.Movies.Add(movie);

            return Created(movie);
        }
Ejemplo n.º 3
0
 private bool TryCheckoutMovie(Movie movie)
 {
     if (movie.IsCheckedOut)
     {
         return false;
     }
     else
     {
         // To check out a movie, set the due date.
         movie.DueDate = DateTime.Now.AddDays(7);
         return true;
     }
 }