示例#1
0
 public IEnumerable<Shift> GetAllShifts()
 {
     using (var context = new PizzaSericeContext())
     {
         return context.Shifts.ToList();
     }
 }
 public VendorIngredient GetVendorIngredientById(int id)
 {
     using (var currentContext = new PizzaSericeContext())
     {
         return currentContext.VendorIngredients.Where(x => x.Id == id).FirstOrDefault();
     }
 }
示例#3
0
 public StockIngredient GetIngredientWithCountById(int id)
 {
     using (var currentContext = new PizzaSericeContext())
     {
         return currentContext.StockIngredients.FirstOrDefault(x => x.IngredientId == id);
     }
 }
 public IEnumerable<Vendor> GetAllVendors()
 {
     using (var currentContext = new PizzaSericeContext())
     {
         return currentContext.Vendors.ToList();
     }
 }
示例#5
0
 public Pizza GetPizzaById(int id)
 {
     using (var currentContext = new PizzaSericeContext())
     {
         return currentContext.Pizzas.Include("PizzaIngredients").FirstOrDefault(x => x.Id == id);
     }
 }
示例#6
0
 public IEnumerable<Pizza> GetAllPizza()
 {
     using (var currentContext = new PizzaSericeContext())
     {
         return currentContext.Pizzas.Include("PizzaIngredients").Where(p => p.IsCustom).ToList();
     }
 }
 public IEnumerable<Role> GetAllRoles()
 {
     using (var context = new PizzaSericeContext())
     {
         return context.Roles.Include("ServiceUsers").ToList();
     }
 }
 public Ingredient GetIngredientById(int id)
 {
     using (var currentcontext = new PizzaSericeContext())
     {
         return currentcontext.Ingredients.Include("StockIngredient").FirstOrDefault(x => x.Id == id);
     }
 }
 public IEnumerable<Ingredient> GetAllIngredients()
 {
     using (var currentContext = new PizzaSericeContext())
     {
         return currentContext.Ingredients.Include("StockIngredient").ToList();
     }
 }
示例#10
0
 public void AddPizza(Pizza pizza)
 {
     using (var currentContext = new PizzaSericeContext())
     {
         currentContext.Pizzas.Add(pizza);
         currentContext.SaveChanges();
     }
 }
示例#11
0
 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 AddUser(ServiceUser user)
 {
     using (var currentContext = new PizzaSericeContext())
     {
         currentContext.ServiceUsers.Add(user);
         currentContext.SaveChanges();
     }
 }
示例#14
0
 public void AddOrder(Order order)
 {
     using (var currentContex = new PizzaSericeContext())
     {
         currentContex.Orders.Add(order);
         currentContex.SaveChanges();
     }
 }
 public void AddIngredient(Ingredient ingredient)
 {
     using (var currentContext = new PizzaSericeContext())
     {
         currentContext.Ingredients.Add(ingredient);
         currentContext.SaveChanges();
     }
 }
示例#16
0
 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();
     }
 }
示例#18
0
        public IEnumerable<VendorIngredient> GetVendorByProductId(int id)
        {
            using (var currentContext = new PizzaSericeContext())
            {
                List<VendorIngredient> vendorIngredients = currentContext.VendorIngredients.Include("Vendor").Where(x => x.IngredientId == id).ToList();

                return vendorIngredients;
            }
        }
 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();
     }
 }
示例#20
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();
     }
 }
示例#21
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();
     }
 }
 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();
     }
 }
示例#23
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 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 ClearCart()
        {
            using (var currentContext = new PizzaSericeContext())
            {

                foreach(var i in currentContext.CartIngredients.ToList())
                {
                    currentContext.CartIngredients.Remove(i);
                }

                currentContext.SaveChanges();
            }
        }
示例#26
0
        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 IEnumerable<Ingredient> GetIngredientsNameByIds(int[] ids)
        {
            using (var currentContext = new PizzaSericeContext())
            {
                List<Ingredient> ingredients = new List<Ingredient>();

                for (var i = 0; i < ids.Length; i++)
                {
                    var id = ids[i];
                    ingredients.Add(currentContext.Ingredients.FirstOrDefault(p => p.Id == id));
                }
                return ingredients;
            }
        }
        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 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();
         }
     }
 }
示例#30
0
        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();
            }
        }