Exemplo n.º 1
0
 public Movie Create(Movie movie)
 {
     var dbItem = new Models.Movie();
     Map(movie, dbItem);
     db.Movies.Add(dbItem);
     db.SaveChanges();
     return MapAll(new Models.Movie[] { dbItem }.AsQueryable()).Single();
 }
Exemplo n.º 2
0
 public bool Update(Movie movie)
 {
     var dbItem = db.Movies.Find(movie.ID);
     if (dbItem == null) return false;
     Map(movie, dbItem);
     db.SaveChanges();
     return true;
 }
Exemplo n.º 3
0
 public int Create(Movie movie)
 {
     var dbItem = new Models.Movie();
     Map(movie, dbItem);
     db.Movies.Add(dbItem);
     db.SaveChanges();
     return dbItem.ID;
 }
Exemplo n.º 4
0
 public HttpResponseMessage Post(Movie movie)
 {
     var newMovie = service.Create(movie);
     var response = Request.CreateResponse(HttpStatusCode.Created, newMovie);
     var url = Url.Link("DefaultApi", new{id=newMovie.ID});
     var uri = new Uri(url);
     response.Headers.Location = uri;
     return response;
 }
Exemplo n.º 5
0
        public HttpResponseMessage Put(int id, Movie movie)
        {
            if (ModelState.IsValid)
            {
                movie.ID = id;
                if (!service.Update(movie)) return Request.CreateResponse(HttpStatusCode.NotFound);
                return Request.CreateResponse(HttpStatusCode.NoContent);
            }

            return Request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
        }
Exemplo n.º 6
0
        void Map(Movie movie, Models.Movie dbItem)
        {
            var director = db.Directors.FirstOrDefault(d => d.Name == movie.Director);
            var country = db.Countries.FirstOrDefault(c => c.Name == movie.Country);
            var genres = db.Genres.Where(g => movie.Genres.Contains(g.Name));

            dbItem.Title = movie.Title;
            dbItem.Description = movie.Description;
            dbItem.Rating = movie.Rating;
            dbItem.Year = movie.YearReleased;
            dbItem.Director = director;
            dbItem.Country = country;
            dbItem.Genres = genres.ToList();
        }
Exemplo n.º 7
0
        void Map(Movie movie, Models.Movie dbItem)
        {
            var director = db.Directors.FirstOrDefault(d => d.Name == movie.Director);
            if (director == null && !String.IsNullOrWhiteSpace(movie.Director))
            {
                director = new Models.Director(){Name = movie.Director};
            }
            var country = db.Countries.FirstOrDefault(c => c.Name == movie.Country);
            if (country == null)
            {
                country = new Models.Country(){Name = movie.Country};
            }

            dbItem.Title = movie.Title;
            dbItem.Description = movie.Description;
            dbItem.Rating = movie.Rating;
            dbItem.Year = movie.YearReleased;
            dbItem.Director = director;
            dbItem.Country = country;
        }
Exemplo n.º 8
0
 public void Put(int id, Movie movie)
 {
     service.Update(movie);
 }
Exemplo n.º 9
0
 public void Post(Movie movie)
 {
     service.Create(movie);
 }