public bool DeletePizza(Pizza pizza) { bool result = false; using (DAL.DbContext db = new DAL.DbContext()) { var dbPizza = db.Pizzas.FirstOrDefault(u => u.Name.Equals(pizza.Name)); db.Pizzas.Remove(dbPizza); result = db.Save(); } return(result); }
public bool DeleteTopping(Topping topping) { bool result = false; using (DAL.DbContext db = new DAL.DbContext()) { var dbTopping = db.Toppings.FirstOrDefault(u => u.Name.Equals(topping.Name)); db.Toppings.Remove(dbTopping); result = db.Save(); } return(result); }
public bool AddTopping(Topping topping) { bool result = false; using (DAL.DbContext db = new DAL.DbContext()) { db.Toppings.Add(new DAL.Topping() { Name = topping.Name }); result = db.Save(); } return(result); }
public bool AddPizza(Pizza pizza) { bool result = false; using (DAL.DbContext db = new DAL.DbContext()) { var newPizza = new DAL.Pizza() { Name = pizza.Name }; db.Pizzas.Add(newPizza); result = db.Save(); } return(result); }
public bool DeleteToppingFromPizza(Topping topping, Pizza pizza) { bool result = false; using (DAL.DbContext db = new DAL.DbContext()) { var dbPizza = db.Pizzas.FirstOrDefault(u => u.Name.Equals(pizza.Name)); var dbTopping = db.Toppings.FirstOrDefault(u => u.PizzaId == dbPizza.Id && u.Name == topping.Name); if (dbTopping != null) { dbTopping.PizzaId = null; result = db.Save(); } } return(result); }
public bool AddTopping(Topping topping, Pizza pizza) { bool result = false; using (DAL.DbContext db = new DAL.DbContext()) { var dbPizza = db.Pizzas.FirstOrDefault(u => u.Name == pizza.Name); if (dbPizza != null) { if (db.Toppings.Any(u => u.PizzaId == dbPizza.Id && u.Name == topping.Name)) { result = false; } else { var dbTopping = db.Toppings.FirstOrDefault(u => u.Name == topping.Name); if (dbTopping == null) { db.Toppings.Add(new DAL.Topping() { Name = topping.Name, PizzaId = dbPizza.Id }); } else { dbTopping.PizzaId = dbPizza.Id; } result = db.Save(); } } } return(result); }