public Movie Add(Movie item) { if (item == null) throw new ArgumentNullException("movie is null"); if (item.Name == null) throw new ArgumentException("FirstName can not be null"); using (Context mCon = new Context()) { if (item.Genres.Count > 0) { List<Genre> temp = new List<Genre>(); bool found = false; foreach (var gen in item.Genres.ToList()) { found = false; foreach (var item2 in mCon.Genres.ToList()) { if (gen.Id == item2.Id) { temp.Add(item2); found = true; } } if (!found) temp.Add(gen); } item.Genres = temp; } item = mCon.Movies.Add(item); mCon.SaveChanges(); } return item; }
public void Remove(int id) { using (Context mCon = new Context()) { OrderMovie ord = mCon.OrderMovie.Where(x => x.Id == id).FirstOrDefault(); mCon.OrderMovie.Remove(ord); mCon.SaveChanges(); } }
public void Remove(int id) { Order temp = Get(id); if (temp == null) throw new ArgumentNullException("Order is null"); using (Context mCon = new Context()) { mCon.Orders.Attach(temp); mCon.Orders.Remove(temp); mCon.SaveChanges(); } }
public void Remove(string username) { Login temp = Get(username); if (temp == null) throw new ArgumentNullException("Login is null"); using (Context mCon = new Context()) { mCon.Login.Attach(temp); mCon.Login.Remove(temp); mCon.SaveChanges(); } }
public Login Add(Login item) { if (item == null) throw new ArgumentNullException("Login cant be null"); using (Context mCon = new Context()) { item.Customer = mCon.Customers.FirstOrDefault(x => x.Id == item.Customer.Id); item = mCon.Login.Add(item); mCon.SaveChanges(); } return item; }
public bool Update(Genre item) { if (item == null) throw new ArgumentNullException("Genre is null"); if (Get(item.Id) == null) return false; using (Context mCon = new Context()) { mCon.Entry(item).State = EntityState.Modified; mCon.SaveChanges(); } return true; }
public Genre Add(Genre item) { if (item == null) throw new ArgumentNullException("Genre is null"); if (item.Name == null) throw new ArgumentException("FirstName can not be null"); using (Context mCon = new Context()) { item = mCon.Genres.Add(item); mCon.SaveChanges(); } return item; }
public OrderMovie Add(OrderMovie item) { if (item == null) throw new ArgumentNullException("Ordermovie can not be null"); using (Context mCon = new Context()) { item.Movie = mCon.Movies.Where(x => x.Id == item.Movie.Id).FirstOrDefault(); item.Order = mCon.Orders.Where(x => x.Id == item.Order.Id).FirstOrDefault(); item = mCon.OrderMovie.Add(item); mCon.SaveChanges(); } return item; }
public Order Add(Order item) { if (item == null) throw new ArgumentNullException("Order is null"); if (item.Customer == null) throw new ArgumentException("Customer can not be null"); using (Context mCon = new Context()) { if (mCon.Customers.FirstOrDefault(x => x.Id == item.Customer.Id) != null) item.Customer = mCon.Customers.FirstOrDefault(x => x.Id == item.Customer.Id); item = mCon.Orders.Add(item); mCon.SaveChanges(); } return item; }
public bool Update(Login item) { if (item == null) throw new ArgumentNullException("Login is null"); if (Get(item.Username) == null) return false; using (Context mCon = new Context()) { Login temp = mCon.Login.FirstOrDefault(x => x.Username == item.Username); temp.Password = item.Password; temp.Customer = item.Customer; mCon.SaveChanges(); } return true; }
public bool Update(OrderMovie item) { if (item == null) throw new ArgumentNullException("OrderMovie is null"); if (Get(item.Id) == null) return false; using (Context mCon = new Context()) { OrderMovie temp = mCon.OrderMovie.FirstOrDefault(x => x.Id == item.Id); temp.Movie = item.Movie; temp.Order = item.Order; mCon.SaveChanges(); } return true; }