public async Task <List <AppRecipesGetDto> > CalulateRecipeByProduct(int productId)
        {
            await UpdateIngredientsCostRecipeByProduct(productId);

            List <AppRecipesGetDto> resultDto = new List <AppRecipesGetDto>();


            AppRecipesQueryFilter filter = new AppRecipesQueryFilter();

            filter.AppproductsId = productId;
            filter.SearchText    = "";
            var recipe = await GetRecipesByProductId(productId);

            if (recipe == null)
            {
                return(resultDto);
            }
            else
            {
                foreach (AppRecipes item in recipe.OrderBy(x => x.OrderCalculate).ToList())
                {
                    await CalculateFormula(item);
                }

                await UpdatePriceByProduct(productId);

                resultDto = await GetRecipesGetDtoByProductId(filter);

                return(resultDto);
            }
        }
        public async Task <IActionResult> GetRecipesGetDtoByProductId(AppRecipesQueryFilter filters)
        {
            Metadata metadata = new Metadata
            {
                IsValid    = false,
                Message    = "",
                TotalCount = 0
            };


            try
            {
                var recipes = await _appRecipesServices.GetRecipesGetDtoByProductId(filters);

                return(Ok(recipes));
            }
            catch (Exception e)
            {
                metadata.IsValid = false;
                metadata.Message = e.InnerException.Message;
                var responseError = new ApiResponse <AppDetailQuotesGetDto>(null)
                {
                    Meta = metadata
                };


                return(Ok(responseError));
            }
        }
        public async Task <List <AppRecipesGetDto> > GetRecipesGetDtoByProductId(AppRecipesQueryFilter filter)
        {
            List <AppRecipesGetDto> resultDto = new List <AppRecipesGetDto>();

            var recipes = await GetAllRecipesByProductId(filter.AppproductsId);

            if (recipes != null)
            {
                if (filter.SearchText != "" && filter.SearchText != null)
                {
                    recipes = recipes.Where(x => x.Description.Trim().ToLower().Contains(filter.SearchText.Trim().ToLower()) || x.Code.Trim().ToLower().Contains(filter.SearchText.Trim().ToLower()) || x.Formula.Trim().ToLower().Contains(filter.SearchText.Trim().ToLower())).ToList();
                }


                List <AppRecipesGetDto> recipesDto = _mapper.Map <List <AppRecipesGetDto> >(recipes);

                foreach (var item in recipesDto)
                {
                    AppProducts appProductsFind = await _appProductsService.GetById((int)item.AppproductsId);

                    if (appProductsFind != null)
                    {
                        AppProductsGetDto appProductsGetDto = _mapper.Map <AppProductsGetDto>(appProductsFind);
                        item.AppProductsGetDto = appProductsGetDto;
                    }
                    AppVariables appVariablesFind = await _appVariablesService.GetById((int)item.AppVariableId);

                    if (appVariablesFind != null)
                    {
                        AppVariablesGetDto appVariablesGetDto = _mapper.Map <AppVariablesGetDto>(appVariablesFind);
                        item.AppVariablesGetDto = appVariablesGetDto;
                    }
                    if (item.AppIngredientsId != null)
                    {
                        AppIngredients appIngredientsFind = await _unitOfWork.AppIngredientsRepository.GetById((int)item.AppIngredientsId);

                        if (appIngredientsFind != null)
                        {
                            AppIngredientsGetDto appIngredientsGetDto = _mapper.Map <AppIngredientsGetDto>(appIngredientsFind);
                            item.AppIngredientsGetDto = appIngredientsGetDto;
                        }
                    }
                }



                resultDto = recipesDto;
            }

            return(resultDto);
        }