public async Task <IActionResult> CreateAppRecipes(AppRecipesCreateDto dto)
        {
            Metadata metadata = new Metadata
            {
                IsValid    = false,
                Message    = "",
                TotalCount = 0
            };


            try
            {
                var recipes = await _appRecipesServices.CreateAppRecipes(dto);

                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 <ApiResponse <List <AppRecipesGetDto> > > CreateAppRecipes(AppRecipesCreateDto dto)
        {
            List <AppRecipesGetDto> resultDto = new List <AppRecipesGetDto>();

            Metadata metadata = new Metadata
            {
                IsValid = true,
                Message = ""
            };

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


            try
            {
                AppRecipes appRecipes = _mapper.Map <AppRecipes>(dto);

                //var recipeByProductVariable = await GetRecipesByProductIdVariableId((int)dto.AppproductsId, (int)dto.AppVariableId);
                //if (recipeByProductVariable != null)
                //{

                //    metadata.IsValid = false;
                //    metadata.Message = "Variable ya existe en este producto!!";
                //    response.Data = null;
                //    response.Meta = metadata;
                //    return response;
                //}


                AppProducts appProductsFind = await _appProductsService.GetById((int)dto.AppproductsId);

                if (appProductsFind == null)
                {
                    metadata.IsValid = false;
                    metadata.Message = "Producto no existe!!";
                    response.Data    = null;
                    response.Meta    = metadata;
                    return(response);
                }
                AppVariables appVariablesFind = await _appVariablesService.GetById((int)dto.AppVariableId);

                if (appVariablesFind == null)
                {
                    metadata.IsValid = false;
                    metadata.Message = "Variable no existe!!";
                    response.Data    = null;
                    response.Meta    = metadata;
                    return(response);
                }

                appRecipes.Code = appVariablesFind.Code;

                appRecipes.Description = appVariablesFind.Description;

                appRecipes.Quantity = dto.Quantity;

                appRecipes.SumValue = dto.SumValue;

                appRecipes.OrderCalculate = dto.OrderCalculate;

                appRecipes.IncludeInSearch = dto.IncludeInSearch;

                appRecipes.AfectaCosto = dto.AfectaCosto;

                appRecipes.Secuencia = dto.Secuencia;

                if (dto.AppIngredientsId != null)
                {
                    AppIngredients appIngredientsFind = await _unitOfWork.AppIngredientsRepository.GetById((int)dto.AppIngredientsId);

                    if (appIngredientsFind == null)
                    {
                        metadata.IsValid = false;
                        metadata.Message = "Ingrediente no existe!!";
                        response.Data    = null;
                        response.Meta    = metadata;
                        return(response);
                    }
                    else
                    {
                        if (dto.AfectaCosto == true)
                        {
                            appRecipes.TotalCost = appIngredientsFind.Cost * appRecipes.Quantity;
                        }
                        else
                        {
                            appRecipes.TotalCost = 0;
                        }
                    }
                }
                else
                {
                    if (dto.Formula == "" || dto.Formula == null)
                    {
                        metadata.IsValid = false;
                        metadata.Message = "Debe Indicar Una formula o seleccionar un ingrediente!!";
                        response.Data    = null;
                        response.Meta    = metadata;
                        return(response);
                    }

                    appRecipes.TotalCost    = 0;
                    appRecipes.Formula      = dto.Formula;
                    appRecipes.FormulaValue = "";
                }


                var inserted = await Insert(appRecipes);
                await UpdateVariableSearchByProduct((int)dto.AppproductsId);

                var listRecipeCalculate = await CalulateRecipeByProduct((int)dto.AppproductsId);

                response.Data = listRecipeCalculate;
                response.Meta = metadata;
                return(response);
            }
            catch (Exception ex)
            {
                metadata.IsValid = false;
                metadata.Message = ex.InnerException.Message;
                response.Data    = null;
                response.Meta    = metadata;
                return(response);
            }
        }