public Order Create(Order t)
 {
     using (dbContext = new MovieShopContext())
     {
         dbContext.Entry(t.Movie).State    = EntityState.Unchanged;
         dbContext.Entry(t.Customer).State = EntityState.Unchanged;
         dbContext.Orders.Add(t);
         dbContext.SaveChanges();
         return(t);
     }
 }
Esempio n. 2
0
 public Genre Update(Genre t)
 {
     using (var db = new MovieShopContext())
     {
         db.Entry(t).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         return(t);
     }
 }
Esempio n. 3
0
 public Movie Update(Movie o)
 {
     using (var db = new MovieShopContext())
     {
         db.Entry(o).State = EntityState.Modified;
         db.SaveChanges();
         return(o);
     }
 }
Esempio n. 4
0
 public bool Delete(Movie o)
 {
     using (var db = new MovieShopContext())
     {
         db.Entry(o).State = EntityState.Deleted;
         db.SaveChanges();
         return(Read(o.Id) == null);
     }
 }
Esempio n. 5
0
 public Address Update(Address t)
 {
     using (dbContext)
     {
         dbContext.Entry(t).State = EntityState.Modified;
         dbContext.SaveChanges();
         return(t);
     }
 }
Esempio n. 6
0
 public void Delete(int id)
 {
     using (var db = new MovieShopContext())
     {
         var genreTodelete = db.Genres.FirstOrDefault(x => x.GenreId == id);
         db.Entry(genreTodelete).State = System.Data.Entity.EntityState.Deleted;
         db.SaveChanges();
     }
 }
Esempio n. 7
0
 public bool Remove(Order t)
 {
     using (var db = new MovieShopContext())
     {
         db.Entry(db.Orders.FirstOrDefault(x => x.ID == t.ID)).State = System.Data.Entity.EntityState.Deleted;
         db.SaveChanges();
         return(db.Orders.FirstOrDefault(x => x.ID == t.ID) == null);
     }
 }
 public Genre Update(Genre t)
 {
     using (var dbContext = new MovieShopContext())
     {
         dbContext.Entry(t).State = EntityState.Modified;
         dbContext.SaveChanges();
         return(t);
     }
 }
 public Addresses Update(Addresses o)
 {
     using (var db = new MovieShopContext())
     {
         db.Entry(o).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         return(o);
     }
 }
Esempio n. 10
0
 public bool Remove(Movie t)
 {
     using (var ctx = new MovieShopContext())
     {
         ctx.Entry(ctx.Movies.FirstOrDefault(x => x.ID == t.ID)).State = System.Data.Entity.EntityState.Deleted;
         ctx.SaveChanges();
         return(ctx.Movies.FirstOrDefault(x => x.ID == t.ID) == null);
     }
 }
 public bool Delete(Addresses o)
 {
     using (var db = new MovieShopContext())
     {
         db.Entry(o).State = System.Data.Entity.EntityState.Deleted;
         db.SaveChanges();
         return(Read(o.Id) == null);
     }
 }
Esempio n. 12
0
 public bool Remove(Genre t)
 {
     using (var ctx = new MovieShopContext())
     {
         ctx.Entry(t).State = System.Data.Entity.EntityState.Deleted;
         ctx.SaveChanges();
         return(true);
     }
 }
Esempio n. 13
0
 public void Delete(int id)
 {
     using (var db = new MovieShopContext())
     {
         var customerTodelete = db.Customers.FirstOrDefault(x => x.CustomerId == id);
         db.Entry(customerTodelete).State = System.Data.Entity.EntityState.Deleted;
         db.SaveChanges();
     }
 }
Esempio n. 14
0
 public ActionResult Edit([Bind(Include = "Id,Street,Number,ZipCode,Country")] Address address)
 {
     if (ModelState.IsValid)
     {
         db.Entry(address).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(address));
 }
Esempio n. 15
0
 public ActionResult Edit([Bind(Include = "ID,Name")] Genre genre)
 {
     if (ModelState.IsValid)
     {
         db.Entry(genre).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(genre));
 }
 public Movie Update(Movie t)
 {
     using (var dbContext = new MovieShopContext())
     {
         t.Genre = dbContext.Genres.Include("Movies").FirstOrDefault(x => x.Id == t.Genre.Id);
         var oldMovie = dbContext.Movies.FirstOrDefault(x => x.Id == t.Id);
         oldMovie.Genre = t.Genre;
         dbContext.Entry(oldMovie).CurrentValues.SetValues(t);
         dbContext.SaveChanges();
         return(t);
     }
 }
Esempio n. 17
0
 public Customer Update(Customer t)
 {
     using (dbContext = new MovieShopContext())
     {
         var oldCustomer = dbContext.Customers.FirstOrDefault(x => x.Id == t.Id);
         if (oldCustomer != null)
         {
             oldCustomer.Address = t.Address;
             dbContext.Entry(oldCustomer).CurrentValues.SetValues(t);
             dbContext.SaveChanges();
         }
         return(t);
     }
 }
