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); } }
public Genre Update(Genre t) { using (var db = new MovieShopContext()) { db.Entry(t).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(t); } }
public Movie Update(Movie o) { using (var db = new MovieShopContext()) { db.Entry(o).State = EntityState.Modified; db.SaveChanges(); return(o); } }
public bool Delete(Movie o) { using (var db = new MovieShopContext()) { db.Entry(o).State = EntityState.Deleted; db.SaveChanges(); return(Read(o.Id) == null); } }
public Address Update(Address t) { using (dbContext) { dbContext.Entry(t).State = EntityState.Modified; dbContext.SaveChanges(); return(t); } }
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(); } }
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); } }
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); } }
public bool Remove(Genre t) { using (var ctx = new MovieShopContext()) { ctx.Entry(t).State = System.Data.Entity.EntityState.Deleted; ctx.SaveChanges(); return(true); } }
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(); } }
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)); }
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); } }
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); } }
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); } }
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)); } }
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(); } }
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); } }
public override Movie Update(MovieShopContext db, Movie movie) { db.Entry(movie).State = EntityState.Modified; db.SaveChanges(); return(movie); }
public override void Delete(MovieShopContext db, int id) { db.Entry(db.Orders.FirstOrDefault(x => x.Id == id)).State = EntityState.Deleted; db.SaveChanges(); }
public override Order Update(MovieShopContext db, Order order) { db.Entry(order).State = EntityState.Modified; db.SaveChanges(); return(order); }
public override Genre Update(MovieShopContext db, Genre genre) { db.Entry(genre).State = EntityState.Modified; db.SaveChanges(); return(genre); }
public override Address Update(MovieShopContext db, Address address) { db.Entry(address).State = EntityState.Modified; db.SaveChanges(); return(address); }
public override Customer Update(MovieShopContext db, Customer customer) { db.Entry(customer).State = EntityState.Modified; db.SaveChanges(); return(customer); }