Esempio n. 1
0
        public async Task<HttpResponseMessage> PutMovie(int id, Movie movie)
        {
            try
            {
                if (movie.Id != id)
                {
                    throw new ValidationException("Invalid movie ID.");
                }
                if (ModelState.IsValid)
                {
                    await _session.StoreAsync(movie);
                    await _session.SaveChangesAsync();
                }
                else
                {
                    return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
            }
            catch (ValidationException ex)
            {
                return Request.CreateResponse(HttpStatusCode.NotAcceptable, ex.Message);
            }

            return Request.CreateResponse(HttpStatusCode.OK);
        }
Esempio n. 2
0
        public async Task<HttpResponseMessage> PostMovie(Movie movie)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    await _session.StoreAsync(movie);
                    await _session.SaveChangesAsync();

                    HttpResponseMessage result = Request.CreateResponse(HttpStatusCode.Created, movie);
                    result.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = movie.Id }));
                    return result;
                }

                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
            catch (ValidationException ex)
            {
                return Request.CreateResponse(HttpStatusCode.NotAcceptable, ex.Message);
            }
        }
Esempio n. 3
0
 public void PostMovie(Movie movie)
 {
     _session.Store(movie);
     _session.SaveChanges();
 }