internal static void Update(string[] args, ref List <string> errors, out RecipeStruct Data) { Data = new RecipeStruct(); var newRecipe = Construct(args.Skip(1).ToArray(), ref errors); if (errors.Any()) { return; } var processedData = LoadData(); if (int.TryParse(args[0], out var id) && !processedData.Any((recipe) => recipe.id == id)) { errors.Add($"Receita de index {args[0]} não existe"); return; } Write( processedData.Select( recipe => recipe.id != id ? recipe.ToString() : new RecipeStruct(recipe.id, args[1], newRecipe.Rendimento, recipe.links).ToString()) .ToArray()); InternalSelect(id, ref errors, out Data); }
internal static void Link(string[] args, ref List <string> errors, out RecipeStruct Data) { Data = new RecipeStruct(); if (!int.TryParse(args[0], out var id)) { errors.Add("Numero integral index em formato invalido"); } var link = Link(args[1..^ 0], ref errors);
internal static void Select(string id, ref List <string> errors, out RecipeStruct Data) { if (int.TryParse(id, out var index)) { InternalSelect(index, ref errors, out Data); } else { Data = new RecipeStruct(); errors.Add("Numero integral index em formato invalido"); } }
internal static void InternalSelect(int index, ref List <string> errors, out RecipeStruct Data) { var data = LoadData().Where(recipe => recipe.id == index); if (!data.Any()) { errors.Add($"Receita de index {index} não existe"); Data = new RecipeStruct(); return; } Data = data.SingleOrDefault(); var error = new List <string>(); var nData = Data.links .OrderBy(link => link.ingredientId) .Select <Link, (Link link, IngredientStruct ingredient)>( link => (link, Ingredient.SelectI(link.ingredientId, ref error, out var ingredient) ? ingredient : new IngredientStruct())); if (Processing.Process.showData) { float total = nData.Select((link) => link.link.quantity / (1 / link.ingredient.rendimento) * link.ingredient.price) .Aggregate(0, (float last, float val) => val + last, val => val); Utils.WriteValues("Dados", (Data.id, "index"), (Data.name, "name"), (Data.rendimento, "rendimento"), (total, "Preço total"), (MathF.Floor(Data.rendimento / .25f * 100) / 100, "Porções de 250g"), (MathF.Floor(total / (MathF.Floor(Data.rendimento / .25f * 100) / 100) * 100) / 100, "Preço/Porção 250g"), (MathF.Floor(Data.rendimento / .55f * 100) / 100, "Porções de 550g"), (MathF.Floor(total / (MathF.Floor(Data.rendimento / .55f * 100) / 100) * 100) / 100, "Preço/Porção 550g")); } nData.SelectMany(link => new string[] { link.link.ingredientId.ToString(), link.ingredient.name, (MathF.Floor(link.link.quantity * 100) / 100).ToString(), (MathF.Floor(1 / link.ingredient.rendimento * 100) / 100).ToString(), link.ingredient.rendimento.ToString(), (MathF.Floor(link.link.quantity / (1 / link.ingredient.rendimento) * 100) / 100).ToString(), (MathF.Floor(link.ingredient.price * 100) / 100).ToString(), (MathF.Floor(link.link.quantity / (1 / link.ingredient.rendimento) * link.ingredient.price * 100) / 100).ToString() }) .PrettyPrint(new string[] { "index", "Nome", "Qtdd Liq.", "FC", "Rend", "Qtdd bruta", "Unitario", "Preço bruto" }, "Ingredientes"); }