Пример #1
0
        public int GetTotalCaloricValue(Cart cart)
        {
            Customer        customer  = cr.GetWholeEntity(cart.CustomerId);
            List <CartPart> cartParts = db.GetWholeEntityByCustomerList(customer).ToList();

            List <Menu> menues = cartParts.Select(x => x.Menu).ToList();

            for (int i = 0; i < menues.Count(); i++)
            {
                menues[i] = mr.GetWholeEntity(menues[i].Id);
            }

            int         totalCaloric = 0;
            List <Dish> dishes       = menues.Select(x => x.Dish).ToList();

            for (int i = 0; i < dishes.Count(); i++)
            {
                dishes[i] = dr.GetWholeEntity(dishes[i].Id);

                List <Ingredient> ingredients = dishes[i].Ingredient.ToList();
                int singleCountCaloricValue   = 0;
                for (int j = 0; j < ingredients.Count(); j++)
                {
                    Product product = pr.GetEntity(ingredients[j].ProductId);
                    singleCountCaloricValue += product.CaloricValue * ingredients[j].ProductWeight / 100;
                }
                totalCaloric += (cartParts[i].DishCount * singleCountCaloricValue);
            }

            return(totalCaloric);
        }