public void AddCartIngredient(int id) { using (var currentContext = new PizzaSericeContext()) { if (currentContext.CartIngredients.Where(x => x.VendorIngredientId == id).ToList().Count < 1) { currentContext.CartIngredients.Add(new CartIngredient { VendorIngredientId = id, Count = 1}); currentContext.SaveChanges(); } else { currentContext.CartIngredients.Where(x => x.VendorIngredientId == id).FirstOrDefault().Count += 1; currentContext.SaveChanges(); } } }
public void AddIngredient(Ingredient ingredient) { using (var currentContext = new PizzaSericeContext()) { currentContext.Ingredients.Add(ingredient); currentContext.SaveChanges(); } }
public void AddVendor(Vendor vendor) { using (var currentContext = new PizzaSericeContext()) { currentContext.Vendors.Add(vendor); currentContext.SaveChanges(); } }
public void AddRole(Role role) { using (var currentContext = new PizzaSericeContext()) { currentContext.Roles.Add(role); currentContext.SaveChanges(); } }
public void AddPizza(Pizza pizza) { using (var currentContext = new PizzaSericeContext()) { currentContext.Pizzas.Add(pizza); currentContext.SaveChanges(); } }
public void AddUser(ServiceUser user) { using (var currentContext = new PizzaSericeContext()) { currentContext.ServiceUsers.Add(user); currentContext.SaveChanges(); } }
public void AddOrder(Order order) { using (var currentContex = new PizzaSericeContext()) { currentContex.Orders.Add(order); currentContex.SaveChanges(); } }
public void DeleteVendor(int id) { using (var currentContext = new PizzaSericeContext()) { Vendor vendor = currentContext.Vendors.Find(id); currentContext.Vendors.Remove(vendor); currentContext.SaveChanges(); } }
public void DeleteIngredient(int id) { using (var currentContext = new PizzaSericeContext()) { Ingredient ingredient = currentContext.Ingredients.Find(id); currentContext.Ingredients.Remove(ingredient); currentContext.SaveChanges(); } }
public void DeleteRole(int roleId) { using (var context = new PizzaSericeContext()) { Role role = GetRoleById(roleId); context.Roles.Attach(role); context.Entry(role).State = System.Data.Entity.EntityState.Deleted; context.SaveChanges(); } }
public void UpdateStock(int id, int count) { using (var currentContext = new PizzaSericeContext()) { StockIngredient currentIngredient = GetIngredientWithCountById(id); currentIngredient.Count -= count; currentContext.Entry(currentIngredient).State = System.Data.Entity.EntityState.Modified; currentContext.SaveChanges(); } }
public void DecrementPrice(int pizzaId, int price) { using (var currentContext = new PizzaSericeContext()) { Pizza currentPizza = GetPizzaById(pizzaId); currentPizza.Price -= price; currentContext.Entry(currentPizza).State = System.Data.Entity.EntityState.Modified; currentContext.SaveChanges(); } }
public void DecrementCount(int orderId, int pizzaId) { using (var currentContext = new PizzaSericeContext()) { PizzaToOrder pizzaToOrder = GetPizzaToOrderById(orderId, pizzaId); pizzaToOrder.Count--; currentContext.Entry(pizzaToOrder).State = EntityState.Modified; currentContext.SaveChanges(); } }
public void AddPrice(int orderId, int price) { using (var currentContext = new PizzaSericeContext()) { Order currentOrder = GetOrderById(orderId); currentOrder.Price += price; currentContext.Entry(currentOrder).State = EntityState.Modified; currentContext.SaveChanges(); } }
public void EditUserRole(int userId, Role role) { using (var context = new PizzaSericeContext()) { ServiceUser user = GetUserById(userId); user.RoleId = role.Id; context.ServiceUsers.Attach(user); context.Entry(user).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } }
public void RefillStock(IEnumerable<CartViewItem> items) { using (var currentContext = new PizzaSericeContext()) { foreach (var item in items) { currentContext.StockIngredients.Where(x => x.Ingredient.Name == item.IngredientName).FirstOrDefault().Count += item.Count; } currentContext.SaveChanges(); } }
public void ClearCart() { using (var currentContext = new PizzaSericeContext()) { foreach(var i in currentContext.CartIngredients.ToList()) { currentContext.CartIngredients.Remove(i); } currentContext.SaveChanges(); } }
public void AddPizzaToOrder(int userId, Pizza pizza) { using (var currentContext = new PizzaSericeContext()) { Order currentOrder = GetUnConfirmedOrder(userId); if (currentOrder == null) { currentOrder = new Order { UserId = userId, Price = 0, IsConfirmed = false }; AddOrder(currentOrder); } PizzaToOrderRepository.Instance.AddPizzaToOrder(currentOrder.Id, pizza); AddPrice(currentOrder.Id, pizza.Price); currentContext.SaveChanges(); } }
public void DeleteFromCart(VendorIngredientItem item) { using (var currentContext = new PizzaSericeContext()) { var cartItem = currentContext.CartIngredients .Where(x => x.VendorIngredient.Vendor.Name == item.VendorName && x.VendorIngredient.Ingredient.Name == item.IngredientName).FirstOrDefault(); cartItem.VendorIngredient = currentContext.VendorIngredients.Where(x => x.Id == cartItem.VendorIngredientId).FirstOrDefault(); if ( cartItem.Count > 1) cartItem.Count -= 1; else currentContext.CartIngredients.Remove(cartItem); currentContext.SaveChanges(); } }
public void AddPizzaToOrder(int orderId, Pizza pizza) { PizzaToOrder pizzaToOrder = GetPizzaToOrderById(orderId, pizza.Id); using (var currentContext = new PizzaSericeContext()) { if (pizzaToOrder == null) { currentContext.PizzaToOrders.Add(new PizzaToOrder { OrderId = orderId, PizzaId = pizza.Id, Count = 1 }); } else IncrementCount(orderId, pizza.Id); currentContext.SaveChanges(); } }
public void DecrementCount(int userId, int pizzaId, int ingredientId) { using (var currentContext = new PizzaSericeContext()) { PizzaIngredient pizzaIngredient = GetPizzaIngredientById(pizzaId, ingredientId); Ingredient ingredient = IngredientRepository.Instance.GetIngredientById(ingredientId); Order currentOrder = OrderRepository.Instance.GetUnConfirmedOrder(userId); if (pizzaIngredient.Count == 1) { DeleteIngredient(userId, pizzaId, ingredient); OrderRepository.Instance.DecrementPrice(currentOrder.Id, ingredient.Price); return; } pizzaIngredient.Count--; OrderRepository.Instance.DecrementPrice(currentOrder.Id, ingredient.Price); currentContext.Entry(pizzaIngredient).State = EntityState.Modified; currentContext.SaveChanges(); } }
public void AddPizzaIngredient(int userId, int pizzaId, Ingredient ingredient) { using (var currentContext = new PizzaSericeContext()) { PizzaIngredient pizzaIngredient = GetPizzaIngredientById(pizzaId, ingredient.Id); Order currentOrder = OrderRepository.Instance.GetUnConfirmedOrder(userId); if (pizzaIngredient == null) { currentContext.PizzaIngredients.Add(new PizzaIngredient { PizzaId = pizzaId, IngredientId = ingredient.Id, Count = 1 }); OrderRepository.Instance.AddPrice(currentOrder.Id, ingredient.Price); } else IncrementCount(userId, pizzaId, ingredient.Id); PizzaRepository.Instance.AddPrice(pizzaId, ingredient.Price); currentContext.SaveChanges(); } }
public void IncrementCount(int userId, int pizzaId, int ingredientId) { PizzaIngredient pizzaIngredient = GetPizzaIngredientById(pizzaId, ingredientId); Ingredient ingredient = IngredientRepository.Instance.GetIngredientById(ingredientId); Order currentOrder = OrderRepository.Instance.GetUnConfirmedOrder(userId); using (var currentContext = new PizzaSericeContext()) { pizzaIngredient.Count++; OrderRepository.Instance.AddPrice(currentOrder.Id, ingredient.Price); currentContext.Entry(pizzaIngredient).State = EntityState.Modified; currentContext.SaveChanges(); } }
public void DeleteOrder(Order order) { using (var currentContext = new PizzaSericeContext()) { currentContext.Orders.Attach(order); currentContext.Entry(order).State = EntityState.Deleted; currentContext.SaveChanges(); } }
public void ConfirmOrder(int userId) { using (var currentContext = new PizzaSericeContext()) { Order order = GetUnConfirmedOrder(userId); order.IsConfirmed = true; currentContext.Entry(order).State = EntityState.Modified; currentContext.SaveChanges(); } }
public void DeleteIngredient(int userId, int pizzaId, Ingredient ingredient) { using (var currentContext = new PizzaSericeContext()) { PizzaIngredient pizzaIngredient = GetPizzaIngredientById(pizzaId, ingredient.Id); Order currentOrder = OrderRepository.Instance.GetUnConfirmedOrder(userId); currentContext.PizzaIngredients.Attach(pizzaIngredient); currentContext.Entry(pizzaIngredient).State = EntityState.Deleted; PizzaRepository.Instance.DecrementPrice(pizzaId, ingredient.Price); OrderRepository.Instance.DecrementPrice(currentOrder.Id, ingredient.Price); currentContext.SaveChanges(); } }
public void DeleteOrderPizza(int orderId, Pizza pizza) { using (var currentContext = new PizzaSericeContext()) { PizzaToOrder pizzaToOrder = GetPizzaToOrderById(orderId, pizza.Id); if (pizzaToOrder.Count == 1) { currentContext.PizzaToOrders.Attach(pizzaToOrder); currentContext.Entry(pizzaToOrder).State = EntityState.Deleted; } else DecrementCount(orderId, pizza.Id); OrderRepository.Instance.DecrementPrice(orderId, pizza.Price); currentContext.SaveChanges(); } }