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


            try
            {
                var recipes = await _appRecipesServices.UpdateAppRecipes(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> > > UpdateAppRecipes(AppRecipesUpdateDto dto)
        {
            List <AppRecipesGetDto> resultDto = new List <AppRecipesGetDto>();

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

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


            try
            {
                var recipe = await GetById(dto.Id);

                if (recipe == null)
                {
                    metadata.IsValid = false;
                    metadata.Message = "Receta no existe!!";
                    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);
                }
                if (dto.Formula.Length > 0)
                {
                    dto.AppIngredientsId = null;
                }


                recipe.Code = appVariablesFind.Code;

                recipe.Description = appVariablesFind.Description;

                recipe.Quantity = dto.Quantity;

                recipe.SumValue = dto.SumValue;

                recipe.OrderCalculate = dto.OrderCalculate;


                recipe.IncludeInSearch = dto.IncludeInSearch;


                recipe.AfectaCosto = dto.AfectaCosto;

                recipe.Secuencia = dto.Secuencia;

                recipe.AppIngredientsId = dto.AppIngredientsId;

                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)
                        {
                            recipe.TotalCost = appIngredientsFind.Cost * recipe.Quantity;
                        }
                        else
                        {
                            recipe.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);
                    }

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


                var updated = await Update(recipe);
                await UpdateVariableSearchByProduct((int)dto.AppproductsId);

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

                metadata.IsValid = true;
                metadata.Message = "Receta actualizada!";
                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);
            }
        }