예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HomeViewModel" /> class.
        /// </summary>
        /// <param name="mainFrameNavigationService">The main frame navigation service.</param>
        /// <param name="pageBaseViewModel">The page base view model.</param>
        /// <param name="ingredientsAccess">The recipe components access.</param>
        /// <param name="loadingIndicatiorModule">The loading indicatior module.</param>
        /// <param name="recipesAccess">The recipes access.</param>
        public AddEditRecipeViewModel(IMainFrameNavigationService mainFrameNavigationService, IPageBaseViewModel pageBaseViewModel,
                                      IIngredientsAccess ingredientsAccess, ILoadingIndicatiorModule loadingIndicatiorModule, IRecipesAccess recipesAccess)
        {
            _mainFrameNavigation     = mainFrameNavigationService;
            _ingredientsAccess       = ingredientsAccess;
            _loadingIndicatiorModule = loadingIndicatiorModule;
            _recipesAccess           = recipesAccess;
            PageBaseModel            = pageBaseViewModel;

            MealTypesCollection = new ObservableCollection <MealTypes>();
            foreach (MealTypes value in Enum.GetValues(typeof(MealTypes)))
            {
                MealTypesCollection.Add(value);
            }

            UnitTypesCollection = new ObservableCollection <UnitTypes>();
            foreach (UnitTypes value in Enum.GetValues(typeof(UnitTypes)))
            {
                UnitTypesCollection.Add(value);
            }

            SelectedRecipe = new Recipe();

            DispatcherHelper.RunAsync(async() =>
            {
                _loadingIndicatiorModule.ShowLoadingIndicatior();
                var components      = await _ingredientsAccess.GetIngredientsList(x => true, x => x.Name);
                AllIngredients      = new ObservableCollection <IIngredient>(components);
                FilteredIngredients = new ObservableCollection <IIngredient>(AllIngredients.Where(x => true));
                _loadingIndicatiorModule.HideLoadingIndicator();
            });
        }
예제 #2
0
        private async Task SaveRecipe()
        {
            try
            {
                _loadingIndicatiorModule.ShowLoadingIndicatior();
                var added = await _recipesAccess.AddRecipe(SelectedRecipe);

                if (added != null)
                {
                    _mainFrameNavigation.GoBack();
                }
                _loadingIndicatiorModule.HideLoadingIndicator();
            }
            catch (Exception e)
            {
                _loadingIndicatiorModule.HideLoadingIndicator();
                //TODO message popup
            }
        }