public void AddIngredient(Ingredient ingredient)
 {
     using (var currentContext = new PizzaSericeContext())
     {
         currentContext.Ingredients.Add(ingredient);
         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 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();
     }
 }
Пример #4
0
 public void CreateIngredient(Ingredient ingredient)
 {
     IngredientRepository.Instance.AddIngredient(ingredient);
 }