Exemplo n.º 1
0
        internal void SaveChanges()
        {
            Worker.EnqueueTask(new WorkerTask(args =>
                {
                    try
                    {
                        using (var proxy = new WorkChannel())
                        {
                            List<RecipeDTO> toUpdate = new List<RecipeDTO>();
                            foreach (var recControl in RecipesCollection)
                            {
                                toUpdate.Add(recControl.Recipe);
                            }
                            return proxy.UpdateOrRemoveRecipe(new UpdateOrRemoveRequest<List<RecipeDTO>>
                            {
                                Data = toUpdate,
                                DataToRemove = RemovedRecipes,
                                Login = ClientConfig.CurrentUser.Email,
                                Password = ClientConfig.CurrentUser.Password
                            });
                        }
                    }
                    catch (Exception exc)
                    {
                        Console.WriteLine(exc.Message);
                        Console.WriteLine("Failed");
                        return exc;
                    }
                }, (s, e) =>
                    {
                        if (e.Result is Exception)
                        {
                            Utils.HandleException(e.Result as Exception);
                            return;
                        }
                        var result = e.Result as TrioResponse<List<RecipeDTO>, List<OrderIngredientDTO>, int>;
                        if (result == null)
                        {
                            Utils.showError(Utils.Messages.UNKNOWN_ERROR_FORMAT);
                            return;
                        }

                        RecipesCollection.Clear();
                        IngredientsRowsCollection.Clear();
                        RemovedRecipes.Clear();
                        foreach (var item in result.First)
                        {
                            var rc = new RecipeControl();
                            rc.Recipe = item;
                            //rc.RecalculatePrices(result.Second.ToArray());
                            rc.Update(Sizes);
                            RecipesCollection.Add(rc);
                        }
                        foreach (var item in result.Second)
                        {
                            var row = new IngredientsRowWork(item, false);
                            row.ButtonIncludeChanged += row_PropertyChanged;
                            IngredientsRowsCollection.Add(row);
                        }
                        Modified = false;
                    }, null));
        }