Exemplo n.º 1
0
        public static OrderViewModel OrderPizza(Guid userId, Guid pizzaId, Guid bottomId, Guid sauceId, List <Guid> ingredientId)
        {
            UnitOfWorkRepository unitOfWork = new UnitOfWorkRepository();

            OrderRule orderrule = new OrderRule();
            var       order     = unitOfWork.OrderRepository.GetAllOrders().Where(x => x.UserId == userId).FirstOrDefault();
            var       piz       = unitOfWork.PizzaRepository.GetPizzaId(pizzaId);
            var       bot       = unitOfWork.BottomRepository.GetBottom(bottomId);
            var       sc        = unitOfWork.SauceRepository.GetSauceId(sauceId);

            if (order == null)
            {
                order           = new Order();
                order.Id        = Guid.NewGuid();
                order.OrderRule = new List <OrderRule>();
            }

            List <Ingredients> _Ing = new List <Ingredients>();

            foreach (var ing in ingredientId)
            {
                var ingr = unitOfWork.IngredientRepository.GetAllIngredients().Where(x => x.Id == ing).FirstOrDefault();
                _Ing.Add(ingr);
            }

            foreach (var ing in _Ing)
            {
                Pizza_Ingredient pizza_Ingredient = new Pizza_Ingredient();
                pizza_Ingredient.Id                 = Guid.NewGuid();
                pizza_Ingredient.IngriedientId      = ing.Id;
                pizza_Ingredient.PizzaIngredient_Id = pizzaId;
                unitOfWork.PizzaIngredientRepository.AddPizza_Ingredients(pizza_Ingredient);
                piz.PizzaIngredient.Add(pizza_Ingredient);
            }
            bot.SauceId     = sc.Id;
            piz.BottomId    = bot.Id;
            piz.OrderRuleId = orderrule.Id;

            orderrule.Id      = Guid.NewGuid();
            orderrule.OrderId = order.Id;
            orderrule.PizzaId = piz.Id;

            order.OrderRule.Add(orderrule);

            unitOfWork.PizzaRepository.UpdatePizza(piz);
            unitOfWork.OrderRepository.AddOrUpdate(order);
            unitOfWork.OrderRuleRepository.AddOrUpdate(orderrule);
            var pizza          = PizzaModelFactory.ConvertPizza(piz);
            var orderViewModel = new OrderViewModel()
            {
                pizza       = pizza,
                bottom      = BottomModelFacotry.ConvertBottom(bot),
                sauce       = SauceModelFactory.ConvertSauce(sc),
                ingredients = IngredientModelFactory.ConvertIngredients(_Ing)
            };

            return(orderViewModel);
        }
Exemplo n.º 2
0
        public void AddOrUpdate(Pizza_Ingredient pizza_Ingredient)
        {
            var pizIng = Database.PizzaIngredient.Where(x => x.Id == pizza_Ingredient.Id).FirstOrDefault();

            if (pizIng != null)
            {
                pizIng = pizza_Ingredient;
                Database.PizzaIngredient.AddOrUpdate(pizIng);
                Database.SaveChanges();
            }
            else
            {
                AddPizza_Ingredients(pizza_Ingredient);
            }
        }
Exemplo n.º 3
0
        public static Pizza_Ingredient ConvertPizzaIngredientModel(PizzaIngredientModel model)
        {
            if (model == null)
            {
                return(null);
            }

            Pizza_Ingredient pizINg = new Pizza_Ingredient()
            {
                Id = model.Id,
                PizzaIngredient_Id = model.PizzaId,
                IngriedientId      = model.Ingredient.Id
            };

            return(pizINg);
        }
Exemplo n.º 4
0
        public static PizzaIngredientModel ConvertPizzaIngredient(Pizza_Ingredient pizIng)
        {
            if (pizIng == null)
            {
                return(null);
            }
            var ingredient = IngredientModelFactory.GetIngredientModel(pizIng.IngriedientId);

            PizzaIngredientModel model = new PizzaIngredientModel
            {
                Id         = pizIng.Id,
                PizzaId    = pizIng.PizzaIngredient_Id,
                Ingredient = ingredient
            };

            return(model);
        }
Exemplo n.º 5
0
 public Pizza_Ingredient AddPizza_Ingredients(Pizza_Ingredient pizIng)
 {
     Database.PizzaIngredient.Add(pizIng);
     Database.SaveChanges();
     return(pizIng);
 }