public static List <BottomModel> GetAllBottoms()
        {
            UnitOfWorkRepository unitOfWork = new UnitOfWorkRepository();
            var bottoms = unitOfWork.BottomRepository.GetAllBottoms();
            var models  = BottomModelFacotry.ConvertBottoms(bottoms);

            return(models);
        }
        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);
        }
Beispiel #3
0
        public static PizzaModel ConvertPizza(Pizza pizza)
        {
            if (pizza == null)
            {
                return(null);
            }
            var bottomModel          = BottomModelFacotry.GetBottomModel(pizza.BottomId);
            var pizzaIngredientModel = PizzaIngredientModelFactory.ConvertPizzaIngredients(pizza.PizzaIngredient);

            PizzaModel pizzaModel = new PizzaModel()
            {
                Id               = pizza.Id,
                Name             = pizza.Name,
                Price            = pizza.Price,
                OrderRuleId      = pizza.OrderRuleId,
                Bottom           = bottomModel,
                PizzaIngredients = pizzaIngredientModel
            };

            return(pizzaModel);
        }