Esempio n. 1
0
 /// <summary>
 /// 
 /// </summary>
 /// <returns></returns>
 public List<Movie> ReadAll()
 {
     using (var ctx = new ShopContextConnection())
     {
         return ctx.Movies.Include("Genre").ToList();
     }
 }
Esempio n. 2
0
 public List<Genre> ReadAll()
 {
     using (var ctx = new ShopContextConnection())
     {
         return ctx.Genres.ToList();
     }
 }
Esempio n. 3
0
 public void Add(Movie movie)
 {
     using (var ctx = new ShopContextConnection())
     {
         ctx.Movies.Attach(movie);
         ctx.Movies.Add(movie);
         ctx.SaveChanges();
     }
 }
Esempio n. 4
0
 public void Add(Order order)
 {
     using (var ctx = new ShopContextConnection())
     {
         ctx.Orders.Attach(order);
         ctx.Orders.Add(order);
         ctx.SaveChanges();
     }
 }
Esempio n. 5
0
 public void Add(Genre genre)
 {
     using (var ctx = new ShopContextConnection())
     {
         //Create the queries
         ctx.Genres.Add(genre);
         //Execute the queries
         ctx.SaveChanges();
     }
 }
Esempio n. 6
0
 public void Delete(Movie movie)
 {
     using (var ctx = new ShopContextConnection())
     {
         ctx.Movies.Attach(movie);
         //var thisMovie =  ctx.Movies.Where(x => x.Id == movie.Id).FirstOrDefault();
         ctx.Movies.Remove(movie);
         ctx.SaveChanges();
     }
 }
Esempio n. 7
0
        //public void Edit([Bind(Include = "Id,Title,Year,Price")] Movie movie)
        //{
        //    if (ModelState.IsValid)
        //    {
        //        ctx.Entry(movie).State = EntityState.Modified;
        //        ctx.SaveChanges();
        //        return RedirectToAction("Index");
        //    }
        //}
        public void Edit(Movie movie)
        {
            using (var ctx = new ShopContextConnection())
            {

                //A gift to Lars from KBTZ team. Enjoy!
                var movieDB = ctx.Movies.FirstOrDefault(x => x.Id == movie.Id);
                movieDB.Genre = ctx.Genres.FirstOrDefault(x => x.Id == movie.Genre.Id);
                movieDB.Title = movie.Title;
                movieDB.Price = movie.Price;
                movieDB.Year = movie.Year;
                movieDB.Description = movie.Description;
                movieDB.url = movie.url;
                movieDB.MovieCoverUrl = movie.MovieCoverUrl;

                ctx.SaveChanges();

                //ctx.SaveChanges();

            }
        }