Esempio n. 18
0
        public Customer Update(Customer t)
        {
            using (var db = new MovieShopContext())
            {
                var foundCustomer = db.Customers.Include(x => x.Address).FirstOrDefault(x => x.CustomerId == t.CustomerId);

                db.Entry(foundCustomer).CurrentValues.SetValues(t);
                foundCustomer.Address = t.Address;
                // db.Entry(t).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();


                return(t);
            }
        }
Esempio n. 19
0
        public bool Delete(int id)
        {
            using (MovieShopContext movieShopContext = new MovieShopContext())
            {
                T entity = this.ReadOne(id, movieShopContext);

                if (entity == null)
                {
                    throw new EntityNotFoundException($"The following entity were not found: {typeof(T).Name}");
                }

                movieShopContext.Entry(entity).State = EntityState.Deleted;
                movieShopContext.SaveChanges();

                return(true);
            }
        }
 public Order Update(Order t)
 {
     using (dbContext = new MovieShopContext())
     {
         var oldOrder = dbContext.Orders.FirstOrDefault(x => x.Id == t.Id);
         if (oldOrder != null)
         {
             if (t.Customer != null)
             {
                 oldOrder.Customer = dbContext.Customers.FirstOrDefault(x => x.Id == t.Customer.Id);
             }
             oldOrder.Movie = dbContext.Movies.FirstOrDefault(x => x.Id == t.Movie.Id);
             dbContext.Entry(oldOrder).CurrentValues.SetValues(t);
             dbContext.SaveChanges();
         }
         return(dbContext.Orders.FirstOrDefault(x => x.Id == t.Id));
     }
 }
Esempio n. 21
0
        public void Edit(Movie movie)
        {
            using (var ctx = new MovieShopContext())
            {
                if (movie == null)
                {
                    throw new ArgumentNullException("movie");
                }
                List <Genre>    ge       = new List <Genre>();
                GenreRepository genrerep = new GenreRepository();
                Genre           g;
                for (int i = 0; i < movie.Genres.Count(); ++i)
                {
                    g = genrerep.Find(movie.Genres.ElementAt(i).Id);
                    movie.Genres.ElementAt(i).Name = g.Name;
                }
                ctx.Entry(movie).State = EntityState.Modified;
                ctx.SaveChanges();


                ////

                //var movieDB = ctx.Movies.FirstOrDefault(x => x.Id == movie.Id);

                //for (int i = 0; i < movie.Genres.Count(); ++i)
                //{
                //    movie.Genres.CopyTo(movieDB.Genres.ToList(),0);
                //    movieDB.Genres.Add(movie.Genres.ElementAt(i));
                //}

                //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();
            }
        }
Esempio n. 22
0
        public T Update(T entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException($"The given {typeof(T).Name} can't be null");
            }

            using (MovieShopContext movieShopContext = new MovieShopContext())
            {
                //We are using AsNoTracking and using a locally call to the database through the context,
                //because we do not want entity framework to track that we load a entity.
                T existingEntity = movieShopContext.Set <T>().AsNoTracking().FirstOrDefault(x => x.Id == entity.Id);

                if (existingEntity == null)
                {
                    throw new EntityNotFoundException($"The following entity were not found: {typeof(T).Name}");
                }

                movieShopContext.Entry(entity).State = EntityState.Modified;
                movieShopContext.SaveChanges();

                return(entity);
            }
        }
Esempio n. 23
0
 public override Movie Update(MovieShopContext db, Movie movie)
 {
     db.Entry(movie).State = EntityState.Modified;
     db.SaveChanges();
     return(movie);
 }
Esempio n. 24
0
 public override void Delete(MovieShopContext db, int id)
 {
     db.Entry(db.Orders.FirstOrDefault(x => x.Id == id)).State = EntityState.Deleted;
     db.SaveChanges();
 }
Esempio n. 25
0
 public override Order Update(MovieShopContext db, Order order)
 {
     db.Entry(order).State = EntityState.Modified;
     db.SaveChanges();
     return(order);
 }
Esempio n. 26
0
 public override Genre Update(MovieShopContext db, Genre genre)
 {
     db.Entry(genre).State = EntityState.Modified;
     db.SaveChanges();
     return(genre);
 }
Esempio n. 27
0
 public override Address Update(MovieShopContext db, Address address)
 {
     db.Entry(address).State = EntityState.Modified;
     db.SaveChanges();
     return(address);
 }
Esempio n. 28
0
 public override Customer Update(MovieShopContext db, Customer customer)
 {
     db.Entry(customer).State = EntityState.Modified;
     db.SaveChanges();
     return(customer);
 }