Ejemplo n.º 1
0
 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 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 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();
     }
 }
Ejemplo n.º 4
0
 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();
     }
 }
Ejemplo n.º 5
0
 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 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 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 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();
     }
 }
 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 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();
     }
 }
Ejemplo n.º 11
0
 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();
     }
 }
Ejemplo n.º 12
0
 public void DeleteOrder(Order order)
 {
     using (var currentContext = new PizzaSericeContext())
     {
         currentContext.Orders.Attach(order);
         currentContext.Entry(order).State = EntityState.Deleted;
         currentContext.SaveChanges();
     }
 }